def _make_yum_base(): global _yum_base if _yum_base is None: # This seems needed... # otherwise 'cannot open Packages database in /var/lib/rpm' starts to happen with sh.Rooted(True): _yum_base = YumBase() _yum_base.setCacheDir(force=True) return _yum_base
def _get_yum_base(): if Helper._yum_base is None: # This 'root' seems needed... # otherwise 'cannot open Packages database in /var/lib/rpm' starts to happen with sh.Rooted(True): _yum_base = YumBase() _yum_base.setCacheDir(force=True) Helper._yum_base = _yum_base return Helper._yum_base
def _get_yum_base(): if Helper._yum_base is None: # This 'root' seems needed... # otherwise 'cannot open Packages database in /var/lib/rpm' starts to happen with sh.Rooted(True): _yum_base = YumBase() _yum_base.setCacheDir(force=True) Helper._yum_base = _yum_base return Helper._yum_base
def _init(self): from yum import YumBase yum = YumBase() yum.setCacheDir() # urlgrabber is a 3rd party module # try: # if sys.stdout.isatty(): # import imp # from urlgrabber.progress import TextMeter # output = imp.load_source("output", "/usr/share/yum=cli") # yum.repos.setProgressBar(TextMeter(fo=sys.stdout)) # yum.repos.callback = output.CacheProgressCallback() # yumout = output.YumOutput() # freport = ( yumout.failureReport, (), {} ) # yum.repos.setFailureCallback( freport ) # except: # print("Warning: Unable to set progress indicator") return yum
class YumDebugInfoDownload(DebugInfoDownload): def __init__(self, cache, tmp, repo_pattern="*debug*", keep_rpms=False, noninteractive=True): super(YumDebugInfoDownload, self).__init__(cache, tmp, repo_pattern, keep_rpms, noninteractive) self.base = YumBase() def initialize_progress(self, updater): self.progress = YumDownloadCallback(updater) self.base.repos.setProgressBar(self.progress) self.base.repos.setMirrorFailureCallback(downloadErrorCallback) def prepare(self): self.mute_stdout() #self.conf.cache = os.geteuid() != 0 # Setup yum (Ts, RPM db, Repo & Sack) # doConfigSetup() takes some time, let user know what we are doing try: # Saw this exception here: # cannot open Packages index using db3 - Permission denied (13) # yum.Errors.YumBaseError: Error: rpmdb open failed self.base.doConfigSetup() except YumBaseError as ex: self.unmute_stdout() print( _("Error initializing yum (YumBase.doConfigSetup): '{0!s}'"). format(str(ex))) #return 1 - can't do this in constructor exit(1) self.unmute_stdout() # make yumdownloader work as non root user if not self.base.setCacheDir(): print(_("Error: can't make cachedir, exiting")) return RETURN_FAILURE # disable all not needed for repo in self.base.repos.listEnabled(): try: repo.close() self.base.repos.disableRepo(repo.id) except YumBaseError as ex: print( _("Can't disable repository '{0!s}': {1!s}").format( repo.id, str(ex))) def initialize_repositories(self): # setting-up repos one-by-one, so we can skip the broken ones... # this helps when users are using 3rd party repos like rpmfusion # in rawhide it results in: Can't find valid base url... for r in self.base.repos.findRepos(pattern=self.repo_pattern): try: rid = self.base.repos.enableRepo(r.id) self.base.repos.doSetup(thisrepo=str(r.id)) log1("enabled repo %s", rid) setattr(r, "skip_if_unavailable", True) # yes, we want async download, otherwise our progressCallback # is not called and the internal yum's one is used, # which causes artifacts on output try: setattr(r, "_async", False) except (NameError, AttributeError) as ex: print(str(ex)) print( _("Can't disable async download, the output might contain artifacts!" )) except YumBaseError as ex: print( _("Can't setup {0}: {1}, disabling").format(r.id, str(ex))) self.base.repos.disableRepo(r.id) # This is somewhat "magic", it unpacks the metadata making it usable. # Looks like this is the moment when yum talks to remote servers, # which takes time (sometimes minutes), let user know why # we have "paused": try: self.base.repos.populateSack(mdtype='metadata', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving metadata: '{0!s}'").format(str(ex))) #we don't want to die here, some metadata might be already retrieved # so there is a chance we already have what we need #return 1 try: # Saw this exception here: # raise Errors.NoMoreMirrorsRepoError, errstr # NoMoreMirrorsRepoError: failure: # repodata/7e6632b82c91a2e88a66ad848e231f14c48259cbf3a1c3e992a77b1fc0e9d2f6-filelists.sqlite.bz2 # from fedora-debuginfo: [Errno 256] No more mirrors to try. self.base.repos.populateSack(mdtype='filelists', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving filelists: '{0!s}'").format(str(ex))) # we don't want to die here, some repos might be already processed # so there is a chance we already have what we need #return 1 def triage(self, files): not_found = [] package_files_dict = {} todownload_size = 0 installed_size = 0 for debuginfo_path in files: log2("yum whatprovides %s", debuginfo_path) pkg = self.base.pkgSack.searchFiles(debuginfo_path) # sometimes one file is provided by more rpms, we can use either of # them, so let's use the first match if pkg: if pkg[0] in package_files_dict.keys(): package_files_dict[pkg[0]].append(debuginfo_path) else: package_files_dict[pkg[0]] = [debuginfo_path] todownload_size += float(pkg[0].size) installed_size += float(pkg[0].installedsize) log2("found pkg for %s: %s", debuginfo_path, pkg[0]) else: log2("not found pkg for %s", debuginfo_path) not_found.append(debuginfo_path) return (package_files_dict, not_found, todownload_size, installed_size) def download_package(self, pkg): remote = pkg.returnSimple('relativepath') local = os.path.basename(remote) local = os.path.join(self.tmpdir, local) remote_path = pkg.returnSimple('remote_url') # check if the pkg is in a local repo and copy it if it is err = None if remote_path.startswith('file:///'): pkg_path = remote_path[7:] log2("copying from local repo: %s", remote) try: shutil.copy(pkg_path, local) except OSError as ex: err = _("Cannot copy file '{0}': {1}").format( pkg_path, str(ex)) else: # pkg is in a remote repo, we need to download it to tmpdir pkg.localpath = local # Hack: to set the localpath we want err = self.base.downloadPkgs(pkglist=[pkg]) # normalize the name # just str(pkg) doesn't work because it can have epoch return (local, err)
class YumDebugInfoDownload(DebugInfoDownload): def __init__(self, cache, tmp, repo_pattern="*debug*", keep_rpms=False, noninteractive=True): super(YumDebugInfoDownload, self).__init__(cache, tmp, repo_pattern, keep_rpms, noninteractive) self.base = YumBase() def initialize_progress(self, updater): self.progress = YumDownloadCallback(updater) self.base.repos.setProgressBar(self.progress) self.base.repos.setMirrorFailureCallback(downloadErrorCallback) def prepare(self): self.mute_stdout() #self.conf.cache = os.geteuid() != 0 # Setup yum (Ts, RPM db, Repo & Sack) # doConfigSetup() takes some time, let user know what we are doing try: # Saw this exception here: # cannot open Packages index using db3 - Permission denied (13) # yum.Errors.YumBaseError: Error: rpmdb open failed self.base.doConfigSetup() except YumBaseError as ex: self.unmute_stdout() print(_("Error initializing yum (YumBase.doConfigSetup): '{0!s}'").format(str(ex))) #return 1 - can't do this in constructor exit(1) self.unmute_stdout() # make yumdownloader work as non root user if not self.base.setCacheDir(): print(_("Error: can't make cachedir, exiting")) return RETURN_FAILURE # disable all not needed for repo in self.base.repos.listEnabled(): try: repo.close() self.base.repos.disableRepo(repo.id) except YumBaseError as ex: print(_("Can't disable repository '{0!s}': {1!s}").format(repo.id, str(ex))) def initialize_repositories(self): # setting-up repos one-by-one, so we can skip the broken ones... # this helps when users are using 3rd party repos like rpmfusion # in rawhide it results in: Can't find valid base url... for r in self.base.repos.findRepos(pattern=self.repo_pattern): try: rid = self.base.repos.enableRepo(r.id) self.base.repos.doSetup(thisrepo=str(r.id)) log1("enabled repo %s", rid) setattr(r, "skip_if_unavailable", True) # yes, we want async download, otherwise our progressCallback # is not called and the internal yum's one is used, # which causes artifacts on output try: setattr(r, "_async", False) except (NameError, AttributeError) as ex: print(str(ex)) print(_("Can't disable async download, the output might contain artifacts!")) except YumBaseError as ex: print(_("Can't setup {0}: {1}, disabling").format(r.id, str(ex))) self.base.repos.disableRepo(r.id) # This is somewhat "magic", it unpacks the metadata making it usable. # Looks like this is the moment when yum talks to remote servers, # which takes time (sometimes minutes), let user know why # we have "paused": try: self.base.repos.populateSack(mdtype='metadata', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving metadata: '{0!s}'").format(str(ex))) #we don't want to die here, some metadata might be already retrieved # so there is a chance we already have what we need #return 1 try: # Saw this exception here: # raise Errors.NoMoreMirrorsRepoError, errstr # NoMoreMirrorsRepoError: failure: # repodata/7e6632b82c91a2e88a66ad848e231f14c48259cbf3a1c3e992a77b1fc0e9d2f6-filelists.sqlite.bz2 # from fedora-debuginfo: [Errno 256] No more mirrors to try. self.base.repos.populateSack(mdtype='filelists', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving filelists: '{0!s}'").format(str(ex))) # we don't want to die here, some repos might be already processed # so there is a chance we already have what we need #return 1 def triage(self, files): not_found = [] package_files_dict = {} todownload_size = 0 installed_size = 0 for debuginfo_path in files: log2("yum whatprovides %s", debuginfo_path) pkg = self.base.pkgSack.searchFiles(debuginfo_path) # sometimes one file is provided by more rpms, we can use either of # them, so let's use the first match if pkg: if pkg[0] in package_files_dict.keys(): package_files_dict[pkg[0]].append(debuginfo_path) else: package_files_dict[pkg[0]] = [debuginfo_path] todownload_size += float(pkg[0].size) installed_size += float(pkg[0].installedsize) log2("found pkg for %s: %s", debuginfo_path, pkg[0]) else: log2("not found pkg for %s", debuginfo_path) not_found.append(debuginfo_path) return (package_files_dict, not_found, todownload_size, installed_size) def download_package(self, pkg): remote = pkg.returnSimple('relativepath') local = os.path.basename(remote) local = os.path.join(self.tmpdir, local) remote_path = pkg.returnSimple('remote_url') # check if the pkg is in a local repo and copy it if it is err = None if remote_path.startswith('file:///'): pkg_path = remote_path[7:] log2("copying from local repo: %s", remote) try: shutil.copy(pkg_path, local) except OSError as ex: err = _("Cannot copy file '{0}': {1}").format(pkg_path, str(ex)) else: # pkg is in a remote repo, we need to download it to tmpdir pkg.localpath = local # Hack: to set the localpath we want err = self.base.downloadPkgs(pkglist=[pkg]) # normalize the name # just str(pkg) doesn't work because it can have epoch return (local, err)
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from sqlalchemy import create_engine from sqlalchemy.exc import IntegrityError from kitchen.text.converters import to_unicode from models import Root, Category, Group, Package, DBSession, initialize_sql from yum import YumBase yumobj = YumBase() yumobj.setCacheDir() def populate(comps='comps-f16', do_dependencies=True): from yum.comps import Comps session = DBSession() c = Comps() c.add('comps/%s.xml' % comps) for group in c.groups: g = Group(id=group.groupid, name=group.name, description=group.description) session.add(g)
def _get_yum_base(): if Helper._yum_base is None: _yum_base = YumBase() _yum_base.setCacheDir(force=True) Helper._yum_base = _yum_base return Helper._yum_base
def _get_yum_base(): if Helper._yum_base is None: _yum_base = YumBase() _yum_base.setCacheDir(force=True) Helper._yum_base = _yum_base return Helper._yum_base
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from sqlalchemy import create_engine from sqlalchemy.exc import IntegrityError from kitchen.text.converters import to_unicode from models import Root, Category, Group, Package, DBSession, initialize_sql from yum import YumBase yumobj = YumBase() yumobj.setCacheDir() def populate(comps='comps-f16', do_dependencies=True): from yum.comps import Comps session = DBSession() c = Comps() c.add('comps/%s.xml' % comps) for group in c.groups: g = Group(id=group.groupid, name=group.name, description=group.description) session.add(g) for package in group.packages: p = session.query(Package).filter_by(name=to_unicode(package)).first()