MCPcopy Index your code
hub / github.com/nodejs/node / FileInfo

Class FileInfo

tools/cpplint.py:1747–1854  ·  view source on GitHub ↗

Provides utility functions for filenames. FileInfo provides easy access to the components of a file's path relative to the project root.

Source from the content-addressed store, hash-verified

1745
1746
1747class FileInfo:
1748 """Provides utility functions for filenames.
1749
1750 FileInfo provides easy access to the components of a file's path
1751 relative to the project root.
1752 """
1753
1754 def __init__(self, filename):
1755 self._filename = filename
1756
1757 def FullName(self):
1758 """Make Windows paths like Unix."""
1759 return os.path.abspath(self._filename).replace("\\", "/")
1760
1761 def RepositoryName(self):
1762 r"""FullName after removing the local path to the repository.
1763
1764 If we have a real absolute path name here we can try to do something smart:
1765 detecting the root of the checkout and truncating /path/to/checkout from
1766 the name so that we get header guards that don't include things like
1767 "C:\\Documents and Settings\\..." or "/home/username/..." in them and thus
1768 people on different computers who have checked the source out to different
1769 locations won't see bogus errors.
1770 """
1771 fullname = self.FullName()
1772
1773 if os.path.exists(fullname):
1774 project_dir = os.path.dirname(fullname)
1775
1776 # If the user specified a repository path, it exists, and the file is
1777 # contained in it, use the specified repository path
1778 if _repository:
1779 repo = FileInfo(_repository).FullName()
1780 root_dir = project_dir
1781 while os.path.exists(root_dir):
1782 # allow case insensitive compare on Windows
1783 if os.path.normcase(root_dir) == os.path.normcase(repo):
1784 return os.path.relpath(fullname, root_dir).replace("\\", "/")
1785 one_up_dir = os.path.dirname(root_dir)
1786 if one_up_dir == root_dir:
1787 break
1788 root_dir = one_up_dir
1789
1790 if os.path.exists(os.path.join(project_dir, ".svn")):
1791 # If there's a .svn file in the current directory, we recursively look
1792 # up the directory tree for the top of the SVN checkout
1793 root_dir = project_dir
1794 one_up_dir = os.path.dirname(root_dir)
1795 while os.path.exists(os.path.join(one_up_dir, ".svn")):
1796 root_dir = os.path.dirname(root_dir)
1797 one_up_dir = os.path.dirname(one_up_dir)
1798
1799 prefix = os.path.commonprefix([root_dir, project_dir])
1800 return fullname[len(prefix) + 1 :]
1801
1802 # Not SVN <= 1.6? Try to find a git, hg, or svn top level directory by
1803 # searching up from the current path.
1804 root_dir = current_dir = os.path.dirname(fullname)

Callers 5

RepositoryNameMethod · 0.85
CheckHeaderFileIncludedFunction · 0.85
CheckIncludeLineFunction · 0.85
FilesBelongToSameModuleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…