MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / FixupPathFromRoot

Function FixupPathFromRoot

src/tests/coding/cpplint.py:2308–2357  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2306 file_path_from_root = fileinfo.RepositoryName()
2307
2308 def FixupPathFromRoot():
2309 if _root_debug:
2310 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
2311 % (_root, fileinfo.RepositoryName()))
2312
2313 # Process the file path with the --root flag if it was set.
2314 if not _root:
2315 if _root_debug:
2316 sys.stderr.write("_root unspecified\n")
2317 return file_path_from_root
2318
2319 def StripListPrefix(lst, prefix):
2320 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
2321 if lst[:len(prefix)] != prefix:
2322 return None
2323 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
2324 return lst[(len(prefix)):]
2325
2326 # root behavior:
2327 # --root=subdir , lstrips subdir from the header guard
2328 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
2329 PathSplitToList(_root))
2330
2331 if _root_debug:
2332 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
2333 " _root=%s)\n") % (maybe_path, file_path_from_root, _root))
2334
2335 if maybe_path:
2336 return os.path.join(*maybe_path)
2337
2338 # --root=.. , will prepend the outer directory to the header guard
2339 full_path = fileinfo.FullName()
2340 # adapt slashes for windows
2341 root_abspath = os.path.abspath(_root).replace('\\', '/')
2342
2343 maybe_path = StripListPrefix(PathSplitToList(full_path),
2344 PathSplitToList(root_abspath))
2345
2346 if _root_debug:
2347 sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " +
2348 "root_abspath=%s)\n") % (maybe_path, full_path, root_abspath))
2349
2350 if maybe_path:
2351 return os.path.join(*maybe_path)
2352
2353 if _root_debug:
2354 sys.stderr.write("_root ignore, returning %s\n" % (file_path_from_root))
2355
2356 # --root=FAKE_DIR is ignored
2357 return file_path_from_root
2358
2359 file_path_from_root = FixupPathFromRoot()
2360 return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'

Callers 1

Calls 6

StripListPrefixFunction · 0.85
PathSplitToListFunction · 0.85
RepositoryNameMethod · 0.80
FullNameMethod · 0.80
writeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected