def build_graphs(repository_pair, builder, parameters): """ Builds three dependency graphs (forward, backward and marked forward) for the given repository pair. @param repository_pair Teh repository pair. @param builder The dependency graph builder. @param parameters The parameters of the repository combiner. """ repository_name = repository_pair.name check.directory_exists(repository_pair.url) check.directory_exists(repository_pair.url_marked) strategy = parameters.preferring_strategy preferables = parameters.package_names["preferable"] graph, back_graph = builder.build_graph(repository_pair.url, parameters.architecture, preferables, strategy) # Generally speaking, sets of packages in non-marked and marked # repositories can differ. That's why we need to build graphs also for # marked repository. # Nevertheless we assume that graph of marked repository is isomorphic # to some subgraph of the non-marked repository graph. # FIXME: If it's not true in some pratical cases, then the special # treatment is needed. marked_graph, _ = builder.build_graph(repository_pair.url_marked, parameters.architecture, preferables, strategy) return graph, back_graph, marked_graph
def __init__(self, cache_directory, name_checking_function): """ Initializes the repository downloader. @param cache_directory The combirepo cache directory. @param name_checking_function The function that checks URLs to be downloaded. """ check.directory_exists(cache_directory) self._cache_directory = cache_directory self._repositories = [] self._name_checking_function = name_checking_function config_paths = files.find_fast(self._cache_directory, ".repository.conf") for config_path in config_paths: parser = configparser.SafeConfigParser() parser.read(config_path) if not parser.has_section("repository"): logging.error("Repository config {0} does not contain " "[repository] section!".format(config_path)) continue if not parser.has_option("repository", "url"): logging.error("Repository config {0} does not contain " "option \"url\" in section " "[repository]!".format(config_path)) continue url = parser.get("repository", "url") if not parser.has_option("repository", "status"): logging.error("Repository config {0} does not contain " "option \"status\" in section " "[repository]!".format(config_path)) status = "unknown" else: status = parser.get("repository", "status") repository = {} repository["url"] = url repository["path"] = os.path.dirname(config_path) repository["status"] = status global update_repositories if (update_repositories is not None and (url in update_repositories or "all" in update_repositories)): shutil.rmtree(os.path.dirname(config_path)) logging.info("Repository for URL {0} will be " "updated!".format(url)) else: self._repositories.append(repository) for repository in self._repositories: logging.debug("Found repository: {0}".format(repository))
def unrpm(rpm_path, destination_path): """ Unpacks the RPM package from the given location to the given directory. @param rpm_path The path to the RPM file. @param destination_path The path to the destination directory. """ check.file_exists(rpm_path) check.directory_exists(destination_path) if not rpm_path.endswith(".rpm"): logging.error("Given file {0} is not an RPM package!".format(rpm_path)) initial_directory = os.getcwd() os.chdir(destination_path) hidden_subprocess.silent_pipe_call(["rpm2cpio", rpm_path], [ "cpio", "--extract", "--unconditional", "--preserve-modification-time", "--make-directories" ]) os.chdir(initial_directory)
def build_graph(self, repository_path, arch, preferables, strategy, packages_list = None): """ Builds the dependency graph of the given repository. @param repository_path The path to the repository @param arch The architecture to be analyzed @param preferables The list of package names that should be prefered in case of "have choice" problem @return The dependency graph in the form of hash. """ self.preferables.extend(preferables) self.strategy = strategy # If the relative path is given, transform it to the absolute path, # because it will be written to the config file. repository_path = os.path.abspath(repository_path) check.directory_exists(repository_path) self.repository_path = repository_path # Create the unique repository ID. repoid = "analyzed-repo-{0}".format(os.getpid()) config_path = self.__build_yum_config(repoid) self.arch = arch yum_base = self.__setup_yum_base(config_path, repoid, self.arch) graph, back_graph = self.__build_dependency_graph(yum_base, packages_list) if logging.getLogger().getEffectiveLevel() == logging.DEBUG: logging.debug("{0}".format(igraph.summary(graph))) logging.debug("{0}".format(graph)) pid = os.getpid() suffix = re.sub('/', '_', repository_path) dot_file_name = "dependency_graph.{0}.{1}.dot".format(pid, suffix) graph.write_dot(dot_file_name) logging.debug("The graph was exported in DOT format to " "file {0}".format(dot_file_name)) return graph, back_graph
def find_fast(directory, expression): """ Finds all files in the given directory that match the given expression. @param directory The directory. @param expressiion The regular expression. """ logging.debug("Searching expression {0} in directory " "{1}".format(expression, directory)) check.directory_exists(directory) matcher = re.compile(expression) files_found = [] for root, dirs, files in os.walk(directory): for file_name in files: if matcher.match(file_name): path = os.path.join(root, file_name) path = os.path.abspath(path) files_found.append(path) return files_found
def path(self, value): check.directory_exists(value) self._path = value
def output_directory_path(self, value): check.directory_exists(value) self._output_directory_path = value
def temporary_directory_path(self, path): check.directory_exists(path) self._temporary_directory_path = path
def temporary_directory_path(self): """The directory where combirepo stores its cache.""" if self._temporary_directory_path is not None: check.directory_exists(self._temporary_directory_path) return self._temporary_directory_path