Exemple #1
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
Exemple #2
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
Exemple #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
Exemple #4
0
Fichier : main.py Projet : zde/dnf
 def exIOError(e):
     dnf.util.log_last_excpetion(logger)
     if e.errno == 32:
         logger.critical(_('Exiting on Broken Pipe'))
     else:
         logger.critical(exception2msg(e))
     return 1
Exemple #5
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 = []
Exemple #6
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 = []
Exemple #7
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)
Exemple #8
0
    def exPluginExit(e):
        '''Called when a plugin raises PluginYumExit.

        Log the plugin's exit message if one was supplied.
        '''
        exitmsg = exception2msg(e)
        if exitmsg:
            logger.warn('%s', exitmsg)
        return 1
Exemple #9
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
Exemple #10
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
Exemple #11
0
    def exPluginExit(e):
        '''Called when a plugin raises PluginYumExit.

        Log the plugin's exit message if one was supplied.
        '''
        exitmsg = exception2msg(e)
        if exitmsg:
            logger.warn('\n\n%s', exitmsg)
        if unlock(): return 200
        return 1
Exemple #12
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)
Exemple #13
0
    def exPluginExit(self, e):
        """Called when a plugin raises
           :class:`dnf.yum.plugins.PluginYumExit`.  Log the plugin's exit
           message if one was supplied.

        :param e: the exception
        :return: the exit code
        """
        exitmsg = exception2msg(e)
        if exitmsg:
            self.logger.warn('\n\n%s', exitmsg)
        if self.unlock(): return 200
        return 1
Exemple #14
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
Exemple #15
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
Exemple #16
0
    def exPluginExit(self, e):
        """Called when a plugin raises
           :class:`dnf.yum.plugins.PluginYumExit`.  Log the plugin's exit
           message if one was supplied.

        :param e: the exception
        :return: the exit code
        """
        exitmsg = exception2msg(e)
        if exitmsg:
            self.logger.warn('\n\n%s', exitmsg)
        if self.unlock(): return 200
        return 1
Exemple #17
0
 def doUtilYumSetup(self):
     """Do a default setup for all the normal or necessary yum components;
        this method is mostly just a 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)
Exemple #18
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
Exemple #19
0
 def doUtilYumSetup(self):
     """Do a default setup for all the normal or necessary yum components;
        this method is mostly just a 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)
Exemple #20
0
 def exFatal(e):
     logger.critical('\n\n%s', exception2msg(e.value))
     if unlock(): return 200
     return 1
Exemple #21
0
    # read and execute access. If not, chdir to /
    try:
        f = open(".")
    except IOError, e:
        if e.errno == errno.EACCES:
            logger.critical(_('No read/execute access in current directory, moving to /'))
            os.chdir("/")
    else:
        f.close()

    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..."))
                tm = 0.1
                if show_lock_owner(e.pid, logger):
                    tm = 2
                time.sleep(tm)
            else:
                logger.critical(_("Another app is currently holding the yum lock; exiting as configured by exit_on_lock"))
                return 1
Exemple #22
0
def ex_IOError(e):
    logger.log(dnf.logging.SUBDEBUG, '', exc_info=True)
    logger.critical(exception2msg(e))
    return 1
Exemple #23
0
    except IOError, e:
        if e.errno == errno.EACCES:
            logger.critical(_('No read/execute access in current directory, moving to /'))
            os.chdir("/")
    else:
        f.close()

    try:
        result, resultmsgs = cli.run()
    except plugins.PluginYumExit, e:
        return exPluginExit(e)
    except dnf.exceptions.LockError:
        raise
    except dnf.exceptions.Error, e:
        result = 1
        resultmsgs = [exception2msg(e)]
    except IOError, e:
        return exIOError(e)

    # Act on the command/shell result
    if result == 0:
        # Normal exit
        for msg in resultmsgs:
            logger.info('%s', msg)
        return 0
    elif result == 1:
        # Fatal error
        for msg in resultmsgs:
            logger.critical(_('Error: %s'), msg)
        return 1
    elif result == 2:
Exemple #24
0
 def exIOError(e):
     if e.errno == 32:
         logger.critical(_('Exiting on Broken Pipe'))
     else:
         logger.critical(exception2msg(e))
     return 1
Exemple #25
0
def _main(base, args):
    """Run the yum program from a command line interface."""

    dnf.i18n.setup_locale()
    dnf.i18n.setup_stdout()

    def exIOError(e):
        if e.errno == 32:
            logger.critical(_('Exiting on Broken Pipe'))
        else:
            logger.critical(exception2msg(e))
        return 1

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

        Log the plugin's exit message if one was supplied.
        '''
        exitmsg = exception2msg(e)
        if exitmsg:
            logger.warn('%s', exitmsg)
        return 1

    def exFatal(e):
        if e.value is not None:
            logger.critical(exception2msg(e.value))
        return 1

    # our core object for the cli
    base.logging.presetup()
    cli = dnf.cli.cli.Cli(base)

    # do our cli parsing and config file setup
    # also sanity check the things being passed on the cli
    try:
        cli.configure(args)
        cli.check()
    except plugins.PluginYumExit as e:
        return exPluginExit(e)
    except dnf.exceptions.LockError:
        raise
    except dnf.exceptions.Error as e:
        return exFatal(e)

    # 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:
        result, resultmsgs = cli.run()
    except plugins.PluginYumExit as e:
        return exPluginExit(e)
    except dnf.exceptions.LockError:
        raise
    except dnf.exceptions.Error as e:
        result = 1
        resultmsgs = [exception2msg(e)]
    except IOError as e:
        return exIOError(e)

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

    # Depsolve stage (if needed)
    if base.transaction is None:
        logger.info(_('Resolving dependencies'))

        try:
            got_transaction = base.resolve()
        except plugins.PluginYumExit as e:
            return exPluginExit(e)
        except dnf.exceptions.Error as e:
            prefix = _('Error: %s')
            logger.critical(prefix, str(e))
            return 1

        logger.info(_('Dependencies resolved.'))
    else:
        got_transaction = len(base.transaction)

    # Act on the depsolve result
    if not got_transaction:
        print(_('Nothing to do.'))
        return 0

    # Run the transaction
    try:
        return_code, resultmsgs = base.do_transaction()
    except plugins.PluginYumExit as e:
        return exPluginExit(e)
    except dnf.exceptions.LockError:
        raise
    except dnf.exceptions.TransactionCheckError as err:
        return_code, resultmsgs = 1, cli.command.get_error_output(err)
    except dnf.exceptions.Error as e:
        return exFatal(e)
    except IOError as e:
        return exIOError(e)

    # rpm ts.check() failed.
    if resultmsgs:
        for msg in resultmsgs:
            logger.critical("%s", msg)
        if base._ts_save_file:
            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:
            logger.info(_("Your transaction was saved, rerun it with:\n yum load-transaction %s") % base._ts_save_file)
    else:
        logger.info(_('Complete!'))

    return return_code
Exemple #26
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:
Exemple #27
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:
Exemple #28
0
 def exFatal(e):
     logger.critical('\n\n%s', exception2msg(e.value))
     if unlock(): return 200
     return 1
Exemple #29
0
Fichier : main.py Projet : zde/dnf
 def exFatal(e):
     if e.value is not None:
         logger.critical(_('Error: %s'), exception2msg(e.value))
     return 1
Exemple #30
0
    try:
        f = open(".")
    except IOError, e:
        if e.errno == errno.EACCES:
            logger.critical(
                _('No read/execute access in current directory, moving to /'))
            os.chdir("/")
    else:
        f.close()

    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..."
                      ))
                tm = 0.1
                if show_lock_owner(e.pid, logger):
                    tm = 2
                time.sleep(tm)
            else: