[yum-commits] 2 commits - yum-debug-dump.py yum-debug-restore.py

James Antill james at osuosl.org
Fri Jan 22 00:41:55 UTC 2010


 yum-debug-dump.py    |   21 +++++++++++++++++++++
 yum-debug-restore.py |   42 +++++++++++++++++++++++++++++++++---------
 2 files changed, 54 insertions(+), 9 deletions(-)

New commits:
commit 485d5e6c4c65d106b43f7bbde040b295f8c523ce
Author: James Antill <james at and.org>
Date:   Thu Jan 21 19:41:45 2010 -0500

    Add rpmdb versions to the dump file

diff --git a/yum-debug-dump.py b/yum-debug-dump.py
index e42ab0a..f280d61 100644
--- a/yum-debug-dump.py
+++ b/yum-debug-dump.py
@@ -52,6 +52,25 @@ class YumDebugDump(yum.YumBase):
 
         return msg
 
+    def dump_rpmdb_versions(self):
+        msg = "%%%%RPMDB VERSIONS\n"
+        # This should be the same as the default [yum] group in version-groups
+        yumcore = set(['yum', 'rpm', 'yum-metadata-parser'])
+        yumplus = set(['glibc', 'sqlite',
+                       'libcurl', 'nss',
+                       'rpm', 'rpm-libs', 'rpm-python',
+                       'python',
+                       'python-iniparse', 'python-urlgrabber', 'python-pycurl'])
+        yumplus.update(yumcore)
+        groups = {'yum-core' : yumcore,
+                  'yum'      : yumplus}
+        data = self.rpmdb.simpleVersion(False, groups=groups)
+        msg += '  all: %s\n' % (data[0],)
+        for grp in sorted(data[2]):
+            msg += '  %s: %s\n' % (grp, data[2][grp])
+
+        return msg
+
     def dump_repos(self):
         msg = "%%%%REPOS\n"
         for repo in sorted(self.repos.listEnabled()):
@@ -82,6 +101,7 @@ class YumDebugDump(yum.YumBase):
         msg += "  global excludes: %s\n" % ",".join(self.conf.exclude)
         return msg
 
+    # FIXME: This should use rpmdb.check_*()
     def dump_rpm_problems(self):
 
         pkgs = {}
@@ -156,6 +176,7 @@ class YumDebugDump(yum.YumBase):
         fo.write(self.dump_rpmdb())
         if not self.opts.norepos:
             fo.write(self.dump_repos())
+        fo.write(self.dump_rpmdb_versions())
         fo.close()
         return fn
 
commit d0301f6e5928786d571f4d32986dc2b5bb03c095
Author: James Antill <james at and.org>
Date:   Thu Jan 21 19:01:24 2010 -0500

     A couple of fixes for yum-debug-restore, and can now work across arch.
    
        Add --ignore-arch option.
        Don't traceback when not given an argument.
        Don't traceback when piped. Eg. | head -2

diff --git a/yum-debug-restore.py b/yum-debug-restore.py
index 5652972..fd95741 100755
--- a/yum-debug-restore.py
+++ b/yum-debug-restore.py
@@ -52,6 +52,8 @@ def cmd_line():
 
     parser.add_option("--install-latest", action="store_true",
                       help="install the latest instead of specific versions")
+    parser.add_option("--ignore-arch", action="store_true",
+                      help="ignore arch of packages, so you can dump on .i386 and restore on .x86_64")
 
     parser.add_option("--filter-types", 
                       help="Limit to: install, remove, update, downgrade")
@@ -59,6 +61,7 @@ def cmd_line():
     (opts, args) = parser.parse_args()
     if not args:
         parser.print_usage()
+        sys.exit(1)
     return (opts, args)
 
 class OtherRpmDB:
@@ -91,6 +94,8 @@ class OtherRpmDB:
             self.pkgtups.append(pkgtup)
 
 def naevr2str(n,a,e,v,r):
+    if a is None: # Assume epoch doesn't change without release changing
+        return "%s-%s-%s" % (n,v,r)
     if e in (None, '', '0'):
         return "%s-%s-%s.%s" % (n,v,r,a)
     return "%s-%s:%s-%s.%s" % (n,e,v,r,a)
@@ -98,28 +103,39 @@ def pkgtup2str(pkgtup):
     n,a,e,v,r = pkgtup
     return naevr2str(n,a,e,v,r)
 
-def pkg_data2list(yb, opkgtups, opkgmaps, install_latest):
+def pkg_data2list(yb, opkgtups, opkgmaps, install_latest, ignore_arch):
     ret = []
     npkgtups = set()
     npkgmaps = {}
     for po in sorted(yb.rpmdb.returnPackages()):
+        arch = po.arch
+        if ignore_arch:
+            arch = None
         if False: pass
-        elif (po.name, po.arch) not in opkgmaps:
+        elif (po.name, arch) not in opkgmaps:
             ret.append(("remove", str(po)))
         elif po.pkgtup not in opkgtups:
-            n,a,e,v,r = opkgmaps[(po.name, po.arch)]
+            n,a,e,v,r = opkgmaps[(po.name, arch)]
             pinstEVR = yum.packages.PackageEVR(e, v, r)
-            if po.EVR < pinstEVR:
-                ret.append(("upgrade",   naevr2str(n,a,e,v,r)))
+            if po.EVR == pinstEVR:
+                assert ignore_arch and po.arch != a
+            elif po.EVR < pinstEVR:
+                ret.append(("upgrade",   naevr2str(n,arch,e,v,r)))
             else:
-                ret.append(("downgrade", naevr2str(n,a,e,v,r)))
+                ret.append(("downgrade", naevr2str(n,arch,e,v,r)))
         npkgtups.add(po.pkgtup)
         npkgmaps[(po.name, po.arch)] = po
+        if ignore_arch:
+            npkgmaps[(po.name, None)] = po
 
     for name, arch in sorted(opkgmaps):
+        if ignore_arch and arch is not None:
+            continue
         if (name, arch) in npkgmaps:
             continue
-        if install_latest:
+        if install_latest and ignore_arch:
+            ret.append(("install", name))
+        elif install_latest:
             ret.append(("install", "%s.%s" % (name, arch)))
         else:
             ret.append(("install", pkgtup2str(opkgmaps[(name, arch)])))
@@ -160,6 +176,9 @@ def main():
     opkgmaps = {}
     for pkgtup in orpmdb.pkgtups:
         opkgmaps[(pkgtup[0], pkgtup[1])] = pkgtup
+        if opts.ignore_arch:
+            n,a,e,v,r = pkgtup
+            opkgmaps[(pkgtup[0], None)] = n,None,e,v,r
 
     if opts.output:
         fo = sys.stdout
@@ -178,11 +197,16 @@ def main():
 
     counts = {}
     for T, pkg in pkg_data2list(yb, set(orpmdb.pkgtups), opkgmaps,
-                                opts.install_latest):
+                                opts.install_latest, opts.ignore_arch):
         if fT is not None and T not in fT:
             continue
         counts[T] = counts.get(T, 0) + 1
-        print >>fo, "%-9s %s" % (T, pkg)
+        try:
+            print >>fo, "%-9s %s" % (T, pkg)
+        except IOError:
+            if opts.output: # mainly due to |
+                sys.exit(1)
+            raise
 
     if opts.output:
         sys.exit(0)


More information about the Yum-commits mailing list