def load_repository(self, repo_id): """Download repo metadata. If the repo is enabled, load its metadata to verify that the repo is valid. An invalid repo will be disabled. This method will by default not try to refresh already loaded data if called repeatedly. :param str repo_id: an identifier of a repository :raise: MetadataError if the metadata cannot be loaded """ log.debug("Load metadata for the '%s' repository.", repo_id) repo = self._get_repository(repo_id) url = repo.baseurl or repo.mirrorlist or repo.metalink if not repo.enabled: log.debug("Don't load metadata from a disabled repository.") return try: repo.load() except dnf.exceptions.RepoError as e: log.debug("Failed to load metadata from '%s': %s", url, str(e)) repo.disable() raise MetadataError(str(e)) from None log.info("Loaded metadata from '%s'.", url)
def __init__(self, setup_sack=True, pbar=None): dnf.Base.__init__(self) # setup the dnf cache RELEASEVER = dnf.rpm.detect_releasever(self.conf.installroot) self.conf.substitutions['releasever'] = RELEASEVER # progress = progress_ui.Progress() ## Package queue self.packageQueue = pkgs.PackageQueue() # read the repository infomation self.read_all_repos() if setup_sack: # populate the dnf sack repos = self.repos.iter_enabled() #all() for repo in repos: if pbar != None: repo.set_progress_bar(pbar) try: repo.load() except dnf.exceptions.RepoError as e: # TODO log and eventually manage it print(e) #repo.set_progress_bar(None) self.fill_sack() self._packages = pkgs.Packages(self) # Define a Packages object
def test_reset_metadata_expired(self): repo = self.repo repo.load() repo.metadata_expire = 0 repo._reset_metadata_expired() self.assertTrue(repo.metadata.expired) repo.metadata_expire = 'never' repo._reset_metadata_expired() self.assertFalse(repo.metadata.expired)
def test_metadata_expire_in(self): repo = self.repo self.assertEqual(repo._metadata_expire_in(), (False, 0)) repo.load() (has, time) = repo._metadata_expire_in() self.assertTrue(has) self.assertGreater(time, 0) repo.metadata_expire = 'never' self.assertEqual(repo._metadata_expire_in(), (True, None))
def test_load(self): # dnf.repo.Repo.load repo = dnf.repo.Repo() class MockRepo: def load(self): return True repo._repo = MockRepo() self.assertHasAttr(repo, "load") repo.load()
def test_reset_metadata_expired(self): repo = self.repo repo.load() repo.metadata_expire = 0 repo._reset_metadata_expired() self.assertTrue(repo._expired) # the expired state only resets outside of _reset_metadata_expired(): repo.metadata_expired = 'never' self.assertTrue(repo._expired) repo._expired = False repo.metadata_expire = 'never' repo._reset_metadata_expired() self.assertFalse(repo._expired)
def test_md_lazy(self): self.repo.load() self.setUp() repo = self.repo repo._md_expire_cache() repo._md_lazy = True self.assertFalse(repo.load())
def test_load(self): repo = self.repo self.assertIsNone(repo.metadata) self.assertTrue(repo.load()) self.assertIsNotNone(repo.metadata) repomd = os.path.join(self.repo._cachedir, "repodata/repomd.xml") self.assertTrue(os.path.isfile(repomd)) self.assertTrue(repo.metadata.fresh)
def _fetch_md(self, repo_name): """Download repo metadata :param repo_name: name/id of repo to fetch :type repo_name: str :returns: None """ repo = self._base.repos[repo_name] repo.enable() try: # Load the metadata to verify that the repo is valid repo.load() except dnf.exceptions.RepoError as e: repo.disable() log.debug("repo: '%s' - %s failed to load repomd", repo.id, repo.baseurl or repo.mirrorlist or repo.metalink) raise MetadataError(e) from e log.info("enabled repo: '%s' - %s and got repomd", repo.id, repo.baseurl or repo.mirrorlist or repo.metalink)
def load_repository(self, repo_id): """Download repo metadata. Enable the repo and load its metadata to verify that the repo is valid. An invalid repo will be disabled. :param str repo_id: an identifier of a repository :raise: MetadataError if the metadata cannot be loaded """ log.debug("Load metadata for the '%s' repository.", repo_id) repo = self._get_repository(repo_id) url = repo.baseurl or repo.mirrorlist or repo.metalink try: repo.enable() repo.load() except dnf.exceptions.RepoError as e: log.debug("Failed to load metadata from '%s': %s", url, str(e)) repo.disable() raise MetadataError(str(e)) from None log.info("Loaded metadata from '%s'.", url)
def build_dnf(self, config): dnf_base = dnf.Base() for repo in dnf_base.repos.all(): repo.disable() for repo_id, repo_opts in config['repos'].items(): repo = dnf.repo.Repo(repo_id, self.dnf_temp_cache) repo.enable() for opt, val in repo_opts.items(): # Inject is a custom option and DNF won't recognize it if opt == "inject": continue setattr(repo, opt, val) repo.load() dnf_base.repos.add(repo) log.debug("Defined repo %s" % repo.id) # Do not consider *anything* to be installed dnf_base.fill_sack(load_system_repo=False, load_available_repos=True) return dnf_base