コード例 #1
0
ファイル: utils.py プロジェクト: lmacken/dnf
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`.
    """
    ps = get_process_info(pid)
    if not ps:
        return None

    # This yumBackend isn't very friendly, so...
    msg = _('  The application with PID %d is: %s')
    if ps['name'] == 'yumBackend.py':
        nmsg = msg % (pid, 'PackageKit')
    else:
        nmsg = msg % (pid, 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") % ps['state'])

    return ps
コード例 #2
0
ファイル: drpm.py プロジェクト: zde/dnf
 def job_done(self, pid, code):
     # handle a finished delta rebuild
     po = self.jobs.pop(pid)
     if code != 0:
         unlink_f(po.rpm.localPkg())
         self.err[po] = _('Delta RPM rebuild failed')
     elif not po.rpm.verifyLocalPkg():
         self.err[po] = _('Checksum of the delta-rebuilt RPM failed')
     else:
         os.unlink(po.localPkg())
         if self.progress:
             name = os.path.basename(po.rpm.localPkg())
             self.progress.end(name, None, 'done', 'DRPM')
コード例 #3
0
ファイル: drpm.py プロジェクト: auchytil/dnf
    def job_done(self, pid, code):
        # handle a finished delta rebuild
        logger.debug('drpm: %d: return code: %d, %d', pid, code >> 8, code & 0xff)

        pload = self.jobs.pop(pid)
        pkg = pload.pkg
        if code != 0:
            unlink_f(pload.pkg.localPkg())
            self.err[pkg] = [_('Delta RPM rebuild failed')]
        elif not pload.pkg.verifyLocalPkg():
            self.err[pkg] = [_('Checksum of the delta-rebuilt RPM failed')]
        else:
            os.unlink(pload.localPkg())
            self.progress.end(pload, dnf.callback.STATUS_DRPM, 'done')
コード例 #4
0
ファイル: main.py プロジェクト: 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
コード例 #5
0
ファイル: transaction.py プロジェクト: lmacken/dnf
 def rpm_limitations(self):
     """ Ensures all the members can be passed to rpm as they are to pefrom
         the transaction.
     """
     src_installs = [pkg for pkg in self.install_set if pkg.arch == 'src']
     if len(src_installs):
         return _("DNF will not install a source rpm package (%s).") % \
             src_installs[0]
     return None
コード例 #6
0
ファイル: persistor.py プロジェクト: zde/dnf
 def _get_expired_from_json(self):
     json_path = os.path.join(self.cachedir, "expired_repos.json")
     f = open(json_path, 'r')
     content = f.read()
     f.close()
     if content == "":
         data = []
         self.logger.warning(_("expired_repos.json is empty file"))
         self._write_json_data(json_path, data)
     else:
         data = json.loads(content)
     return set(data)
コード例 #7
0
ファイル: conf.py プロジェクト: auchytil/dnf
    def _make_ready(self):
        if self._ready:
            return

        self._ready = True
        self._system_cachedir = self._retdir(self.prefix)
        if util.am_i_root():
            self._cachedir = self._system_cachedir
        else:
            try:
                user_prefix = misc.getCacheDir()
                self._cachedir = self._retdir(user_prefix)
            except (IOError, OSError) as e:
                self.logger.critical(_('Could not set cachedir: %s'), ucd(e))
コード例 #8
0
ファイル: repo.py プロジェクト: auchytil/dnf
    def _target_params(self):
        pkg = self.pkg
        ctype, csum = pkg.returnIdSum()
        ctype_code = getattr(librepo, ctype.upper(), librepo.CHECKSUM_UNKNOWN)
        if ctype_code == librepo.CHECKSUM_UNKNOWN:
            logger.warn(_("unsupported checksum type: %s") % ctype)

        return {
            'relative_url' : pkg.location,
            'checksum_type' : ctype_code,
            'checksum' : csum,
            'expectedsize' : pkg.downloadsize,
            'base_url' : pkg.baseurl,
        }
コード例 #9
0
ファイル: utils.py プロジェクト: lmacken/dnf
def get_process_info(pid):
    """Return information about a process taken from
    /proc/*pid*/status, /proc/stat/, and /proc/*pid*/stat.

    :param pid: the process id number
    :return: a dictionary containing information about the process
    """
    if not pid:
        return

    try:
        pid = int(pid)
    except ValueError as e:
        return

    # Maybe true if /proc isn't mounted, or not Linux ... or something.
    if (not os.path.exists("/proc/%d/status" % pid) or
        not os.path.exists("/proc/stat") or
        not os.path.exists("/proc/%d/stat" % pid)):
        return

    ps = {}
    for line in open("/proc/%d/status" % pid):
        if line[-1] != '\n':
            continue
        data = line[:-1].split(':\t', 1)
        if len(data) < 2:
            continue
        if data[1].endswith(' kB'):
            data[1] = data[1][:-3]
        ps[data[0].strip().lower()] = data[1].strip()
    if 'vmrss' not in ps:
        return
    if 'vmsize' not in ps:
        return
    boot_time = None
    for line in open("/proc/stat"):
        if line.startswith("btime "):
            boot_time = int(line[len("btime "):-1])
            break
    if boot_time is None:
        return
    ps_stat = open("/proc/%d/stat" % pid).read().split()
    ps['utime'] = jiffies_to_seconds(ps_stat[13])
    ps['stime'] = jiffies_to_seconds(ps_stat[14])
    ps['cutime'] = jiffies_to_seconds(ps_stat[15])
    ps['cstime'] = jiffies_to_seconds(ps_stat[16])
    ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21])
    ps['state'] = {'R' : _('Running'),
                   'S' : _('Sleeping'),
                   'D' : _('Uninterruptible'),
                   'Z' : _('Zombie'),
                   'T' : _('Traced/Stopped')
                   }.get(ps_stat[2], _('Unknown'))

    return ps
コード例 #10
0
ファイル: main.py プロジェクト: zde/dnf
def main(args):
    with dnf.cli.cli.BaseCli() as base:
        try:
            return _main(base, args)
        except dnf.exceptions.ProcessLockError as e:
            logger.critical(e.value)
            show_lock_owner(e.pid, logger)
            return 1
        except dnf.exceptions.LockError as e:
            logger.critical(e.value)
            return 1
        except KeyboardInterrupt as e:
            print(_("Terminated."), file=sys.stderr)
            return 1
    return 0
コード例 #11
0
ファイル: drpm.py プロジェクト: auchytil/dnf
    def _target_params(self):
        delta = self.delta
        ctype, csum = delta.chksum
        ctype = hawkey.chksum_name(ctype)
        chksum = hexlify(csum).decode()

        ctype_code = getattr(librepo, ctype.upper(), librepo.CHECKSUM_UNKNOWN)
        if ctype_code == librepo.CHECKSUM_UNKNOWN:
            logger.warn(_("unsupported checksum type: %s") % ctype)

        return {
            'relative_url' : delta.location,
            'checksum_type' : ctype_code,
            'checksum' : chksum,
            'expectedsize' : delta.downloadsize,
            'base_url' : delta.baseurl,
        }
コード例 #12
0
 def babysitting_remove(self, pkgs):
     if "kernel" == pkgs:
         if not self._seriously(_("Do you really want to remove all your "
                                  "kernels (including the running one)?")):
             pkgs=""
     return self.original_remove(pkgs)
コード例 #13
0
ファイル: main.py プロジェクト: zde/dnf
 def exFatal(e):
     if e.value is not None:
         logger.critical(_('Error: %s'), exception2msg(e.value))
     return 1
コード例 #14
0
ファイル: repo.py プロジェクト: auchytil/dnf
 def _exc2msg(self, librepo_exception):
     exc_msg = librepo_exception.args[1]
     msg = _("Failed to synchronize cache for repo '%s': %s") % \
           (self.id, exc_msg)
     return msg
コード例 #15
0
ファイル: main.py プロジェクト: zde/dnf
def _main(base, args):
    """Run the yum program from a command line interface."""

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

    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

    def exFatal(e):
        if e.value is not None:
            logger.critical(_('Error: %s'), 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 dnf.exceptions.LockError:
        raise
    except dnf.exceptions.Error as e:
        return exFatal(e)
    except (IOError, OSError) as e:
        return exIOError(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:
        cli.run()
    except dnf.exceptions.LockError:
        raise
    except dnf.exceptions.Error as e:
        return exFatal(e)
    except (IOError, OSError) as e:
        return exIOError(e)

    if not cli.command.resolve:
        return cli.command.success_retval

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

        try:
            got_transaction = base.resolve()
        except dnf.exceptions.Error as e:
            logger.critical(_('Error: %s'), 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 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:
        base.plugins.run_transaction()
        logger.info(_('Complete!'))

    return return_code
コード例 #16
0
ファイル: main.py プロジェクト: ryanuber/dnf
        cli.configure(args)
        cli.check()
    except plugins.PluginYumExit, e:
        return exPluginExit(e)
    except dnf.exceptions.LockError:
        raise
    except dnf.exceptions.Error, 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, 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)
コード例 #17
0
ファイル: main.py プロジェクト: xyxel/dnf
 def exIOError(e):
     if e.errno == 32:
         logger.critical(_('Exiting on Broken Pipe'))
     else:
         logger.critical(exception2msg(e))
     return 1
コード例 #18
0
ファイル: main.py プロジェクト: xyxel/dnf
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
コード例 #19
0
 def __init__(self, base=None, *args):
     self.logger = logging.getLogger("dnf")
     self.base = base
     self.logger.info(_("The Babysitter plugin is active"))
コード例 #20
0
ファイル: utils.py プロジェクト: PaulReiber/dnf
    if 'vmsize' not in ps:
        return
    boot_time = None
    for line in open("/proc/stat"):
        if line.startswith("btime "):
            boot_time = int(line[len("btime "):-1])
            break
    if boot_time is None:
        return
    ps_stat = open("/proc/%d/stat" % pid).read().split()
    ps['utime'] = jiffies_to_seconds(ps_stat[13])
    ps['stime'] = jiffies_to_seconds(ps_stat[14])
    ps['cutime'] = jiffies_to_seconds(ps_stat[15])
    ps['cstime'] = jiffies_to_seconds(ps_stat[16])
    ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21])
    ps['state'] = {'R' : _('Running'),
                   'S' : _('Sleeping'),
                   'D' : _('Uninterruptible'),
                   'Z' : _('Zombie'),
                   'T' : _('Traced/Stopped')
                   }.get(ps_stat[2], _('Unknown'))

    return ps

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