summaryrefslogtreecommitdiff
path: root/rpmdircmp
diff options
context:
space:
mode:
authorThomas Arendsen Hein <thomas@intevation.de>2008-03-13 17:30:47 (GMT)
committerThomas Arendsen Hein <thomas@intevation.de>2008-03-13 17:30:47 (GMT)
commit9674746b16fb884ef2b36c52e0bc5ef74b517d36 (patch)
tree6def0f5c944df8e013a501c7f6dce8c97fa79e2a /rpmdircmp
parentb2007fb1460ff597e0a37fcc7fb6b1bf689a7afd (diff)
downloadserver-9674746b16fb884ef2b36c52e0bc5ef74b517d36.tar.gz
rpmdircmp: Be able to run on binary rpms, too
Diffstat (limited to 'rpmdircmp')
-rwxr-xr-xrpmdircmp32
1 files changed, 20 insertions, 12 deletions
diff --git a/rpmdircmp b/rpmdircmp
index 4bc59a2..86de671 100755
--- a/rpmdircmp
+++ b/rpmdircmp
@@ -7,7 +7,7 @@
# This program is free software under the GPL (>=v2)
"""
-rpmdircmp olddir newdir
+rpmdircmp olddir newdir [ext]
Prints list of removed/added/updated/unchanged rpm packages
"""
@@ -30,9 +30,10 @@ def rpmpackager(rpmdir, rpm):
_packagercache[rpm] = packager
return packager
-def rpmdir2list(rpmdir):
- """Returns list of all .src.rpm files in the given directory.
+def rpmdir2list(rpmdir, ext):
+ """Returns list of all rpm files in the given directory.
+ rpm files must have the extension "ext", e.g. ".src.rpm".
The list contains tuples: (name, version, release, packager)
"""
rpms = []
@@ -42,16 +43,16 @@ def rpmdir2list(rpmdir):
for rpm in dirlist:
sys.stderr.write("%d ... \r" % todo)
todo -= 1
- if rpm.endswith('.src.rpm'):
- entry = rpm[:-len('src.rpm')-1].rsplit('-', 2)
+ if rpm.endswith(ext):
+ entry = rpm[:-len(ext)-1].rsplit('-', 2)
entry.append(rpmpackager(rpmdir, rpm))
rpms.append(tuple(entry))
sys.stderr.write('OK. \n')
return rpms
-def rpmsets(rpmdir):
+def rpmsets(rpmdir, ext):
names = {}
- rpms = rpmdir2list(rpmdir)
+ rpms = rpmdir2list(rpmdir, ext)
for rpm in rpms:
name = rpm[0]
if name in names:
@@ -59,11 +60,11 @@ def rpmsets(rpmdir):
names[name] = rpm
return set(rpms), set(names), names
-if len(sys.argv[1:]) != 2:
- sys.stderr.write("%s\n" % __doc__)
-else:
- oldrpms, oldnames, olddict = rpmsets(sys.argv[1])
- newrpms, newnames, newdict = rpmsets(sys.argv[2])
+def main(olddir, newdir, ext=None):
+ if not ext:
+ ext = '.src.rpm'
+ oldrpms, oldnames, olddict = rpmsets(olddir, ext)
+ newrpms, newnames, newdict = rpmsets(newdir, ext)
removed = [olddict[name] for name in list(oldnames.difference(newnames))]
added = [newdict[name] for name in list(newnames.difference(oldnames))]
@@ -92,3 +93,10 @@ else:
if wrote_title:
sys.stdout.write("\n")
+
+if __name__ == "__main__":
+ if 2 <= len(sys.argv[1:]) <= 3:
+ main(*sys.argv[1:])
+ else:
+ sys.stderr.write("%s\n" % __doc__)
+