[yum-commits] 3 commits - yumcommands.py yum/__init__.py yum.spec

James Antill james at osuosl.org
Fri Feb 21 21:22:22 UTC 2014


 yum.spec        |    3 +
 yum/__init__.py |   26 +++++++++++++++++
 yumcommands.py  |   85 ++++++++++++++++++++++++++++++++++++++++----------------
 3 files changed, 90 insertions(+), 24 deletions(-)

New commits:
commit 4c866fe059fb0545fc842473561ac73009cbdf11
Author: James Antill <james at and.org>
Date:   Fri Feb 21 16:19:28 2014 -0500

    Copy packages in/out of an installroot, for no downloads creating containers.

diff --git a/yum/__init__.py b/yum/__init__.py
index 37ab468..dc468cb 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -45,6 +45,7 @@ import logging
 import logging.config
 import operator
 import tempfile
+import shutil
 
 import yum.i18n
 # This is required to make gaftonmode work...
@@ -689,6 +690,12 @@ class YumBase(depsolve.Depsolve):
         if hasattr(self, 'prerepoconf'):
             self.conf # touch the config class first
 
+            if (self.conf.installroot != '/' and
+                not hasattr(self, '_old_cachedir')):
+                # Try loading cache from outside...
+                ir = len(self.conf.installroot)
+                self._old_cachedir = self.conf.cachedir[ir:]
+
             self.getReposFromConfig()
 
         #  For rhnplugin, and in theory other stuff, calling
@@ -2398,6 +2405,9 @@ much more problems).
                 self.verbose_logger.warn(_("ignoring a dupe of %s") % po)
                 return True
             beenthere.add(local)
+            if downloadonly and not os.path.exists(local):
+              # Check before we munge the name...
+              po.repo._preload_pkg_from_system_cache(po)
             if os.path.exists(local):
                 if self.verifyPkg(local, po, False):
                     self.verbose_logger.debug(_("using local copy of %s") % po)
@@ -2442,6 +2452,22 @@ much more problems).
                 format_number(rpmsize), format_number(deltasize), 100 - deltasize*100.0/rpmsize)
 
         if downloadonly:
+            if hasattr(self, '_old_cachedir'):
+              # Try to link/copy them out, if we have somewhere to put them.
+
+              for po in pkglist:
+                if not po.localpath.startswith(self.conf.cachedir):
+                  continue
+
+                end = po.localpath[len(self.conf.cachedir):]
+                try:
+                  os.link(po.localpath, self._old_cachedir + end)
+                except:
+                  try:
+                    shutil.copy2(po.localpath, self._old_cachedir + end)
+                  except:
+                    pass
+
             # close DBs, unlock
             self.repos.close()
             self.closeRpmDB()
commit 907aa56f37d33a40d9a77e77ca58335534ce50f6
Author: James Antill <james at and.org>
Date:   Fri Feb 21 16:16:23 2014 -0500

     A few cleanups for the fs sub-command:
    
    . Add checks for diff/cpio.
    . Add missing import for rpm, when override_install_langs isn't set.
    . Allow users to run some of the commands.
    . Map fs snap to fssnap command.
    . Add translations and add messages when you alter the filters.
    . Save config. file inside the chroot.

diff --git a/yumcommands.py b/yumcommands.py
index 52b8c90..f98d99e 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -23,6 +23,7 @@ Classes for subcommands of the yum command line interface.
 import os
 import sys
 import cli
+import rpm
 from yum import logginglevels
 from yum import _, P_
 from yum import misc
@@ -34,6 +35,7 @@ import time
 from yum.i18n import utf8_width, utf8_width_fill, to_unicode, exception2msg
 import tempfile
 import shutil
+import distutils.spawn
 import glob
 
 import yum.config
@@ -4334,6 +4336,14 @@ class FSCommand(YumCommand):
         :param basecmd: the name of the command
         :param extcmds: the command line arguments passed to *basecmd*
         """
+        if extcmds and extcmds[0] in ('du', 'status', 'diff'):
+            # Anyone can go for it...
+            return
+
+        if len(extcmds) == 1 and extcmds[0] in ('filters', 'filter'):
+            # Can look, but not touch.
+            return
+
         checkRootUID(base)
 
     def _fs_pkg_walk(self, pkgs, prefix, modified=False, verbose=False):
@@ -4611,22 +4621,48 @@ class FSCommand(YumCommand):
                 break
 
     def _fs_filters(self, base, extcmds):
-        writeRawConfigFile = yum.config._writeRawConfigFile
+        def _save(confkey):
+            writeRawConfigFile = yum.config._writeRawConfigFile
+
+            # Always create installroot, so we can change it.
+            if not os.path.exists(base.conf.installroot + '/etc/yum'):
+                os.makedirs(base.conf.installroot + '/etc/yum')
+
+            fn = base.conf.installroot+'/etc/yum/yum.conf'
+            if not os.path.exists(fn):
+                # Try the old default
+                nfn = base.conf.installroot+'/etc/yum.conf'
+                if not os.path.exists(nfn):
+                    shutil.copy2(base.conf.config_file_path, fn)
+            ybc = base.conf
+            writeRawConfigFile(fn, 'main', ybc.yumvar,
+                               ybc.cfg.options, ybc.iteritems,
+                               ybc.optionobj,
+                               only=[confkey])
 
         if not extcmds:
             oil = base.conf.override_install_langs
             if not oil:
                 oil = "rpm: " + rpm.expandMacro("%_install_langs")
-            print "File system filters:"
-            print "  Nodocs:", 'nodocs' in base.conf.tsflags
-            print "  Languages:", oil
+            print _("File system filters:")
+            print _("  Nodocs:"), 'nodocs' in base.conf.tsflags
+            print _("  Languages:"), oil
         elif extcmds[0] in ('docs', 'nodocs',
                             'documentation', 'nodocumentation'):
             c_f = 'nodocs' in base.conf.tsflags
-            n_f = extcmds[0].startswith('no')
+            n_f = not extcmds[0].startswith('no')
             if n_f == c_f:
+                if n_f:
+                    print _("Already enabled documentation filter.")
+                else:
+                    print _("Already disabled documentation filter.")
                 return
 
+            if n_f:
+                print _("Enabling documentation filter.")
+            else:
+                print _("Disabling documentation filter.")
+
             nts = base.conf.tsflags
             if n_f:
                 nts = nts + ['nodocs']
@@ -4634,15 +4670,8 @@ class FSCommand(YumCommand):
                 nts = [x for x in nts if x != 'nodocs']
             base.conf.tsflags = " ".join(nts)
 
-            fn = '/etc/yum/yum.conf'
-            if not os.path.exists(fn):
-                # Try the old default
-                fn = '/etc/yum.conf'
-            ybc = base.conf
-            writeRawConfigFile(fn, 'main', ybc.yumvar,
-                               ybc.cfg.options, ybc.iteritems,
-                               ybc.optionobj,
-                               only=['tsflags'])
+            _save('tsflags')
+
         elif extcmds[0] in ('langs', 'nolangs', 'lang', 'nolang',
                             'languages', 'nolanguages',
                             'language', 'nolanguage'):
@@ -4652,19 +4681,21 @@ class FSCommand(YumCommand):
                 val = ":".join(extcmds[1:])
 
             if val == base.conf.override_install_langs:
+                if val:
+                    print _("Already filtering languages to: %s") % val
+                else:
+                    print _("Already disabled language filter.")
                 return
 
+            if val:
+                print _("Setting language filter to: %s") % val
+            else:
+                print _("Disabling language filter.")
+
             base.conf.override_install_langs = val
 
-            fn = '/etc/yum/yum.conf'
-            if not os.path.exists(fn):
-                # Try the old default
-                fn = '/etc/yum.conf'
-            ybc = base.conf
-            writeRawConfigFile(fn, 'main', ybc.yumvar,
-                               ybc.cfg.options, ybc.iteritems,
-                               ybc.optionobj,
-                               only=['override_install_langs'])
+            _save('override_install_langs')
+
         else:
             return 1, [_('Not a valid sub-command of fs filter')]
 
@@ -4736,6 +4767,9 @@ class FSCommand(YumCommand):
             else:
                 print >>sys.stderr, _('Not packaged?:'), fpath
 
+        if not distutils.spawn.find_executable("diff"):
+            raise yum.Errors.YumBaseError, _("Can't find diff command")
+
         prefix = "."
         if extcmds:
             prefix = extcmds[0]
@@ -4845,7 +4879,7 @@ class FSCommand(YumCommand):
         """
         if extcmds and extcmds[0] in ('filters', 'filter',
                                       'refilter', 'refilter-cleanup',
-                                      'du', 'status', 'diff'):
+                                      'du', 'status', 'diff', 'snap'):
             subcommand = extcmds[0]
             extcmds = extcmds[1:]
         else:
@@ -4871,6 +4905,9 @@ class FSCommand(YumCommand):
         elif subcommand == 'status':
             ret = self._fs_status(base, extcmds)
 
+        elif subcommand == 'snap':
+            ret = FSSnapshotCommand().doCommand(base, 'fs snap', args)
+
         else:
             return 1, [_('Not a valid sub-command of %s') % basecmd]
 
commit f932ddc40d8452c1a7d46d7c7fd8eb90b6f5cac2
Author: James Antill <james at and.org>
Date:   Fri Feb 21 16:15:01 2014 -0500

    Add spec requires for fs sub-command.

diff --git a/yum.spec b/yum.spec
index 93cfa14..854baf3 100644
--- a/yum.spec
+++ b/yum.spec
@@ -98,6 +98,9 @@ Requires: pygpgme
 Requires: pyliblzma
 # Not really a suggests anymore, due to metadata using it.
 Requires: pyxattr
+# Suggests, needed for yum fs diff
+Requires: diffutils
+Requires: cpio
 
 Conflicts: rpm >= 5-0
 # Zif is a re-implementation of yum in C, however:


More information about the Yum-commits mailing list