()
| 1829 | file_path_from_root = fileinfo.RepositoryName() |
| 1830 | |
| 1831 | def FixupPathFromRoot(): |
| 1832 | if _root_debug: |
| 1833 | sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n" |
| 1834 | %(_root, fileinfo.RepositoryName())) |
| 1835 | |
| 1836 | # Process the file path with the --root flag if it was set. |
| 1837 | if not _root: |
| 1838 | if _root_debug: |
| 1839 | sys.stderr.write("_root unspecified\n") |
| 1840 | return file_path_from_root |
| 1841 | |
| 1842 | def StripListPrefix(lst, prefix): |
| 1843 | # f(['x', 'y'], ['w, z']) -> None (not a valid prefix) |
| 1844 | if lst[:len(prefix)] != prefix: |
| 1845 | return None |
| 1846 | # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd'] |
| 1847 | return lst[(len(prefix)):] |
| 1848 | |
| 1849 | # root behavior: |
| 1850 | # --root=subdir , lstrips subdir from the header guard |
| 1851 | maybe_path = StripListPrefix(PathSplitToList(file_path_from_root), |
| 1852 | PathSplitToList(_root)) |
| 1853 | |
| 1854 | if _root_debug: |
| 1855 | sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," + |
| 1856 | " _root=%s)\n") %(maybe_path, file_path_from_root, _root)) |
| 1857 | |
| 1858 | if maybe_path: |
| 1859 | return os.path.join(*maybe_path) |
| 1860 | |
| 1861 | # --root=.. , will prepend the outer directory to the header guard |
| 1862 | full_path = fileinfo.FullName() |
| 1863 | root_abspath = os.path.abspath(_root) |
| 1864 | |
| 1865 | maybe_path = StripListPrefix(PathSplitToList(full_path), |
| 1866 | PathSplitToList(root_abspath)) |
| 1867 | |
| 1868 | if _root_debug: |
| 1869 | sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " + |
| 1870 | "root_abspath=%s)\n") %(maybe_path, full_path, root_abspath)) |
| 1871 | |
| 1872 | if maybe_path: |
| 1873 | return os.path.join(*maybe_path) |
| 1874 | |
| 1875 | if _root_debug: |
| 1876 | sys.stderr.write("_root ignore, returning %s\n" %(file_path_from_root)) |
| 1877 | |
| 1878 | # --root=FAKE_DIR is ignored |
| 1879 | return file_path_from_root |
| 1880 | |
| 1881 | file_path_from_root = FixupPathFromRoot() |
| 1882 | return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_' |
no test coverage detected
searching dependent graphs…