[yum-commits] 6 commits - cli.py yum/config.py yummain.py yum/rpmsack.py yum/update_md.py

James Antill james at osuosl.org
Mon Jun 16 18:54:52 UTC 2014


 cli.py           |   34 ++++++++++++++++++++++++++++++++--
 yum/config.py    |   40 ++++++++++++++++++++++++----------------
 yum/rpmsack.py   |   21 +++++++++++++++++++--
 yum/update_md.py |   10 +++++-----
 yummain.py       |    6 +++++-
 5 files changed, 85 insertions(+), 26 deletions(-)

New commits:
commit 22271bf34e71bbfc75d0a59354fc0108e004f36c
Author: James Antill <james at and.org>
Date:   Mon Jun 9 16:09:32 2014 -0400

    Read FS yumvars before yum.conf setup, and reread if installroot changed.

diff --git a/yum/config.py b/yum/config.py
index 6e0ecdc..1b5a11d 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -1022,6 +1022,23 @@ class VersionGroupConf(BaseConfig):
     pkglist = ListOption()
     run_with_packages = BoolOption(False)
 
+def _read_yumvars(yumvars, root):
+    # Read the FS yumvars
+    try:
+        dir_fsvars = root + "/etc/yum/vars/"
+        fsvars = os.listdir(dir_fsvars)
+    except OSError:
+        fsvars = []
+    for fsvar in fsvars:
+        if os.path.islink(dir_fsvars + fsvar):
+            continue
+        try:
+            val = open(dir_fsvars + fsvar).readline()
+            if val and val[-1] == '\n':
+                val = val[:-1]
+        except (OSError, IOError):
+            continue
+        yumvars[fsvar] = val
 
 def readStartupConfig(configfile, root, releasever=None):
     """Parse Yum's main configuration file and return a
@@ -1044,6 +1061,7 @@ def readStartupConfig(configfile, root, releasever=None):
     confpp_obj = ConfigPreProcessor(configfile)
 
     yumvars = _getEnvVar()
+    _read_yumvars(yumvars, yumconf.installroot)
     confpp_obj._vars = yumvars
     startupconf.yumvars = yumvars
 
@@ -1102,22 +1120,12 @@ def readMainConfig(startupconf):
         ir_path = varReplace(ir_path, yumvars)
         setattr(yumconf, option, ir_path)
     
-    # Read the FS yumvars
-    try:
-        dir_fsvars = yumconf.installroot + "/etc/yum/vars/"
-        fsvars = os.listdir(dir_fsvars)
-    except OSError:
-        fsvars = []
-    for fsvar in fsvars:
-        if os.path.islink(dir_fsvars + fsvar):
-            continue
-        try:
-            val = open(dir_fsvars + fsvar).readline()
-            if val and val[-1] == '\n':
-                val = val[:-1]
-        except (OSError, IOError):
-            continue
-        yumvars[fsvar] = val
+    if StartupConf.installroot.default != yumconf.installroot:
+        #  Note that this isn't perfect, in that if the initial installroot has
+        # X=Y, and X doesn't exist in the new installroot ... then we'll still
+        # have X afterwards (but if the new installroot has X=Z, that will be
+        # the value after this).
+        _read_yumvars(yumvars, yumconf.installroot)
 
     # These can use the above FS yumvars
     for option in ('cachedir', 'logfile', 'persistdir'):
commit 2ee11dc5e09ff061935531bf4a72e8a2b64f8967
Author: James Antill <james at and.org>
Date:   Mon Jun 16 14:49:10 2014 -0400

    Add cli specific info. for inhibit. BZ 1109930.

diff --git a/yummain.py b/yummain.py
index 24bbe6c..55c35b9 100755
--- a/yummain.py
+++ b/yummain.py
@@ -270,7 +270,11 @@ def main(args):
 
     # Run the transaction
     try:
-        return_code = base.doTransaction()
+        inhibit = {'what' : 'shutdown:idle',
+                   'who'  : 'yum cli',
+                   'why'  : 'Running transaction', # i18n?
+                   'mode' : 'block'}
+        return_code = base.doTransaction(inhibit=inhibit)
     except plugins.PluginYumExit, e:
         return exPluginExit(e)
     except Errors.RepoError, e:
commit b122391ed76ec4bfd44507a4747f1f581bd405be
Author: James Antill <james at and.org>
Date:   Mon Jun 16 14:45:20 2014 -0400

    Call systemd Inhibit, to inhibit shutdowns during transactions. BZ 1109930.

diff --git a/cli.py b/cli.py
index aa73278..b7f5b5a 100755
--- a/cli.py
+++ b/cli.py
@@ -69,6 +69,18 @@ class CliError(yum.Errors.YumBaseError):
         yum.Errors.YumBaseError.__init__(self)
         self.args = args
 
+def sys_inhibit(what, who, why, mode):
+    """ Tell systemd to inhibit shutdown, via. dbus. """
+    try:
+        import dbus
+        bus = dbus.SystemBus()
+        proxy = bus.get_object('org.freedesktop.login1',
+                               '/org/freedesktop/login1')
+        iface = dbus.Interface(proxy, 'org.freedesktop.login1.Manager')
+        return iface.Inhibit(what, who, why, mode)
+    except:
+        return None
+
 class YumBaseCli(yum.YumBase, output.YumOutput):
     """This is the base class for yum cli."""
        
@@ -571,7 +583,10 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
 
         return self.yum_cli_commands[self.basecmd].doCommand(self, self.basecmd, self.extcmds)
 
-    def doTransaction(self):
+    def doTransaction(self, inhibit={'what' : 'shutdown:idle',
+                                     'who'  : 'yum API',
+                                     'why'  : 'Running transaction', # i18n?
+                                     'mode' : 'block'}):
         """Take care of package downloading, checking, user
         confirmation and actually running the transaction.
 
@@ -768,9 +783,24 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         if self.conf.debuglevel < 2:
             cb.display.output = False
 
-        self.verbose_logger.log(yum.logginglevels.INFO_2, _('Running transaction'))
+        inhibited = False
+        if inhibit:
+            fd = sys_inhibit(inhibit['what'], inhibit['who'],
+                             inhibit['why'], inhibit['mode'])
+            if fd is not None:
+                msg = _('Running transaction (shutdown inhibited)')
+                inhibited = True
+        if not inhibited:
+            msg = _('Running transaction')
+
+        self.verbose_logger.log(yum.logginglevels.INFO_2, msg)
         resultobject = self.runTransaction(cb=cb)
 
+        #  fd is either None or dbus.UnifFD() and the real API to close is thus:
+        # if fd is not None: os.close(fd.take())
+        # ...but this is easier, doesn't require a test and works.
+        del fd
+
         self.verbose_logger.debug('Transaction time: %0.3f' % (time.time() - ts_st))
         # close things
         self.verbose_logger.log(yum.logginglevels.INFO_1,
commit 6e7e0ade4ea0d4c86e61d5daa89b6761b58b92b0
Author: James Antill <james at and.org>
Date:   Mon Jun 9 16:15:35 2014 -0400

    Fixup rid unknown subst. for previous i18n patch.

diff --git a/yum/update_md.py b/yum/update_md.py
index 0fc2088..7dcfce5 100644
--- a/yum/update_md.py
+++ b/yum/update_md.py
@@ -527,9 +527,9 @@ class UpdateMetadata(object):
     def add(self, obj, mdtype='updateinfo'):
         """ Parse a metadata from a given YumRepository, file, or filename. """
 
-        def _rid(repoid, fmt=_('(from %s)')):
+        def _rid(repoid, fmt=_('(from %s)'), unknown=_("<unknown>")):
             if not repoid:
-                return  fmt % _("UNKNOWN")
+                repoid = unknown
             return fmt % repoid
 
         if not obj:
commit 4afcfb0e02df7253ad9b08f3b426b717a899d27c
Author: Trần Ngọc Quân <vnwildman at gmail.com>
Date:   Sat Jun 7 07:25:29 2014 +0700

    Strip space in _rid() to make translations easier.

diff --git a/yum/update_md.py b/yum/update_md.py
index a62bc00..0fc2088 100644
--- a/yum/update_md.py
+++ b/yum/update_md.py
@@ -527,9 +527,9 @@ class UpdateMetadata(object):
     def add(self, obj, mdtype='updateinfo'):
         """ Parse a metadata from a given YumRepository, file, or filename. """
 
-        def _rid(repoid, fmt=_(' (from %s)')):
+        def _rid(repoid, fmt=_('(from %s)')):
             if not repoid:
-                return ''
+                return  fmt % _("UNKNOWN")
             return fmt % repoid
 
         if not obj:
@@ -559,7 +559,7 @@ class UpdateMetadata(object):
                 try:
                     un = UpdateNotice(elem)
                 except UpdateNoticeException, e:
-                    msg = _("An update notice%s is broken, skipping.") % _rid(repoid)
+                    msg = _("An update notice %s is broken, skipping.") % _rid(repoid)
                     if self._vlogger:
                         self._vlogger.log(logginglevels.DEBUG_1, "%s", msg)
                     else:
@@ -567,9 +567,9 @@ class UpdateMetadata(object):
                     continue
 
                 if not self.add_notice(un):
-                    msg = _("Update notice %s%s is broken, or a bad duplicate, skipping.") % (un['update_id'], _rid(repoid))
+                    msg = _("Update notice %s %s is broken, or a bad duplicate, skipping.") % (un['update_id'], _rid(repoid))
                     if not have_dup:
-                        msg += _('\nYou should report this problem to the owner of the %srepository.') % _rid(repoid, "%s ")
+                        msg += _('\nYou should report this problem to the owner of the %s repository.') % _rid(repoid, "%s")
                     have_dup = True
                     if self._vlogger:
                         self._vlogger.warn("%s", msg)
commit 406fbca7d1020fcf6c9d3d98c02bf8198ea90d57
Author: James Antill <james at and.org>
Date:   Mon Jun 2 13:04:03 2014 -0400

    Have check provides check directly against the rpm index, and then quit.

diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index 138e53f..2d718c1 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -1633,14 +1633,31 @@ class RPMDBPackageSack(PackageSackBase):
                 problems.append(RPMDBProblemObsoleted(pkg, obsoleter=obspo))
         return problems
 
+    def _check_provides_get(self, pkg, provtup):
+        """ This is kind of a super quick version of getProvides(), because all
+            we really care about is that the rpm provides index is functional.
+            We already know the answer to the provides. """
+
+        if False: # This is the slow/steady way...
+            name, flags, version = provtup
+            return pkg in self.getProvides(name, flags, version)
+
+        prcotype = 'provides'
+        n = provtup[0]
+        tag = self.DEP_TABLE[prcotype][0]
+        for hdr, idx in self._get_packages(tag, misc.to_utf8(n)):
+            po = self._makePackageObject(hdr, idx)
+            if po == pkg:
+                return True
+        return False
+
     def check_provides(self):
         """ For each package, check that a provides search for it's name (and
             everything it provides) finds it. """
         problems = []
         for pkg in sorted(self.returnPackages()):
             for provtup in pkg.provides:
-                name, flags, version = provtup
-                if pkg not in self.getProvides(name, flags, version):
+                if not self._check_provides_get(pkg, provtup):
                     problems.append(RPMDBProblemProvides(pkg, provide=provtup))
                     break
         return problems


More information about the Yum-commits mailing list