Ejemplo n.º 1
0
 def __call__(self, parser, namespace, values, option_string=None):
     if not isinstance(values, str):
         sys.exit("*** %s is not a string" % values)
     self.path = Path(values)
     self.path.assert_exists()
     self.path.assert_is_file()
     self.path.assert_mode(os.R_OK)
     namespace.style_file = str(self.path)
Ejemplo n.º 2
0
 def _installed_directories(self):
     for path in os.environ["PATH"].split(os.pathsep):
         if not os.path.exists(path):
             continue
         for e in os.listdir(path):
             b = Path(os.path.join(path, e))
             if b.is_file() and b.filename() in CLANG_BINARIES:
                 yield b.directory()
Ejemplo n.º 3
0
 def clone_or_fetch(self, repository_base):
     """
     Clones a fresh repository at the given base unless it exists already.
     If it exists already, it will fetch the latest upstream state (which is
     less abusive of the github servers than a full clone). The result will
     be returned as a GitRepository instance.
     """
     p = Path(repository_base)
     return (self._fetch(repository_base) if p.exists() else
             self.clone(repository_base))
Ejemplo n.º 4
0
 def __init__(self, invocation_dir, output_file):
     path = Path(output_file)
     containing_directory = Path(path.containing_directory())
     if not os.path.exists(str(containing_directory)):
         os.makedirs(str(containing_directory))
     containing_directory.assert_exists()
     containing_directory.assert_mode(os.R_OK | os.W_OK)
     self.invocation_dir = invocation_dir
     self.output_file = str(path)
Ejemplo n.º 5
0
 def __call__(self, parser, namespace, values, option_string=None):
     if not isinstance(values, str):
         sys.exit("*** %s is not a single string" % values)
     p = Path(values)
     p.assert_exists()
     p.assert_is_directory()
     p.assert_mode(os.R_OK | os.W_OK)
Ejemplo n.º 6
0
 def __init__(self, repository_base):
     super().__init__()
     json_file = os.path.join(repository_base, REPO_INFO_FILENAME)
     path = Path(json_file)
     if not path.exists():
         # If there is no .json file in the repo, it might be an old version
         # checked out. We can still do best-effort with a default file
         # that is located in this repo.
         json_file = self._failback_file()
         path = Path(json_file)
         if not path.exists():
             sys.exit("Could not find a .json repository info file to use.")
     path.assert_is_file()
     path.assert_mode(os.R_OK)
     content = read_file(json_file)
     self.update(json.loads(content))
Ejemplo n.º 7
0
 def __init__(self, file_path):
     p = Path(file_path)
     p.assert_exists()
     p.assert_is_file()
     p.assert_mode(os.R_OK)
     self.file_path = file_path
     self.raw_contents = read_file(file_path)
     self.parameters = self._parse_parameters()
     self.rejected_parameters = {}
Ejemplo n.º 8
0
 def _find_binaries(self, search_directories):
     binaries = {}
     for directory in search_directories:
         for binary in CLANG_BINARIES:
             path = Path(os.path.join(directory, binary))
             if not path.exists():
                 continue
             path.assert_is_file()
             path.assert_mode(os.R_OK | os.X_OK)
             if path.filename() not in binaries:
                 binaries[path.filename()] = []
             version = str(ClangVersion(str(path)))
             binaries[path.filename()].append({
                 'path': str(path),
                 'version': version
             })
     return binaries
Ejemplo n.º 9
0
 def __init__(self, repository_base):
     self.repository_base = str(Path(repository_base))
     git_path = GitPath(repository_base)
     git_path.assert_exists()
     git_path.assert_mode(os.R_OK)
     git_path.assert_in_git_repository()
     if str(self.repository_base) != str(git_path.repository_base()):
         sys.exit("*** %s is not the base of its repository" %
                  self.repository_base)
     self.repo_info = RepositoryInfo(self.repository_base)
Ejemplo n.º 10
0
 def _parameter_directory(self, path_arg_str):
     p = Path(path_arg_str)
     p.assert_exists()
     # Tarball-download versions of clang put binaries in a bin/
     # subdirectory. For convenience, tolerate a parameter of either:
     # <unpacked_tarball>, <unpacked tarball>/bin or
     # <unpacked_tarball>/bin/<specific_binary>
     if p.is_file():
         return p.directory()
     bin_subdir = os.path.join(str(p), "bin/")
     if os.path.exists(bin_subdir):
         return bin_subdir
     return str(p)
Ejemplo n.º 11
0
 def __call__(self, parser, namespace, values, option_string=None):
     if not isinstance(values, str):
         sys.exit("*** %s is not a single string" % values)
     if not str(values).startswith(tempfile.gettempdir()):
         sys.exit("*** %s is not under %s" % (p, tempfile.gettempdir()))
     namespace.tmp_directory = str(Path(values))
Ejemplo n.º 12
0
 def __init__(self, directory):
     if not os.path.exists(str(directory)):
         os.makedirs(str(directory))
     path = Path(directory)
     path.assert_mode(os.R_OK | os.W_OK)
     self.directory = directory
Ejemplo n.º 13
0
 def __init__(self, directory):
     path = Path(directory)
     path.assert_exists()
     path.assert_is_directory()
     path.assert_mode(os.R_OK)
     self.directory = directory
Ejemplo n.º 14
0
 def __init__(self, binary_path):
     p = Path(binary_path)
     if p.filename() in ASK_FOR_VERSION:
         self.version = self._version_from_asking(binary_path)
     else:
         self.version = self._version_from_path(binary_path)
Ejemplo n.º 15
0
 def assert_has_makefile(self):
     makefile = Path(os.path.join(self.repository_base, "Makefile"))
     if not makefile.exists():
         sys.exit("*** no Makefile found in %s. You must ./autogen.sh "
                  "and/or ./configure first" % self.repository_base)
Ejemplo n.º 16
0
 def _is_repository_base(self):
     self.assert_is_directory()
     return Path(os.path.join(self.path, '.git/')).exists()