MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / FileInfo

Class FileInfo

src/tests/coding/cpplint.py:1550–1652  ·  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

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