[yum-commits] 4 commits - yumcommands.py

James Antill james at osuosl.org
Mon Feb 24 02:01:06 UTC 2014


 yumcommands.py |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

New commits:
commit 0e6f4f26d2241360a1f62b8c91fef4a41fb90b6e
Merge: 77c85ef 4c866fe
Author: James Antill <james at and.org>
Date:   Sun Feb 23 21:00:24 2014 -0500

    Merge branch 'master' of ssh://yum.baseurl.org/srv/projects/yum/git/yum
    
    * 'master' of ssh://yum.baseurl.org/srv/projects/yum/git/yum: (2 commits)
      Copy packages in/out of an installroot, for no downloads creating containers.
      ...
    
     Screwed up double commit.
    
    Conflicts:
    	yumcommands.py

commit 77c85efcb09f0121d6a611d92e1fc6a237179656
Author: James Antill <james at and.org>
Date:   Sun Feb 23 20:57:06 2014 -0500

    Choose yum.conf correctly for fs filter saving.

diff --git a/yumcommands.py b/yumcommands.py
index 4385a34..ef84c1f 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -4632,7 +4632,9 @@ class FSCommand(YumCommand):
             if not os.path.exists(fn):
                 # Try the old default
                 nfn = base.conf.installroot+'/etc/yum.conf'
-                if not os.path.exists(nfn):
+                if os.path.exists(nfn):
+                    fn = nfn
+                else:
                     shutil.copy2(base.conf.config_file_path, fn)
             ybc = base.conf
             writeRawConfigFile(fn, 'main', ybc.yumvar,
commit fcec4d88fa18c30e1aeabf724bec11dcfb1e2655
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/rpm2cpio.
    . 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..4385a34 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,14 @@ 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")
+        # These just shouldn't happen...
+        if not distutils.spawn.find_executable("cpio"):
+            raise yum.Errors.YumBaseError, _("Can't find cpio command")
+        if not distutils.spawn.find_executable("rpm2cpio"):
+            raise yum.Errors.YumBaseError, _("Can't find rpm2cpio command")
+
         prefix = "."
         if extcmds:
             prefix = extcmds[0]
@@ -4845,7 +4884,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 +4910,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 00aec000813db1b45a7b38e1aa396b1bb8764eb7
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()


More information about the Yum-commits mailing list