MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / FixupPathFromRoot

Function FixupPathFromRoot

steps/cpplint.py:2323–2371  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2321 file_path_from_root = fileinfo.RepositoryName()
2322
2323 def FixupPathFromRoot():
2324 if _root_debug:
2325 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
2326 % (_root, fileinfo.RepositoryName()))
2327
2328 # Process the file path with the --root flag if it was set.
2329 if not _root:
2330 if _root_debug:
2331 sys.stderr.write("_root unspecified\n")
2332 return file_path_from_root
2333
2334 def StripListPrefix(lst, prefix):
2335 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
2336 if lst[:len(prefix)] != prefix:
2337 return None
2338 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
2339 return lst[(len(prefix)):]
2340
2341 # root behavior:
2342 # --root=subdir , lstrips subdir from the header guard
2343 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
2344 PathSplitToList(_root))
2345
2346 if _root_debug:
2347 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
2348 " _root=%s)\n") % (maybe_path, file_path_from_root, _root))
2349
2350 if maybe_path:
2351 return os.path.join(*maybe_path)
2352
2353 # --root=.. , will prepend the outer directory to the header guard
2354 full_path = fileinfo.FullName()
2355 root_abspath = os.path.abspath(_root)
2356
2357 maybe_path = StripListPrefix(PathSplitToList(full_path),
2358 PathSplitToList(root_abspath))
2359
2360 if _root_debug:
2361 sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " +
2362 "root_abspath=%s)\n") % (maybe_path, full_path, root_abspath))
2363
2364 if maybe_path:
2365 return os.path.join(*maybe_path)
2366
2367 if _root_debug:
2368 sys.stderr.write("_root ignore, returning %s\n" % (file_path_from_root))
2369
2370 # --root=FAKE_DIR is ignored
2371 return file_path_from_root
2372
2373 file_path_from_root = FixupPathFromRoot()
2374 return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'

Callers 1

Calls 5

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

Tested by

no test coverage detected