Example #1
0
    def testable(self):
        """ Get a list of installed testing updates.

        This method is a generate that yields packages that you currently
        have installed that you have yet to test and provide feedback for.

        """
        from yum import YumBase
        yum = YumBase()
        yum.doConfigSetup(init_plugins=False)
        with open('/etc/fedora-release', 'r') as f:
            fedora = f.readlines()[0].split()[2]
        tag = 'f%s-updates-testing' % fedora
        builds = self.get_koji_session(
            login=False).listTagged(tag, latest=True)
        for build in builds:
            pkgs = yum.rpmdb.searchNevra(name=build['name'],
                                         ver=build['version'],
                                         rel=build['release'],
                                         epoch=None,
                                         arch=None)
            if len(pkgs):
                update_list = self.query(package=[build['nvr']])['updates']
                for update in update_list:
                    yield update
Example #2
0
 def __init__(self, importkeys=False, progress=None):
     """
     Construct a customized instance of YumBase.
     This includes:
       - loading yum plugins.
       - custom configuration.
       - setting the progress bar for download progress reporting.
       - prime our progress report object.
     :param importkeys: Allow the import of GPG keys.
     :type importkeys: bool
     :param progress: A progress reporting object.
     :type progress: ProgressReport
     """
     parser = OptionParser()
     parser.parse_args([])
     self.__parser = parser
     YumBase.__init__(self)
     self.preconf.optparser = self.__parser
     self.preconf.plugin_types = (TYPE_CORE, TYPE_INTERACTIVE)
     self.conf.assumeyes = importkeys
     self.progress = progress or ProgressReport()
     bar = DownloadCallback(self.progress)
     self.repos.setProgressBar(bar)
     self.progress.push_step('Refresh Repository Metadata')
     self.logfile = getLogger('yum.filelogging')
Example #3
0
 def __init__(self, cache, tmp, repo_pattern="*debug*", keep_rpms=False,
              noninteractive=True):
     self.old_stdout = -1
     self.cachedir = cache
     self.tmpdir = tmp
     global TMPDIR
     TMPDIR = tmp
     self.keeprpms = keep_rpms
     self.noninteractive = noninteractive
     self.repo_pattern=repo_pattern
     YumBase.__init__(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
     print _("Initializing yum")
     try:
         # Saw this exception here:
         # cannot open Packages index using db3 - Permission denied (13)
         # yum.Errors.YumBaseError: Error: rpmdb open failed
         self.doConfigSetup()
     except YumBaseError, ex:
         self.unmute_stdout()
         print _("Error initializing yum (YumBase.doConfigSetup): '{0!s}'").format(ex)
         #return 1 - can't do this in constructor
         exit(1)
def get_yum_releasever(yumbase=None):
    if not yumbase:
        yumbase = YumBase()
        yumbase.doConfigSetup(init_plugins=False)
    yum_releaseversion = yumbase.conf.yumvar['releasever']
    releasever = yum_releaseversion.lower().replace('server', '')
    return releasever
Example #5
0
    def testable(self):
        """ Get a list of installed testing updates.

        This method is a generate that yields packages that you currently
        have installed that you have yet to test and provide feedback for.

        """
        from yum import YumBase
        yum = YumBase()
        yum.doConfigSetup(init_plugins=False)
        with open('/etc/fedora-release', 'r') as f:
            fedora = f.readlines()[0].split()[2]
        tag = 'f%s-updates-testing' % fedora
        builds = self.get_koji_session(login=False).listTagged(tag,
                                                               latest=True)
        for build in builds:
            pkgs = yum.rpmdb.searchNevra(name=build['name'],
                                         ver=build['version'],
                                         rel=build['release'],
                                         epoch=None,
                                         arch=None)
            if len(pkgs):
                update_list = self.query(package=[build['nvr']])['updates']
                for update in update_list:
                    yield update
Example #6
0
def get_yum_releasever(yumbase=None):
    if not yumbase:
        yumbase = YumBase()
        yumbase.doConfigSetup(init_plugins=False)
    yum_releaseversion = yumbase.conf.yumvar['releasever']
    releasever = yum_releaseversion.lower().replace('server', '')
    return releasever
Example #7
0
 def __init__(self, importkeys=False, progress=None):
     """
     Construct a customized instance of YumBase.
     This includes:
       - loading yum plugins.
       - custom configuration.
       - setting the progress bar for download progress reporting.
       - prime our progress report object.
     :param importkeys: Allow the import of GPG keys.
     :type importkeys: bool
     :param progress: A progress reporting object.
     :type progress: ProgressReport
     """
     parser = OptionParser()
     parser.parse_args([])
     self.__parser = parser
     YumBase.__init__(self)
     self.preconf.optparser = self.__parser
     self.preconf.plugin_types = (TYPE_CORE, TYPE_INTERACTIVE)
     self.conf.assumeyes = importkeys
     self.progress = progress or ProgressReport()
     bar = DownloadCallback(self.progress)
     self.repos.setProgressBar(bar)
     self.progress.push_step('Refresh Repository Metadata')
     self.logfile = getLogger('yum.filelogging')
Example #8
0
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
Example #10
0
 def close(self):
     """
     This should be handled by __del__() but YumBase
     objects never seem to completely go out of scope and
     garbage collected.
     """
     YumBase.close(self)
     self.closeRpmDB()
     self.cleanLoggers()
Example #11
0
 def doPluginSetup(self, *args, **kwargs):
     """
     Set command line arguments.
     Support TYPE_INTERACTIVE plugins.
     """
     YumBase.doPluginSetup(self, *args, **kwargs)
     p = self.__parser
     options, args = p.parse_args([])
     self.plugins.setCmdLine(options, args)
Example #12
0
 def close(self):
     """
     This should be handled by __del__() but YumBase
     objects never seem to completely go out of scope and
     garbage collected.
     """
     YumBase.close(self)
     self.closeRpmDB()
     self.cleanLoggers()
Example #13
0
 def doPluginSetup(self, *args, **kwargs):
     """
     Set command line arguments.
     Support TYPE_INTERACTIVE plugins.
     """
     YumBase.doPluginSetup(self, *args, **kwargs)
     p = self.__parser
     options, args = p.parse_args([])
     self.plugins.setCmdLine(options, args)
 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
Example #15
0
    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()
Example #16
0
 def __init__(self, importkeys=False):
     """
     @param importkeys: Allow the import of GPG keys.
     @type importkeys: bool
     """
     parser = OptionParser()
     parser.parse_args([])
     self.__parser = parser
     YumBase.__init__(self)
     self.preconf.optparser = self.__parser
     self.preconf.plugin_types = (TYPE_CORE, TYPE_INTERACTIVE)
     self.conf.assumeyes = importkeys
 def generate(repofn):
     """
     Generate the report content.
     :param repofn: The .repo file basename used to filter the report.
     :type repofn: str
     :return: The report content
     :rtype: dict
     """
     yb = YumBase()
     try:
         return dict(enabled_repos=EnabledReport.find_enabled(yb, repofn))
     finally:
         yb.close()
Example #18
0
    def __init__(self,
                 cache,
                 tmp,
                 repo_pattern="*debug*",
                 keep_rpms=False,
                 noninteractive=True,
                 releasever=None):
        super(YumDebugInfoDownload, self).__init__(cache, tmp, repo_pattern,
                                                   keep_rpms, noninteractive)

        self.base = YumBase()
        if not releasever is None:
            self.base.conf.substitutions['releasever'] = releasever
Example #19
0
 def processTransaction(self):
     """
     Process the transaction.
     The method is overridden so we can add progress reporting.
     The *callback* is used to report high-level progress.
     The *display* is used to report rpm-level progress.
     """
     try:
         callback = ProcessTransCallback(self.progress)
         display = RPMCallback(self.progress)
         YumBase.processTransaction(self, callback, rpmDisplay=display)
         self.progress.set_status(True)
     except Exception:
         self.progress.set_status(False)
         raise
Example #20
0
 def processTransaction(self):
     """
     Process the transaction.
     The method is overridden so we can add progress reporting.
     The *callback* is used to report high-level progress.
     The *display* is used to report rpm-level progress.
     """
     try:
         callback = ProcessTransCallback(self.progress)
         display = RPMCallback(self.progress)
         YumBase.processTransaction(self, callback, rpmDisplay=display)
         self.progress.set_status(True)
     except Exception:
         self.progress.set_status(False)
         raise
Example #21
0
    def __init__(self, cache, tmp, repo_pattern="*debug*", keep_rpms=False,
                 noninteractive=True, releasever=None):
        super(YumDebugInfoDownload, self).__init__(cache, tmp, repo_pattern, keep_rpms, noninteractive)

        self.base = YumBase()
        if not releasever is None:
            self.base.conf.substitutions['releasever'] = releasever
Example #22
0
    def resolveCode(self):
        solver = YumBase()
        solver.save_ts = save_ts
        solver.conf = FakeConf()
        solver.arch.setup_arch('x86_64')
        solver.tsInfo = solver._tsInfo = self.tsInfo
        solver.rpmdb = self.rpmdb
        solver.pkgSack = self.xsack

        for po in self.rpmdb:
            po.repoid = po.repo.id = "installed"
        for po in self.xsack:
            if po.repo.id is None:
                po.repo.id = "TestRepository"
            po.repoid = po.repo.id
        for txmbr in self.tsInfo:
            if txmbr.ts_state in ('u', 'i'):
                if txmbr.po.repo.id is None:
                    txmbr.po.repo.id = "TestRepository"
                txmbr.po.repoid = txmbr.po.repo.id
            else:
                txmbr.po.repoid = txmbr.po.repo.id = "installed"

        result, msg = solver.resolveDeps()
        return (self.res[result], msg)
 def __init__(self, cache, tmp, keep_rpms=False):
     self.cachedir = cache
     self.tmpdir = tmp
     self.keeprpms = keep_rpms
     YumBase.__init__(self)
     mute_stdout()
     #self.conf.cache = os.geteuid() != 0
     # Setup yum (Ts, RPM db, Repo & Sack)
     try:
         # Saw this exception here:
         # cannot open Packages index using db3 - Permission denied (13)
         # yum.Errors.YumBaseError: Error: rpmdb open failed
         self.doConfigSetup()
     except Exception, e:
         unmute_stdout()
         print _("Error initializing yum (YumBase.doConfigSetup): '%s'") % str(e)
         #return 1 - can't do this in constructor
         exit(1)
 def __init__(self, cache, tmp, keep_rpms=False):
     self.cachedir = cache
     self.tmpdir = tmp
     self.keeprpms = keep_rpms
     YumBase.__init__(self)
     mute_stdout()
     #self.conf.cache = os.geteuid() != 0
     # Setup yum (Ts, RPM db, Repo & Sack)
     try:
         # Saw this exception here:
         # cannot open Packages index using db3 - Permission denied (13)
         # yum.Errors.YumBaseError: Error: rpmdb open failed
         self.doConfigSetup()
     except Exception, e:
         unmute_stdout()
         print _("Error initializing yum (YumBase.doConfigSetup): '%s'"
                 ) % str(e)
         #return 1 - can't do this in constructor
         exit(1)
Example #25
0
	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
Example #26
0
    def resolveCode(self):
        solver = YumBase()
        solver.save_ts  = save_ts
        solver.conf = FakeConf()
        solver.arch.setup_arch('x86_64')
        solver.tsInfo = solver._tsInfo = self.tsInfo
        solver.rpmdb = self.rpmdb
        solver.pkgSack = self.xsack

        for po in self.rpmdb:
            po.repoid = po.repo.id = "installed"
        for po in self.xsack:
            if po.repo.id is None:
                po.repo.id = "TestRepository"
            po.repoid = po.repo.id
        for txmbr in self.tsInfo:
            if txmbr.ts_state in ('u', 'i'):
                if txmbr.po.repo.id is None:
                    txmbr.po.repo.id = "TestRepository"
                txmbr.po.repoid = txmbr.po.repo.id
            else:
                txmbr.po.repoid = txmbr.po.repo.id = "installed"

        result, msg = solver.resolveDeps()
        return (self.res[result], msg)
Example #27
0
def _run_transaction(transaction_name, install_mode, remove_mode):
    import os
    from yum import YumBase

    transaction = open(os.path.join(config.STACKDIR, transaction_name),
            'r')

    my_yum = YumBase()
    
    for line in transaction:
        line = line.strip()
        parts = line.split(' ')
        if parts[0] == install_mode:
            fn = my_yum.install
        elif parts[0] == remove_mode:
            fn = my_yum.remove
        else:
            assert False, "corrupt transaction file"

        if parts[2] == 'None':
            parts[2] = None
        fn(name=parts[1], epoch=parts[2], version=parts[3],
                release=parts[4], arch=parts[5])

    dlpkgs = map(lambda x: x.po, filter(lambda txmbr:
                                        txmbr.ts_state in ("i", "u"),
                                        my_yum.tsInfo.getMembers()))
    my_yum.downloadPkgs(dlpkgs)

    my_yum.initActionTs() # make a new, blank ts to populate
    my_yum.populateTs(keepold=0)
    my_yum.ts.check() #required for ordering
    my_yum.ts.order() # order

    # FIXME: is it really sane to use this from here?
    import sys
    sys.path.append('/usr/share/yum-cli')
    import callback

    cb = callback.RPMInstallCallback(output = 0)
    cb.filelog = True
    cb.tsInfo = my_yum.tsInfo
    my_yum.runTransaction(cb)
Example #28
0
 def setUp(self):
     self.db_dir = tempfile.mkdtemp()
     productid.DatabaseDirectory.PATH = self.db_dir
     self.pm = productid.ProductManager()
     cert1 = stubs.StubEntitlementCertificate(
         stubs.StubProduct('product1'),
         start_date=datetime.datetime(2010, 1, 1),
         end_date=datetime.datetime(2050, 1, 1))
     cert2 = stubs.StubEntitlementCertificate(
         stubs.StubProduct('product2'),
         start_date=datetime.datetime(2010, 1, 1),
         end_date=datetime.datetime(2060, 1, 1))
     self.pm.pdir = stubs.StubProductDirectory([cert1, cert2])
     sys.stdout = stubs.MockStdout()
     self.yb = YumBase()
Example #29
0
 def __init__(self, cache, tmp, keep_rpms=False, noninteractive=True):
     self.cachedir = cache
     self.tmpdir = tmp
     global tmpdir
     tmpdir = tmp
     self.keeprpms = keep_rpms
     self.noninteractive = noninteractive
     YumBase.__init__(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
     print _("Initializing yum")
     try:
         # Saw this exception here:
         # cannot open Packages index using db3 - Permission denied (13)
         # yum.Errors.YumBaseError: Error: rpmdb open failed
         self.doConfigSetup()
     except Exception, e:
         unmute_stdout()
         print _("Error initializing yum (YumBase.doConfigSetup): '{0!s}'"
                 ).format(e)
         #return 1 - can't do this in constructor
         exit(1)
Example #30
0
def YumSingleton():
    from StringIO import StringIO
    new_out = StringIO()
    sav_out = (sys.stdout, sys.stderr)  # save old IO
    [x.flush() for x in sav_out]  # flush output
    sys.stdout = sys.stderr = new_out
    ex = None
    try:
        yb = YumBase()
        yb.conf
        return yb
    except Exception as x:
        ex = x  # save exception
    finally:
        new_out.flush()  # grab the output
        (sys.stdout, sys.stderr) = sav_out  # restore it
    # if we got here, then we had an error
    sys.stderr.write(str(new_out))
    raise ex if ex else Exception('Error creating yum.YumBase()')
Example #31
0
def YumSingleton():
    from StringIO import StringIO
    new_out = StringIO()
    sav_out = (sys.stdout, sys.stderr)  # save old IO
    [x.flush() for x in sav_out]  # flush output
    sys.stdout = sys.stderr = new_out
    ex = None
    try:
        yb = YumBase()
        yb.conf
        return yb
    except Exception as x:
        ex = x  # save exception
        raise  # raise the exception with stack
    finally:
        new_out.flush()  # grab the output
        (sys.stdout, sys.stderr) = sav_out  # restore it
        if ex:  # if there was an error, then print it out
            sys.stderr.write(str(new_out))
Example #32
0
 def __init__(self):
     YumBase.__init__(self)
     self.conf.assumeyes = True
Example #33
0
 def __init__(self):
     YumBase.__init__(self)
     self.conf.assumeyes = True
Example #34
0
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)
Example #35
0
    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()
Example #36
0
def main(directory, version):
    """
    Update packages in directory and install all those available

    @type  directory: string
    @param directory: path to the directory which contains a copy of the whole system

    @type  version: string
    @param version: PowerKVM version used to update system

    @rtype: boolean
    @returns: True if the packages was successfully updated;
              False otherwise
    """
    os.chroot(directory)

    # update all packages
    yumBase = YumBase()

    # get all enabled repos
    enabledRepos = yumBase.repos.listEnabled()

    # disable all yum repos
    yumBase.repos.disableRepo('*')

    # enable only the powerkvm repo
    yumBase.repos.enableRepo('powerkvm-%s' % version)

    # update system
    yumBase.update()

    rc, msgs = yumBase.buildTransaction()
    if rc != 2:
        return False

    try:
        yumBase.processTransaction()
    except:
        return False

    # check if there is more than one kernel installed
    # if so, remove one
    availableKernels = yumBase.searchPackages(['name'], ['kernel'])
    installedKernels = 0

    for pkg in availableKernels:
        if pkg.repoid == 'installed' and pkg.name == 'kernel':
            installedKernels += 1

    if installedKernels != 1:
        yumBase.remove(name='kernel')

    # install new packages available in the repo
    pkgs = yumBase.doPackageLists().available
    for pkg in pkgs:
        yumBase.install(pkg)

    # build and process the YUM transaction
    rc, msgs = yumBase.buildTransaction()
    if rc != 2:
        return False

    try:
        yumBase.processTransaction()
    except:
        return False

    # re-enable the repos
    for repo in enabledRepos:
        repo.enable()

    return True
Example #37
0
# This program is distributed in the hope that it will be useful,
# 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)
Example #38
0
# This program is distributed in the hope that it will be useful,
# 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:
Example #39
0
#coding: utf-8
#
# Ailurus - a simple application installer and GNOME tweaker
#
# Copyright (C) 2009-2010, Ailurus developers and Ailurus contributors
# Copyright (C) 2007-2010, Trusted Digital Technology Laboratory, Shanghai Jiao Tong University, China.
#
# Ailurus is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Ailurus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ailurus; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

import sys
from yum import YumBase
base = YumBase()
ygh = base.doPackageLists()
for available in ygh.available:
    name = available.pkgtup[0]
    print >>sys.stderr, name # because base.doPackageLists prints text to stdout
Example #40
0
 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
Example #41
0
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)
Example #42
0
 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
import os
import json
from urlparse import urljoin
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from yum import YumBase

# Disable insecure requests warning
# So we don't break our syslog handler.
# This (disabled) warning is expected due to our use of
# self-signed certificates when we communicate between
# the agent and manager.
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

yp = YumBase()
yp.preconf.debuglevel = 0
yp.preconf.errorlevel = 0
yp.doLock()
yp.getReposFromConfig()
yp.doSackFilelistPopulate()

packages = ["python2-iml-agent"]

if "IML_PROFILE_PACKAGES" in os.environ:
    packages += os.environ["IML_PROFILE_PACKAGES"].split(",")

ypl = yp.doPackageLists(pkgnarrow="updates", patterns=packages)

has_updates = len(ypl.updates) > 0