Commit d0301f6e authored by James Antill's avatar James Antill

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
parent 1c066e5b
...@@ -52,6 +52,8 @@ def cmd_line(): ...@@ -52,6 +52,8 @@ def cmd_line():
parser.add_option("--install-latest", action="store_true", parser.add_option("--install-latest", action="store_true",
help="install the latest instead of specific versions") 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", parser.add_option("--filter-types",
help="Limit to: install, remove, update, downgrade") help="Limit to: install, remove, update, downgrade")
...@@ -59,6 +61,7 @@ def cmd_line(): ...@@ -59,6 +61,7 @@ def cmd_line():
(opts, args) = parser.parse_args() (opts, args) = parser.parse_args()
if not args: if not args:
parser.print_usage() parser.print_usage()
return (opts, args) return (opts, args)
class OtherRpmDB: class OtherRpmDB:
...@@ -91,6 +94,8 @@ class OtherRpmDB: ...@@ -91,6 +94,8 @@ class OtherRpmDB:
self.pkgtups.append(pkgtup) self.pkgtups.append(pkgtup)
def naevr2str(n,a,e,v,r): 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'): if e in (None, '', '0'):
return "%s-%s-%s.%s" % (n,v,r,a) return "%s-%s-%s.%s" % (n,v,r,a)
return "%s-%s:%s-%s.%s" % (n,e,v,r,a) return "%s-%s:%s-%s.%s" % (n,e,v,r,a)
...@@ -98,28 +103,39 @@ def pkgtup2str(pkgtup): ...@@ -98,28 +103,39 @@ def pkgtup2str(pkgtup):
n,a,e,v,r = pkgtup n,a,e,v,r = pkgtup
return naevr2str(n,a,e,v,r) 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 = [] ret = []
npkgtups = set() npkgtups = set()
npkgmaps = {} npkgmaps = {}
for po in sorted(yb.rpmdb.returnPackages()): for po in sorted(yb.rpmdb.returnPackages()):
arch = po.arch
if ignore_arch:
arch = None
if False: pass if False: pass
elif (, po.arch) not in opkgmaps: elif (, arch) not in opkgmaps:
ret.append(("remove", str(po))) ret.append(("remove", str(po)))
elif po.pkgtup not in opkgtups: elif po.pkgtup not in opkgtups:
n,a,e,v,r = opkgmaps[(, po.arch)] n,a,e,v,r = opkgmaps[(, arch)]
pinstEVR = yum.packages.PackageEVR(e, v, r) pinstEVR = yum.packages.PackageEVR(e, v, r)
if po.EVR < pinstEVR: if po.EVR == pinstEVR:
ret.append(("upgrade", naevr2str(n,a,e,v,r))) assert ignore_arch and po.arch != a
elif po.EVR < pinstEVR:
ret.append(("upgrade", naevr2str(n,arch,e,v,r)))
else: else:
ret.append(("downgrade", naevr2str(n,a,e,v,r))) ret.append(("downgrade", naevr2str(n,arch,e,v,r)))
npkgtups.add(po.pkgtup) npkgtups.add(po.pkgtup)
npkgmaps[(, po.arch)] = po npkgmaps[(, po.arch)] = po
if ignore_arch:
npkgmaps[(, None)] = po
for name, arch in sorted(opkgmaps): for name, arch in sorted(opkgmaps):
if ignore_arch and arch is not None:
if (name, arch) in npkgmaps: if (name, arch) in npkgmaps:
continue continue
if install_latest: if install_latest and ignore_arch:
ret.append(("install", name))
elif install_latest:
ret.append(("install", "%s.%s" % (name, arch))) ret.append(("install", "%s.%s" % (name, arch)))
else: else:
ret.append(("install", pkgtup2str(opkgmaps[(name, arch)]))) ret.append(("install", pkgtup2str(opkgmaps[(name, arch)])))
...@@ -160,6 +176,9 @@ def main(): ...@@ -160,6 +176,9 @@ def main():
opkgmaps = {} opkgmaps = {}
for pkgtup in orpmdb.pkgtups: for pkgtup in orpmdb.pkgtups:
opkgmaps[(pkgtup[0], pkgtup[1])] = pkgtup 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: if opts.output:
fo = sys.stdout fo = sys.stdout
...@@ -178,11 +197,16 @@ def main(): ...@@ -178,11 +197,16 @@ def main():
counts = {} counts = {}
for T, pkg in pkg_data2list(yb, set(orpmdb.pkgtups), opkgmaps, 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: if fT is not None and T not in fT:
continue continue
counts[T] = counts.get(T, 0) + 1 counts[T] = counts.get(T, 0) + 1
print >>fo, "%-9s %s" % (T, pkg) print >>fo, "%-9s %s" % (T, pkg)
except IOError:
if opts.output: # mainly due to |
if opts.output: if opts.output:
sys.exit(0) sys.exit(0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment