Example #1
0
 def rpmdb_warn_checks():
     try:
         probs = base._rpmdb_warn_checks(out=verbose_logger.info, warn=False)
     except Errors.YumBaseError, e:
         # This is mainly for PackageSackError from rpmdb.
         verbose_logger.info(_(" Yum checks failed: %s"), exception2msg(e))
         probs = []
Example #2
0
 def rpmdb_warn_checks():
     try:
         probs = base._rpmdb_warn_checks(out=verbose_logger.info, warn=False)
     except Errors.YumBaseError, e:
         # This is mainly for PackageSackError from rpmdb.
         verbose_logger.info(_(" Yum checks failed: %s"), exception2msg(e))
         probs = []
Example #3
0
 def exIOError(e):
     if e.errno == 32:
         logger.critical(_('\n\nExiting on Broken Pipe'))
     else:
         logger.critical(_('\n\n%s') % exception2msg(e))
     if unlock(): return 200
     return 1
Example #4
0
 def exIOError(self, e):
     if e.errno == 32:
         self.logger.critical(_('\n\nExiting on Broken Pipe'))
     else:
         self.logger.critical(_('\n\n%s') % exception2msg(e))
     if self.unlock(): return 200
     return 1
Example #5
0
    def downloadPackages(self, opts):

        toDownload = []

        packages = self.cmds
        for pkg in packages:
            toActOn = []

            if not pkg or pkg[0] != '@':
                pkgnames = [pkg]
            else:
                group_string = pkg[1:]
                pkgnames = set()
                for grp in self.comps.return_groups(group_string):
                    if 'mandatory' in self.conf.group_package_types:
                        pkgnames.update(grp.mandatory_packages)
                    if 'default' in self.conf.group_package_types:
                        pkgnames.update(grp.default_packages)
                    if 'optional' in self.conf.group_package_types:
                        pkgnames.update(grp.optional_packages)
                    if self.conf.enable_group_conditionals:
                        for condreq, cond in grp.conditional_packages.iteritems(
                        ):
                            if self.isPackageInstalled(cond):
                                pkgnames.add(condreq)

                if not pkgnames:
                    self.logger.error('No packages for group %s' %
                                      group_string)
                    continue

            pos = self.pkgSack.returnPackages(patterns=pkgnames)
            exactmatch, matched, unmatched = parsePackages(pos, pkgnames)
            installable = (exactmatch + matched)
            if not installable:
                try:
                    installable = self.returnPackagesByDep(pkg)
                    installable = yum.misc.unique(installable)
                except yum.Errors.YumBaseError, msg:
                    self.logger.error(exception2msg(msg))
                    continue

            if not installable:  # doing one at a time, apart from groups
                self.logger.error('No Match for argument %s' % pkg)
                continue
            for newpkg in installable:
                toActOn.extend(_best_convert_pkg2srcpkgs(self, opts, newpkg))
            if toActOn:
                pkgGroups = self._groupPackages(toActOn)
                for group in pkgGroups:
                    pkgs = pkgGroups[group]
                    if opts.source:
                        toDownload.extend(
                            self.bestPackagesFromList(pkgs, 'src'))
                    elif opts.archlist:
                        for arch in opts.archlist.split(','):
                            toDownload.extend(
                                self.bestPackagesFromList(pkgs, arch))
                    else:
                        toDownload.extend(self.bestPackagesFromList(pkgs))
Example #6
0
    def dequeue(self, block=True):
        """ Try to De-Queue a delta rebuild and spawn the rebuild process. """
        # Do this here, just to keep the zombies at bay...
        self._wait()

        if not self._future_jobs:
            return False

        if self.limit <= len(self.jobs):
            if not block:
                return False
            self.wait(len(self.jobs) - self.limit + 1)

        po = self._future_jobs.pop(0)
        args = ('-a', po.arch)
        if po.oldrpm: args += '-r', po.oldrpm
        args += po.localpath, po.rpm.localpath

        try:
            pid = os.spawnl(os.P_NOWAIT, APPLYDELTA, APPLYDELTA, *args)
        except OSError as e:
            raise MiscError(
                _('Couldn\'t spawn %s: %s') % (APPLYDELTA, exception2msg(e)))
        self.jobs[pid] = po
        return True
Example #7
0
 def exIOError(e):
     if e.errno == 32:
         logger.critical(_("\n\nExiting on Broken Pipe"))
     else:
         logger.critical(_("\n\n%s") % exception2msg(e))
     if unlock():
         return 200
     return 1
Example #8
0
 def waitForLock(self):
     lockerr = ""
     while True:
         try:
             self.doLock()
         except Errors.LockError, e:
             if exception2msg(e) != lockerr:
                 lockerr = exception2msg(e)
                 self.logger.critical(lockerr)
             if not self.conf.exit_on_lock:
                 self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...")  
                 show_lock_owner(e.pid, self.logger)
                 time.sleep(2)
             else:
                 raise Errors.YumBaseError, _("Another app is currently holding the yum lock; exiting as configured by exit_on_lock")
         else:
             break
Example #9
0
    def doUtilConfigSetup(self,
                          args=sys.argv[1:],
                          pluginsTypes=(plugins.TYPE_CORE, )):
        """Parse command line options, and perform configuration.

        :param args: list of arguments to use for configuration
        :param pluginsTypes: a sequence specifying the types of
           plugins to load
        :return: a dictionary containing the values of command line options
        """
        # Parse only command line options that affect basic yum setup
        opts = self._parser.firstParse(args)

        # go through all the setopts and set the global ones
        self._parseSetOpts(opts.setopts)

        if self.main_setopts:
            for opt in self.main_setopts.items:
                setattr(opts, opt, getattr(self.main_setopts, opt))

        # Just print out the version if that's what the user wanted
        if opts.version:
            self._printUtilVersion()
            sys.exit(0)
        # get the install root to use
        root = self._parser.getRoot(opts)
        if opts.quiet:
            opts.debuglevel = 0
        if opts.verbose:
            opts.debuglevel = opts.errorlevel = 6

        # Read up configuration options and initialise plugins
        try:
            pc = self.preconf
            pc.fn = opts.conffile
            pc.root = root
            pc.init_plugins = not opts.noplugins
            pc.plugin_types = pluginsTypes
            pc.optparser = self._parser
            pc.debuglevel = opts.debuglevel
            pc.errorlevel = opts.errorlevel
            if hasattr(opts, "disableplugins"):
                pc.disabled_plugins = self._parser._splitArg(
                    opts.disableplugins)
            if hasattr(opts, "enableplugins"):
                pc.enabled_plugins = self._parser._splitArg(opts.enableplugins)
            if hasattr(opts, "releasever"):
                pc.releasever = opts.releasever
            self.conf

            # now set  all the non-first-start opts from main from our setopts
            if self.main_setopts:
                for opt in self.main_setopts.items:
                    setattr(self.conf, opt, getattr(self.main_setopts, opt))

        except Errors.ConfigError, e:
            self.logger.critical(_('Config Error: %s'), exception2msg(e))
            sys.exit(1)
Example #10
0
 def main(self):
     # Add command line option specific to yumdownloader
     self.addCmdOptions()
     # Parse the commandline option and setup the basics.
     try:
         opts = self.doUtilConfigSetup()
     except yum.Errors.RepoError, e:
         self.logger.error(exception2msg(e))
         sys.exit(50)
Example #11
0
 def main(self):
     # Add command line option specific to yumdownloader
     self.addCmdOptions()
     # Parse the commandline option and setup the basics.
     try:
         opts = self.doUtilConfigSetup()
     except yum.Errors.RepoError, e:
         self.logger.error(exception2msg(e))
         sys.exit(50)
Example #12
0
    def exFatal(self, e):
        """Output a message stating that a fatal error has occurred.

        :param e: the exception
        :return: the exit code
        """
        self.logger.critical('\n\n%s', exception2msg(e))
        if self.unlock(): return 200
        return 1
Example #13
0
    def exFatal(self, e):
        """Output a message stating that a fatal error has occurred.

        :param e: the exception
        :return: the exit code
        """
        self.logger.critical('\n\n%s', exception2msg(e))
        if self.unlock(): return 200
        return 1
Example #14
0
    def downloadPackages(self,opts):
        
        toDownload = []
    
        packages = self.cmds
        for pkg in packages:
            toActOn = []

            if not pkg or pkg[0] != '@':
                pkgnames = [pkg]
            else:
                group_string = pkg[1:]
                pkgnames = set()
                for grp in self.comps.return_groups(group_string):
                    if 'mandatory' in self.conf.group_package_types:
                        pkgnames.update(grp.mandatory_packages)
                    if 'default' in self.conf.group_package_types:
                        pkgnames.update(grp.default_packages)
                    if 'optional' in self.conf.group_package_types:
                        pkgnames.update(grp.optional_packages)
                    if self.conf.enable_group_conditionals:
                        for condreq, cond in grp.conditional_packages.iteritems():
                            if self.isPackageInstalled(cond):
                                pkgnames.add(condreq)

                if not pkgnames:
                    self.logger.error('No packages for group %s' % group_string)
                    continue

            pos = self.pkgSack.returnPackages(patterns=pkgnames)
            exactmatch, matched, unmatched = parsePackages(pos, pkgnames)
            installable = (exactmatch + matched)
            if not installable:
                try:
                    installable = self.returnPackagesByDep(pkg)
                    installable = yum.misc.unique(installable)
                except yum.Errors.YumBaseError, msg:
                    self.logger.error(exception2msg(msg))
                    continue

            if not installable: # doing one at a time, apart from groups
                self.logger.error('No Match for argument %s' % pkg)
                continue
            for newpkg in installable:
                toActOn.extend(_best_convert_pkg2srcpkgs(self, opts, newpkg))
            if toActOn:
                pkgGroups = self._groupPackages(toActOn)
                for group in pkgGroups:
                    pkgs = pkgGroups[group]
                    if opts.source:
                        toDownload.extend(self.bestPackagesFromList(pkgs, 'src'))
                    elif opts.archlist:
                        for arch in opts.archlist.split(','):
                            toDownload.extend(self.bestPackagesFromList(pkgs, arch))
                    else:
                        toDownload.extend(self.bestPackagesFromList(pkgs))
Example #15
0
    def exRepoError(e):
        # For RepoErrors ... help out by forcing new repodata next time.
        # XXX: clean only the repo that has failed?
        try:
            base.cleanExpireCache()
        except Errors.YumBaseError:
            # Let's not confuse the user further (they don't even know we tried
            # the clean).
            pass

        msg = _("""\
 One of the configured repositories failed (%(repo)s),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=%(repoid)s ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable %(repoid)s
        or
            subscription-manager repos --disable=%(repoid)s

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=%(repoid)s.skip_if_unavailable=true
""")

        repoui = _('Unknown')
        repoid = _('<repoid>')
        try:
            repoid = e.repo.id
            repoui = e.repo.name
        except AttributeError:
            pass

        msg = msg % {'repoid' : repoid, 'repo' : repoui}

        logger.critical('\n\n%s\n%s', msg, exception2msg(e))

        if unlock(): return 200
        return 1
Example #16
0
    def exRepoError(e):
        # For RepoErrors ... help out by forcing new repodata next time.
        # XXX: clean only the repo that has failed?
        try:
            base.cleanExpireCache()
        except Errors.YumBaseError:
            # Let's not confuse the user further (they don't even know we tried
            # the clean).
            pass

        msg = _("""\
 One of the configured repositories failed (%(repo)s),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=%(repoid)s ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable %(repoid)s
        or
            subscription-manager repos --disable=%(repoid)s

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=%(repoid)s.skip_if_unavailable=true
""")

        repoui = _('Unknown')
        repoid = _('<repoid>')
        try:
            repoid = e.repo.id
            repoui = e.repo.name
        except AttributeError:
            pass

        msg = msg % {'repoid' : repoid, 'repo' : repoui}

        logger.critical('\n\n%s\n%s', msg, exception2msg(e))

        if unlock(): return 200
        return 1
Example #17
0
    def exPluginExit(self, e):
        '''Called when a plugin raises PluginYumExit.

        Log the plugin's exit message if one was supplied.
        ''' # ' xemacs hack
        exitmsg = exception2msg(e)
        if exitmsg:
            self.logger.warn('\n\n%s', exitmsg)
        if self.unlock(): return 200
        return 1
Example #18
0
    def exPluginExit(e):
        '''Called when a plugin raises PluginYumExit.

        Log the plugin's exit message if one was supplied.
        ''' # ' xemacs hack
        exitmsg = exception2msg(e)
        if exitmsg:
            logger.warn('\n\n%s', exitmsg)
        if unlock(): return 200
        return 1
Example #19
0
    def doUtilConfigSetup(self,args = sys.argv[1:],pluginsTypes=(plugins.TYPE_CORE,)):
        """Parse command line options, and perform configuration.

        :param args: list of arguments to use for configuration
        :param pluginsTypes: a sequence specifying the types of
           plugins to load
        :return: a dictionary containing the values of command line options
        """
        # Parse only command line options that affect basic yum setup
        opts = self._parser.firstParse(args)

        # go through all the setopts and set the global ones
        self._parseSetOpts(opts.setopts)

        if self.main_setopts:
            for opt in self.main_setopts.items:
                setattr(opts, opt, getattr(self.main_setopts, opt))

        # Just print out the version if that's what the user wanted
        if opts.version:
            self._printUtilVersion()
            sys.exit(0)
        # get the install root to use
        root = self._parser.getRoot(opts)
        if opts.quiet:
            opts.debuglevel = 0
        if opts.verbose:
            opts.debuglevel = opts.errorlevel = 6
        
        # Read up configuration options and initialise plugins
        try:
            pc = self.preconf
            pc.fn = opts.conffile
            pc.root = root
            pc.init_plugins = not opts.noplugins
            pc.plugin_types = pluginsTypes
            pc.optparser = self._parser
            pc.debuglevel = opts.debuglevel
            pc.errorlevel = opts.errorlevel
            if hasattr(opts, "disableplugins"):
                pc.disabled_plugins =self._parser._splitArg(opts.disableplugins)
            if hasattr(opts, "enableplugins"):
                pc.enabled_plugins = self._parser._splitArg(opts.enableplugins)
            if hasattr(opts, "releasever"):
                pc.releasever = opts.releasever
            self.conf

            # now set  all the non-first-start opts from main from our setopts
            if self.main_setopts:
                for opt in self.main_setopts.items:
                    setattr(self.conf, opt, getattr(self.main_setopts, opt))

        except Errors.ConfigError, e:
            self.logger.critical(_('Config Error: %s'), exception2msg(e))
            sys.exit(1)
Example #20
0
    def exPluginExit(e):
        """Called when a plugin raises PluginYumExit.

        Log the plugin's exit message if one was supplied.
        """  # ' xemacs hack
        exitmsg = exception2msg(e)
        if exitmsg:
            logger.warn("\n\n%s", exitmsg)
        if unlock():
            return 200
        return 1
Example #21
0
 def rpmdb_warn_checks():
     try:
         probs = base._rpmdb_warn_checks(out=verbose_logger.info,
                                         warn=False)
     except Errors.YumBaseError as e:
         # This is mainly for PackageSackError from rpmdb.
         verbose_logger.info(_(" Yum checks failed: %s"), exception2msg(e))
         probs = []
     if not probs:
         verbose_logger.info(
             _(" You could try running: rpm -Va --nofiles --nodigest"))
Example #22
0
    def __init__(self):
        YumUtilBase.__init__(self, YumDownloader.NAME, YumDownloader.VERSION, YumDownloader.USAGE)
        self.logger = logging.getLogger("yum.verbose.cli.yumdownloader")

        self.localPackages = []

        # Add util commandline options to the yum-cli ones
        self.optparser = self.getOptionParser()
        try:
            self.main()
        except (OSError, IOError), e:
            self.logger.error(exception2msg(e))
            sys.exit(1)
Example #23
0
    def exPluginExit(self, e):
        """Called when a plugin raises
           :class:`yum.plugins.PluginYumExit`.  Log the plugin's exit
           message if one was supplied.

        :param e: the exception
        :return: the exit code
        """ # ' xemacs hack
        exitmsg = exception2msg(e)
        if exitmsg:
            self.logger.warn('\n\n%s', exitmsg)
        if self.unlock(): return 200
        return 1
Example #24
0
    def exIOError(self, e):
        """Output a message stating that the program is exiting due to
        an IO exception.

        :param e: the IO exception
        :return: the exit code
        """
        if e.errno == 32:
            self.logger.critical(_('\n\nExiting on Broken Pipe'))
        else:
            self.logger.critical(_('\n\n%s') % exception2msg(e))
        if self.unlock(): return 200
        return 1
Example #25
0
    def exPluginExit(self, e):
        """Called when a plugin raises
           :class:`yum.plugins.PluginYumExit`.  Log the plugin's exit
           message if one was supplied.

        :param e: the exception
        :return: the exit code
        """ # ' xemacs hack
        exitmsg = exception2msg(e)
        if exitmsg:
            self.logger.warn('\n\n%s', exitmsg)
        if self.unlock(): return 200
        return 1
Example #26
0
    def exIOError(self, e):
        """Output a message stating that the program is exiting due to
        an IO exception.

        :param e: the IO exception
        :return: the exit code
        """
        if e.errno == 32:
            self.logger.critical(_('\n\nExiting on Broken Pipe'))
        else:
            self.logger.critical(_('\n\n%s') % exception2msg(e))
        if self.unlock(): return 200
        return 1
Example #27
0
 def doUtilYumSetup(self):
     """do a default setup for all the normal/necessary yum components,
        really just a shorthand for testing"""
     # FIXME - we need another way to do this, I think.
     try:
         self.waitForLock()
         self._getTs()
         self._getRpmDB()
         self._getRepos(doSetup = True)
         self._getSacks()
     except Errors.YumBaseError, msg:
         self.logger.critical(exception2msg(msg))
         sys.exit(1)
Example #28
0
    def doUtilBuildTransaction(self, unfinished_transactions_check=True):
        """Build the transaction.

        :param unfinished_transactions_check: whether to check if an
           unfinished transaction has been saved
        """
        try:
            (result, resultmsgs) = self.buildTransaction(
                unfinished_transactions_check=unfinished_transactions_check)
        except plugins.PluginYumExit as e:
            return self.exPluginExit(e)
        except Errors.YumBaseError as e:
            result = 1
            resultmsgs = [exception2msg(e)]
        except KeyboardInterrupt:
            return self.exUserCancel()
        except IOError as e:
            return self.exIOError(e)

        # Act on the depsolve result
        if result == 0:
            # Normal exit
            if self.unlock(): return 200
            return 0
        elif result == 1:
            # Fatal error
            for prefix, msg in self.pretty_output_restring(resultmsgs):
                self.logger.critical(prefix, msg)
            if not self.conf.skip_broken:
                self.verbose_logger.info(
                    _(" You could try using --skip-broken to work around the problem"
                      ))
            if not self._rpmdb_warn_checks(out=self.verbose_logger.info,
                                           warn=False):
                self.verbose_logger.info(
                    _(" You could try running: rpm -Va --nofiles --nodigest"))
            if self.unlock(): return 200
            return 1
        elif result == 2:
            # Continue on
            pass
        else:
            self.logger.critical(_('Unknown Error(s): Exit Code: %d:'), result)
            for msg in resultmsgs:
                self.logger.critical(msg)
            if self.unlock(): return 200
            return 3

        self.verbose_logger.log(logginglevels.INFO_2,
                                _('\nDependencies Resolved'))
Example #29
0
    def __init__(self):
        YumUtilBase.__init__(self, YumDownloader.NAME, YumDownloader.VERSION,
                             YumDownloader.USAGE)
        self.logger = logging.getLogger("yum.verbose.cli.yumdownloader")

        self.localPackages = []

        # Add util commandline options to the yum-cli ones
        self.optparser = self.getOptionParser()
        try:
            self.main()
        except (OSError, IOError), e:
            self.logger.error(exception2msg(e))
            sys.exit(1)
Example #30
0
 def waitForLock(self):
     """Establish the yum lock.  If another process is already
     holding the yum lock, by default this method will keep trying
     to establish the lock until it is successful.  However, if
     :attr:`self.conf.exit_on_lock` is set to True, it will
     raise a :class:`Errors.YumBaseError`.
     """
     lockerr = ""
     while True:
         try:
             self.doLock()
         except Errors.LockError, e:
             if exception2msg(e) != lockerr:
                 lockerr = exception2msg(e)
                 self.logger.critical(lockerr)
             if not self.conf.exit_on_lock:
                 self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...")  
                 show_lock_owner(e.pid, self.logger)
                 time.sleep(2)
             else:
                 raise Errors.YumBaseError, _("Another app is currently holding the yum lock; exiting as configured by exit_on_lock")
         else:
             break
Example #31
0
 def doUtilYumSetup(self):
     """Do a default setup for all the normal or necessary yum components;
        this method is mostly just used for testing.
     """
     # FIXME - we need another way to do this, I think.
     try:
         self.waitForLock()
         self._getTs()
         self._getRpmDB()
         self._getRepos(doSetup=True)
         self._getSacks()
     except Errors.YumBaseError, msg:
         self.logger.critical(exception2msg(msg))
         sys.exit(1)
Example #32
0
 def install_deps(self, deplist, opts):
     errors = set()
     for dep in deplist:
         self.logger.debug(' REQ:  %s' % dep)
         if dep.startswith("rpmlib("):
             continue
         instreq = self.returnInstalledPackagesByDep(dep)
         if instreq:
             self.logger.info(' --> Already installed : %s' % instreq[0])
             continue
         try:
             pkg = self.returnPackageByDep(dep)
             self.logger.info(' --> %s' % pkg)
             self.install(pkg)
         except yum.Errors.YumBaseError, e:
             errors.add(exception2msg(e))
Example #33
0
def show_lock_owner(pid, logger):
    """Output information about another process that is holding the
    yum lock.

    :param pid: the process id number of the process holding the yum
       lock
    :param logger: the logger to output the information to
    :return: a dictionary containing information about the process.
       This is the same as the dictionary returned by
       :func:`get_process_info`.
    """
    try:
        ps = get_process_info(pid)
    except IOError, e:
        logger.critical("%s", exception2msg(e))
        ps = None
Example #34
0
 def install_deps(self, deplist, opts):
     errors = set()
     for dep in deplist:
         self.logger.debug(' REQ:  %s' % dep)                
         if dep.startswith("rpmlib("): 
             continue
         instreq = self.returnInstalledPackagesByDep(dep)
         if instreq:
             self.logger.info(' --> Already installed : %s'  % instreq[0])                    
             continue
         try:
             pkg = self.returnPackageByDep(dep)
             self.logger.info(' --> %s' % pkg)
             self.install(pkg)
         except yum.Errors.YumBaseError, e:
             errors.add(exception2msg(e))
Example #35
0
def show_lock_owner(pid, logger):
    """Output information about another process that is holding the
    yum lock.

    :param pid: the process id number of the process holding the yum
       lock
    :param logger: the logger to output the information to
    :return: a dictionary containing information about the process.
       This is the same as the dictionary returned by
       :func:`get_process_info`.
    """
    try:
        ps = get_process_info(pid)
    except IOError, e:
        logger.critical("%s", exception2msg(e))
        ps = None
Example #36
0
 def doUtilYumSetup(self,opts):
     """do a default setup for all the normal/necessary yum components,
        really just a shorthand for testing"""
     try:
         # Setup source repos
         if opts.source:
             self.setupSourceRepos()
         self._getRepos(doSetup = True)
         # if '--source' is used the add src to the archlist
         if opts.source:
             archlist = rpmUtils.arch.getArchList() + ['src']    
         elif opts.archlist:
             archlist = []
             for a in opts.archlist.split(','):
                 archlist.extend(rpmUtils.arch.getArchList(a))
         else:
             archlist = rpmUtils.arch.getArchList()
         self._getSacks(archlist=archlist)
     except yum.Errors.YumBaseError, msg:
         self.logger.critical(exception2msg(msg))
         sys.exit(1)
Example #37
0
File: drpm.py Project: dmnks/yum
    def dequeue(self, block=True):
        """ Try to De-Queue a delta rebuild and spawn the rebuild process. """
        # Do this here, just to keep the zombies at bay...
        self._wait()

        if not self._future_jobs:
            return False

        if self.limit <= len(self.jobs):
            if not block:
                return False
            self.wait(len(self.jobs) - self.limit + 1)

        po = self._future_jobs.pop(0)
        args = ("-a", po.arch)
        if po.oldrpm:
            args += "-r", po.oldrpm
        args += po.localpath, po.rpm.localpath

        try:
            pid = os.spawnl(os.P_NOWAIT, APPLYDELTA, APPLYDELTA, *args)
        except OSError, e:
            raise MiscError, _("Couldn't spawn %s: %s") % (APPLYDELTA, exception2msg(e))
Example #38
0
def show_lock_owner(pid, logger):
    """Output information about another process that is holding the
    yum lock.

    :param pid: the process id number of the process holding the yum
       lock
    :param logger: the logger to output the information to
    :return: a dictionary containing information about the process.
       This is the same as the dictionary returned by
       :func:`get_process_info`.
    """
    try:
        ps = get_process_info(pid)
    except IOError as e:
        logger.critical("%s", exception2msg(e))
        ps = None
    if not ps:
        return None

    # This yumBackend isn't very friendly, so...
    if ps['name'] == 'yumBackend.py':
        nmsg = _("  The other application is: PackageKit")
    else:
        nmsg = _("  The other application is: %s") % ps['name']

    logger.critical("%s", nmsg)
    logger.critical(
        _("    Memory : %5s RSS (%5sB VSZ)") % (format_number(
            int(ps['vmrss']) * 1024), format_number(int(ps['vmsize']) * 1024)))

    ago = seconds_to_ui_time(int(time.time()) - ps['start_time'])
    logger.critical(
        _("    Started: %s - %s ago") % (time.ctime(ps['start_time']), ago))
    logger.critical(_("    State  : %s, pid: %d") % (ps['state'], pid))

    return ps
Example #39
0
    # also sanity check the things being passed on the cli
    try:
        base.getOptionsConfig(args)
    except plugins.PluginYumExit, e:
        return exPluginExit(e)
    except Errors.YumBaseError, e:
        return exFatal(e)
    except (OSError, IOError), e:
        return exIOError(e)

    lockerr = ""
    while True:
        try:
            base.doLock()
        except Errors.LockError, e:
            if exception2msg(e) != lockerr:
                lockerr = exception2msg(e)
                logger.critical(lockerr)
            if e.errno in (errno.EPERM, errno.EACCES, errno.ENOSPC):
                logger.critical(_("Can't create lock file; exiting"))
                return 1

            if not base.conf.exit_on_lock:
                logger.critical(_("Another app is currently holding the yum lock; waiting for it to exit..."))
                show_lock_owner(e.pid, logger)
                time.sleep(2)
            else:
                logger.critical(_("Another app is currently holding the yum lock; exiting as configured by exit_on_lock"))
                return 1
        else:
            break
Example #40
0
def main(args):
    """Run the yum program from a command line interface."""

    yum.misc.setup_locale(override_time=True)

    def exUserCancel():
        logger.critical(_('\n\nExiting on user cancel'))
        if unlock(): return 200
        return 1

    def exIOError(e):
        if e.errno == 32:
            logger.critical(_('\n\nExiting on Broken Pipe'))
        else:
            logger.critical(_('\n\n%s') % exception2msg(e))
        if unlock(): return 200
        return 1

    def exPluginExit(e):
        '''Called when a plugin raises PluginYumExit.

        Log the plugin's exit message if one was supplied.
        ''' # ' xemacs hack
        exitmsg = exception2msg(e)
        if exitmsg:
            logger.warn('\n\n%s', exitmsg)
        if unlock(): return 200
        return 1

    def exFatal(e):
        logger.critical('\n\n%s', exception2msg(e.value))
        if unlock(): return 200
        return 1

    def exRepoError(e):
        # For RepoErrors ... help out by forcing new repodata next time.
        # XXX: clean only the repo that has failed?
        try:
            base.cleanExpireCache()
        except Errors.YumBaseError:
            # Let's not confuse the user further (they don't even know we tried
            # the clean).
            pass

        msg = _("""\
 One of the configured repositories failed (%(repo)s),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=%(repoid)s ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable %(repoid)s
        or
            subscription-manager repos --disable=%(repoid)s

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=%(repoid)s.skip_if_unavailable=true
""")

        repoui = _('Unknown')
        repoid = _('<repoid>')
        try:
            repoid = e.repo.id
            repoui = e.repo.name
        except AttributeError:
            pass

        msg = msg % {'repoid': repoid, 'repo': repoui}

        logger.critical('\n\n%s\n%s', msg, exception2msg(e))

        if unlock(): return 200
        return 1

    def unlock():
        try:
            base.closeRpmDB()
            base.doUnlock()
        except Errors.LockError as e:
            return 200
        return 0

    def rpmdb_warn_checks():
        try:
            probs = base._rpmdb_warn_checks(out=verbose_logger.info,
                                            warn=False)
        except Errors.YumBaseError as e:
            # This is mainly for PackageSackError from rpmdb.
            verbose_logger.info(_(" Yum checks failed: %s"), exception2msg(e))
            probs = []
        if not probs:
            verbose_logger.info(
                _(" You could try running: rpm -Va --nofiles --nodigest"))

    logger = logging.getLogger("yum.main")
    verbose_logger = logging.getLogger("yum.verbose.main")

    # Try to open the current directory to see if we have
    # read and execute access. If not, chdir to /
    try:
        f = open(".")
    except IOError as e:
        if e.errno == errno.EACCES:
            logger.critical(
                _('No read/execute access in current directory, moving to /'))
            os.chdir("/")
    else:
        f.close()
    try:
        os.getcwd()
    except OSError as e:
        if e.errno == errno.ENOENT:
            logger.critical(
                _('No getcwd() access in current directory, moving to /'))
            os.chdir("/")

    # our core object for the cli
    base = cli.YumBaseCli()

    # do our cli parsing and config file setup
    # also sanity check the things being passed on the cli
    try:
        base.getOptionsConfig(args)
    except plugins.PluginYumExit as e:
        return exPluginExit(e)
    except Errors.YumBaseError as e:
        return exFatal(e)
    except (OSError, IOError) as e:
        return exIOError(e)

    try:
        base.waitForLock()
    except Errors.YumBaseError as e:
        return exFatal(e)

    try:
        result, resultmsgs = base.doCommands()
    except plugins.PluginYumExit as e:
        return exPluginExit(e)
    except Errors.RepoError as e:
        return exRepoError(e)
    except Errors.YumBaseError as e:
        result = 1
        resultmsgs = [exception2msg(e)]
    except KeyboardInterrupt:
        return exUserCancel()
    except IOError as e:
        return exIOError(e)

    # Act on the command/shell result
    if result == 0:
        # Normal exit
        for msg in resultmsgs:
            verbose_logger.log(logginglevels.INFO_2, '%s', msg)
        if unlock(): return 200
        return base.exit_code
    elif result == 1:
        # Fatal error
        for msg in resultmsgs:
            logger.critical(_('Error: %s'), msg)
        if unlock(): return 200
        return 1
    elif result == 2:
        # Continue on
        pass
    elif result == 100:
        if unlock(): return 200
        return 100
    else:
        logger.critical(_('Unknown Error(s): Exit Code: %d:'), result)
        for msg in resultmsgs:
            logger.critical(msg)
        if unlock(): return 200
        return 3

    # Mainly for ostree, but might be useful for others.
    if base.conf.usr_w_check:
        usrinstpath = base.conf.installroot + "/usr"
        usrinstpath = usrinstpath.replace('//', '/')
        if (os.path.exists(usrinstpath)
                and not os.access(usrinstpath, os.W_OK)):
            logger.critical(_('No write access to %s directory') % usrinstpath)
            logger.critical(_('  Maybe this is an ostree image?'))
            logger.critical(
                _('  To disable you can use --setopt=usr_w_check=false'))
            if unlock(): return 200
            return 1

    # Depsolve stage
    verbose_logger.log(logginglevels.INFO_2, _('Resolving Dependencies'))

    try:
        (result, resultmsgs) = base.buildTransaction()
    except plugins.PluginYumExit as e:
        return exPluginExit(e)
    except Errors.RepoError as e:
        return exRepoError(e)
    except Errors.YumBaseError as e:
        result = 1
        resultmsgs = [exception2msg(e)]
    except KeyboardInterrupt:
        return exUserCancel()
    except IOError as e:
        return exIOError(e)

    # Act on the depsolve result
    if result == 0:
        # Normal exit
        if unlock(): return 200
        return base.exit_code
    elif result == 1:
        # Fatal error
        for prefix, msg in base.pretty_output_restring(resultmsgs):
            logger.critical(prefix, msg)
        if base._depsolving_failed:
            if not base.conf.skip_broken:
                verbose_logger.info(
                    _(" You could try using --skip-broken to work around the problem"
                      ))
            rpmdb_warn_checks()
        if unlock(): return 200
        return 1
    elif result == 2:
        # Continue on
        pass
    else:
        logger.critical(_('Unknown Error(s): Exit Code: %d:'), result)
        for msg in resultmsgs:
            logger.critical(msg)
        if unlock(): return 200
        return 3

    verbose_logger.log(logginglevels.INFO_2, _('\nDependencies Resolved'))

    # Run the transaction
    try:
        inhibit = {
            'what': 'shutdown:idle',
            'who': 'yum cli',
            'why': 'Running transaction',  # i18n?
            'mode': 'block'
        }
        return_code = base.doTransaction(inhibit=inhibit)
    except plugins.PluginYumExit as e:
        return exPluginExit(e)
    except Errors.RepoError as e:
        return exRepoError(e)
    except Errors.YumBaseError as e:
        return exFatal(e)
    except KeyboardInterrupt:
        return exUserCancel()
    except IOError as e:
        return exIOError(e)

    # rpm ts.check() failed.
    if type(return_code) == type((0, )) and len(return_code) == 2:
        (result, resultmsgs) = return_code
        for msg in resultmsgs:
            logger.critical("%s", msg)
        rpmdb_warn_checks()
        return_code = result
        if base._ts_save_file:
            verbose_logger.info(
                _("Your transaction was saved, rerun it with:\n yum load-transaction %s"
                  ) % base._ts_save_file)
    elif return_code < 0:
        return_code = 1  # Means the pre-transaction checks failed...
        #  This includes:
        # . No packages.
        # . Hitting N at the prompt.
        # . GPG check failures.
        if base._ts_save_file:
            verbose_logger.info(
                _("Your transaction was saved, rerun it with:\n yum load-transaction %s"
                  ) % base._ts_save_file)
    else:
        verbose_logger.log(logginglevels.INFO_2, _('Complete!'))

    if unlock(): return 200
    return return_code or base.exit_code
Example #41
0
 def failfunc(e, name=name, repo=repo):
     mdpath.pop(repo, None)
     if hasattr(e, 'exception'): e = e.exception
     self.verbose_logger.warn(
         _('Failed to download %s for repository %s: %s'), name,
         repo, exception2msg(e))
Example #42
0
        return exIOError(e)

    try:
        base.waitForLock()
    except Errors.YumBaseError, e:
        return exFatal(e)

    try:
        result, resultmsgs = base.doCommands()
    except plugins.PluginYumExit, e:
        return exPluginExit(e)
    except Errors.RepoError, e:
        return exRepoError(e)
    except Errors.YumBaseError, e:
        result = 1
        resultmsgs = [exception2msg(e)]
    except KeyboardInterrupt:
        return exUserCancel()
    except IOError, e:
        return exIOError(e)

    # Act on the command/shell result
    if result == 0:
        # Normal exit
        for msg in resultmsgs:
            verbose_logger.log(logginglevels.INFO_2, '%s', msg)
        if unlock(): return 200
        return base.exit_code
    elif result == 1:
        # Fatal error
        for msg in resultmsgs:
Example #43
0
File: drpm.py Project: dmnks/yum
 def failfunc(e, name=name, repo=repo):
     mdpath.pop(repo, None)
     if hasattr(e, "exception"):
         e = e.exception
     self.verbose_logger.warn(_("Failed to download %s for repository %s: %s"), name, repo, exception2msg(e))
Example #44
0
            if hasattr(opts, "enableplugins"):
                pc.enabled_plugins = self._parser._splitArg(opts.enableplugins)
            if hasattr(opts, "releasever"):
                pc.releasever = opts.releasever
            self.conf

            # now set  all the non-first-start opts from main from our setopts
            if self.main_setopts:
                for opt in self.main_setopts.items:
                    setattr(self.conf, opt, getattr(self.main_setopts, opt))

        except Errors.ConfigError, e:
            self.logger.critical(_('Config Error: %s'), exception2msg(e))
            sys.exit(1)
        except ValueError, e:
            self.logger.critical(_('Options Error: %s'), exception2msg(e))
            sys.exit(1)
        except plugins.PluginYumExit, e:
            self.logger.critical(_('PluginExit Error: %s'), exception2msg(e))
            sys.exit(1)
        except Errors.YumBaseError, e:
            self.logger.critical(_('Yum Error: %s'), exception2msg(e))
            sys.exit(1)
            
        # update usage in case plugins have added commands
        self._parser.set_usage(self._usage)
        
        # Now parse the command line for real and 
        # apply some of the options to self.conf
        (opts, self.cmds) = self._parser.setupYumConfig()
        if self.cmds:
Example #45
0
            if hasattr(opts, "enableplugins"):
                pc.enabled_plugins = self._parser._splitArg(opts.enableplugins)
            if hasattr(opts, "releasever"):
                pc.releasever = opts.releasever
            self.conf

            # now set  all the non-first-start opts from main from our setopts
            if self.main_setopts:
                for opt in self.main_setopts.items:
                    setattr(self.conf, opt, getattr(self.main_setopts, opt))

        except Errors.ConfigError, e:
            self.logger.critical(_('Config Error: %s'), exception2msg(e))
            sys.exit(1)
        except ValueError, e:
            self.logger.critical(_('Options Error: %s'), exception2msg(e))
            sys.exit(1)
        except plugins.PluginYumExit, e:
            self.logger.critical(_('PluginExit Error: %s'), exception2msg(e))
            sys.exit(1)
        except Errors.YumBaseError, e:
            self.logger.critical(_('Yum Error: %s'), exception2msg(e))
            sys.exit(1)

        # update usage in case plugins have added commands
        self._parser.set_usage(self._usage)

        # Now parse the command line for real and
        # apply some of the options to self.conf
        (opts, self.cmds) = self._parser.setupYumConfig()
        if self.cmds:
Example #46
0
 def exFatal(e):
     logger.critical('\n\n%s', exception2msg(e.value))
     if unlock(): return 200
     return 1
Example #47
0
 def exFatal(self, e):
     self.logger.critical('\n\n%s', exception2msg(e))
     if self.unlock(): return 200
     return 1
Example #48
0
 def exFatal(e):
     logger.critical('\n\n%s', exception2msg(e.value))
     if unlock(): return 200
     return 1
Example #49
0
        return exIOError(e)

    try:
        base.waitForLock()
    except Errors.YumBaseError, e:
        return exFatal(e)

    try:
        result, resultmsgs = base.doCommands()
    except plugins.PluginYumExit, e:
        return exPluginExit(e)
    except Errors.RepoError, e:
        return exRepoError(e)
    except Errors.YumBaseError, e:
        result = 1
        resultmsgs = [exception2msg(e)]
    except KeyboardInterrupt:
        return exUserCancel()
    except IOError, e:
        return exIOError(e)

    # Act on the command/shell result
    if result == 0:
        # Normal exit 
        for msg in resultmsgs:
            verbose_logger.log(logginglevels.INFO_2, '%s', msg)
        if unlock(): return 200
        return base.exit_code
    elif result == 1:
        # Fatal error
        for msg in resultmsgs:
Example #50
0
            if hasattr(opts, "enableplugins"):
                pc.enabled_plugins = self._parser._splitArg(opts.enableplugins)
            if hasattr(opts, "releasever"):
                pc.releasever = opts.releasever
            self.conf

            # now set  all the non-first-start opts from main from our setopts
            if self.main_setopts:
                for opt in self.main_setopts.items:
                    setattr(self.conf, opt, getattr(self.main_setopts, opt))

        except Errors.ConfigError, e:
            self.logger.critical(_("Config Error: %s"), exception2msg(e))
            sys.exit(1)
        except ValueError, e:
            self.logger.critical(_("Options Error: %s"), exception2msg(e))
            sys.exit(1)
        except plugins.PluginYumExit, e:
            self.logger.critical(_("PluginExit Error: %s"), exception2msg(e))
            sys.exit(1)
        except Errors.YumBaseError, e:
            self.logger.critical(_("Yum Error: %s"), exception2msg(e))
            sys.exit(1)

        # update usage in case plugins have added commands
        self._parser.set_usage(self._usage)

        # Now parse the command line for real and
        # apply some of the options to self.conf
        (opts, self.cmds) = self._parser.setupYumConfig()
        if self.cmds: