MCPcopy Create free account
hub / github.com/alibaba/GraphScope / FileInfo

Class FileInfo

analytical_engine/misc/cpplint.py:1554–1656  ·  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

1552
1553
1554class FileInfo(object):
1555 """Provides utility functions for filenames.
1556
1557 FileInfo provides easy access to the components of a file's path
1558 relative to the project root.
1559 """
1560
1561 def __init__(self, filename):
1562 self._filename = filename
1563
1564 def FullName(self):
1565 """Make Windows paths like Unix."""
1566 return os.path.abspath(self._filename).replace('\\', '/')
1567
1568 def RepositoryName(self):
1569 r"""FullName after removing the local path to the repository.
1570
1571 If we have a real absolute path name here we can try to do something smart:
1572 detecting the root of the checkout and truncating /path/to/checkout from
1573 the name so that we get header guards that don't include things like
1574 "C:\\Documents and Settings\\..." or "/home/username/..." in them and thus
1575 people on different computers who have checked the source out to different
1576 locations won't see bogus errors.
1577 """
1578 fullname = self.FullName()
1579
1580 if os.path.exists(fullname):
1581 project_dir = os.path.dirname(fullname)
1582
1583 # If the user specified a repository path, it exists, and the file is
1584 # contained in it, use the specified repository path
1585 if _repository:
1586 repo = FileInfo(_repository).FullName()
1587 root_dir = project_dir
1588 while os.path.exists(root_dir):
1589 # allow case-insensitive compare on Windows
1590 if os.path.normcase(root_dir) == os.path.normcase(repo):
1591 return os.path.relpath(fullname, root_dir).replace('\\', '/')
1592 one_up_dir = os.path.dirname(root_dir)
1593 if one_up_dir == root_dir:
1594 break
1595 root_dir = one_up_dir
1596
1597 if os.path.exists(os.path.join(project_dir, ".svn")):
1598 # If there's a .svn file in the current directory, we recursively look
1599 # up the directory tree for the top of the SVN checkout
1600 root_dir = project_dir
1601 one_up_dir = os.path.dirname(root_dir)
1602 while os.path.exists(os.path.join(one_up_dir, ".svn")):
1603 root_dir = os.path.dirname(root_dir)
1604 one_up_dir = os.path.dirname(one_up_dir)
1605
1606 prefix = os.path.commonprefix([root_dir, project_dir])
1607 return fullname[len(prefix) + 1:]
1608
1609 # Not SVN <= 1.6? Try to find a git, hg, or svn top level directory by
1610 # searching up from the current path.
1611 root_dir = current_dir = os.path.dirname(fullname)

Callers 6

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

Calls

no outgoing calls

Tested by

no test coverage detected