MCPcopy Create free account
hub / github.com/apache/mesos / FixupPathFromRoot

Function FixupPathFromRoot

support/cpplint.py:1836–1884  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1834 file_path_from_root = fileinfo.RepositoryName()
1835
1836 def FixupPathFromRoot():
1837 if _root_debug:
1838 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
1839 %(_root, fileinfo.RepositoryName()))
1840
1841 # Process the file path with the --root flag if it was set.
1842 if not _root:
1843 if _root_debug:
1844 sys.stderr.write("_root unspecified\n")
1845 return file_path_from_root
1846
1847 def StripListPrefix(lst, prefix):
1848 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
1849 if lst[:len(prefix)] != prefix:
1850 return None
1851 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
1852 return lst[(len(prefix)):]
1853
1854 # root behavior:
1855 # --root=subdir , lstrips subdir from the header guard
1856 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
1857 PathSplitToList(_root))
1858
1859 if _root_debug:
1860 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
1861 " _root=%s)\n") %(maybe_path, file_path_from_root, _root))
1862
1863 if maybe_path:
1864 return os.path.join(*maybe_path)
1865
1866 # --root=.. , will prepend the outer directory to the header guard
1867 full_path = fileinfo.FullName()
1868 root_abspath = os.path.abspath(_root)
1869
1870 maybe_path = StripListPrefix(PathSplitToList(full_path),
1871 PathSplitToList(root_abspath))
1872
1873 if _root_debug:
1874 sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " +
1875 "root_abspath=%s)\n") %(maybe_path, full_path, root_abspath))
1876
1877 if maybe_path:
1878 return os.path.join(*maybe_path)
1879
1880 if _root_debug:
1881 sys.stderr.write("_root ignore, returning %s\n" %(file_path_from_root))
1882
1883 # --root=FAKE_DIR is ignored
1884 return file_path_from_root
1885
1886 file_path_from_root = FixupPathFromRoot()
1887 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
joinMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected