MCPcopy Create free account
hub / github.com/BVLC/caffe / FileInfo

Class FileInfo

scripts/cpp_lint.py:875–962  ·  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

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

Callers 3

CheckIncludeLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected