summaryrefslogtreecommitdiffstats
path: root/tools/rpmlisting.py
diff options
context:
space:
mode:
authorJason Pepas <cell@ices.utexas.edu>2006-08-25 13:54:46 +0000
committerJason Pepas <cell@ices.utexas.edu>2006-08-25 13:54:46 +0000
commit55f761496835c56417995ddefaf41d313fb2cda5 (patch)
tree8c61035059d9a422e414113c77fcf0629e26d5b3 /tools/rpmlisting.py
parent7af374b0d38e4507a9f2606fc682cb06fb959a9b (diff)
downloadbcfg2-55f761496835c56417995ddefaf41d313fb2cda5.tar.gz
bcfg2-55f761496835c56417995ddefaf41d313fb2cda5.tar.bz2
bcfg2-55f761496835c56417995ddefaf41d313fb2cda5.zip
Added 'get_pkgs2()' to rpmlisting.py, which parses rpm filenames instead of using the rpm command to read rpm meta data. On my machine, this resulted in a runtime reduction from half an hour to 3 seconds.
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2110 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'tools/rpmlisting.py')
-rw-r--r--tools/rpmlisting.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tools/rpmlisting.py b/tools/rpmlisting.py
index c6347e97b..1f23e9905 100644
--- a/tools/rpmlisting.py
+++ b/tools/rpmlisting.py
@@ -137,6 +137,29 @@ pkgs = {
return pkgs
+def get_pkgs2(rpmdir):
+ """scan a dir of rpms and generate a pkgs structure. this version parses the filenames directly instead of reading their metadata. on my machine, this brought runtime from half an hour down to 3 seconds."""
+ pkgs = {}
+ rpms = [item for item in os.listdir(rpmdir) if item.endswith('.rpm')]
+ for filename in rpms:
+ name, version, release, arch = None, None, None, None
+ (major, minor) = sys.version_info[:2]
+ if major >= 2 and minor >= 4:
+ (blob, arch, extension) = filename.rsplit('.', 2)
+ (name, version, release) = blob.rsplit('-', 2)
+ else:
+ (rextension, rarch, rblob) = filename[::-1].split('.', 2)
+ (blob, arch, extension) = (rblob[::-1], rarch[::-1], rextension[::-1])
+ (rrelease, rversion, rname) = blob[::-1].split('-', 2)
+ (name, version, release) = (rname[::-1], rversion[::-1], rrelease[::-1])
+ rpmblob = {'file':filename, 'name':name, 'version':version, 'release':release, 'arch':arch}
+ if pkgs.has_key(name):
+ pkgs[name].append(rpmblob)
+ else:
+ pkgs[name] = [rpmblob]
+ return pkgs
+
+
def prune_pkgs(pkgs):
"""prune a pkgs structure to contain only the latest version of each package (includes multiarch results)."""
latest_pkgs = {}
@@ -189,7 +212,7 @@ def scan_rpm_dir(rpmdir, uri, group, priority=0, output=sys.stdout):
"""the meat of this library."""
output.write('<PackageList uri="%s" type="rpm" priority="%s">\n' % (uri, priority))
output.write(' <Group name="%s">\n' % group)
- pkgs = prune_archs(prune_pkgs(get_pkgs(rpmdir)))
+ pkgs = prune_archs(prune_pkgs(get_pkgs2(rpmdir)))
for rpmblobs in sorted_values(pkgs):
if len(rpmblobs) == 1:
# regular pkgmgr entry