def run(self): """Execute the util action here.""" pkgs = self.base.sack.query().filterm(empty=True) no_matched_spec = [] for module_spec in self.opts.module: try: pkgs = pkgs.union(self._get_packages_from_modules(module_spec)) except dnf.exceptions.Error: no_matched_spec.append(module_spec) if no_matched_spec: msg = P_("Unable to find a match for argument: '{}'", "Unable to find a match for arguments: '{}'", len(no_matched_spec)).format("' '".join(no_matched_spec)) raise dnf.exceptions.Error(msg) if self.opts.resolve: pkgs = pkgs.union(self._get_providers_of_requires(pkgs)) # download rpms self._do_downloads(pkgs) # Create a repository at destdir with modular data remove_tmp_moduleyamls_files = [] for repo in self.base.repos.iter_enabled(): module_md_path = repo.get_metadata_path('modules') if module_md_path: filename = "".join( [repo.id, "-", os.path.basename(module_md_path)]) dest_path = os.path.join(self.base.conf.destdir, filename) shutil.copy(module_md_path, dest_path) remove_tmp_moduleyamls_files.append(dest_path) args = [ "createrepo_c", "--update", "--unique-md-filenames", self.base.conf.destdir ] p = subprocess.run(args) if p.returncode: msg = _( "Creation of repository failed with return code {}. All downloaded content was kept on the system" ) msg = msg.format(p.returncode) raise dnf.exceptions.Error(msg) for file_path in remove_tmp_moduleyamls_files: os.remove(file_path)
def add_repo(self): """ process --add-repo option """ # Get the reposdir location myrepodir = self.base.conf.get_reposdir errors_count = 0 for url in self.opts.add_repo: if dnf.pycomp.urlparse.urlparse(url).scheme == '': url = 'file://' + os.path.abspath(url) logger.info(_('Adding repo from: %s'), url) if url.endswith('.repo'): # .repo file - download, put into reposdir and enable it destname = os.path.basename(url) destname = os.path.join(myrepodir, destname) try: f = self.base.urlopen(url, mode='w+') shutil.copy2(f.name, destname) os.chmod(destname, 0o644) f.close() except IOError as e: errors_count += 1 logger.error(e) continue else: # just url to repo, create .repo file on our own repoid = sanitize_url_to_fs(url) reponame = 'created by {} config-manager from {}'.format( dnf.util.MAIN_PROG, url) destname = os.path.join(myrepodir, "%s.repo" % repoid) content = "[%s]\nname=%s\nbaseurl=%s\nenabled=1\n" % \ (repoid, reponame, url) if not save_to_file(destname, content): continue if errors_count: raise dnf.exceptions.Error( P_("Configuration of repo failed", "Configuration of repos failed", errors_count))
def run(self): if self.opts.since: logger.info( _('Listing changelogs since {}').format(self.opts.since)) elif self.opts.count: logger.info( P_('Listing only latest changelog', 'Listing {} latest changelogs', self.opts.count).format(self.opts.count)) elif self.opts.upgrades: logger.info( _('Listing only new changelogs since installed version of the package' )) else: logger.info(_('Listing all changelogs')) by_srpm = self.by_srpm(self.query()) for name in by_srpm: print( _('Changelogs for {}').format(', '.join( sorted({str(pkg) for pkg in by_srpm[name]})))) for chlog in self.filter_changelogs(by_srpm[name][0]): print(self.base.format_changelog(chlog))