MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / FileInfo

Class FileInfo

rtpose_wrapper/scripts/cpp_lint.py:871–958  ·  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

869
870
871class FileInfo:
872 """Provides utility functions for filenames.
873
874 FileInfo provides easy access to the components of a file's path
875 relative to the project root.
876 """
877
878 def __init__(self, filename):
879 self._filename = filename
880
881 def FullName(self):
882 """Make Windows paths like Unix."""
883 return os.path.abspath(self._filename).replace('\\', '/')
884
885 def RepositoryName(self):
886 """FullName after removing the local path to the repository.
887
888 If we have a real absolute path name here we can try to do something smart:
889 detecting the root of the checkout and truncating /path/to/checkout from
890 the name so that we get header guards that don't include things like
891 "C:\Documents and Settings\..." or "/home/username/..." in them and thus
892 people on different computers who have checked the source out to different
893 locations won't see bogus errors.
894 """
895 fullname = self.FullName()
896
897 if os.path.exists(fullname):
898 project_dir = os.path.dirname(fullname)
899
900 if os.path.exists(os.path.join(project_dir, ".svn")):
901 # If there's a .svn file in the current directory, we recursively look
902 # up the directory tree for the top of the SVN checkout
903 root_dir = project_dir
904 one_up_dir = os.path.dirname(root_dir)
905 while os.path.exists(os.path.join(one_up_dir, ".svn")):
906 root_dir = os.path.dirname(root_dir)
907 one_up_dir = os.path.dirname(one_up_dir)
908
909 prefix = os.path.commonprefix([root_dir, project_dir])
910 return fullname[len(prefix) + 1:]
911
912 # Not SVN <= 1.6? Try to find a git, hg, or svn top level directory by
913 # searching up from the current path.
914 root_dir = os.path.dirname(fullname)
915 while (root_dir != os.path.dirname(root_dir) and
916 not os.path.exists(os.path.join(root_dir, ".git")) and
917 not os.path.exists(os.path.join(root_dir, ".hg")) and
918 not os.path.exists(os.path.join(root_dir, ".svn"))):
919 root_dir = os.path.dirname(root_dir)
920
921 if (os.path.exists(os.path.join(root_dir, ".git")) or
922 os.path.exists(os.path.join(root_dir, ".hg")) or
923 os.path.exists(os.path.join(root_dir, ".svn"))):
924 prefix = os.path.commonprefix([root_dir, project_dir])
925 return fullname[len(prefix) + 1:]
926
927 # Don't know what to do; header guard warnings may be wrong...
928 return fullname

Callers 3

CheckIncludeLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected