summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
authorAdrian Likins <alikins@redhat.com>2008-06-26 12:42:06 -0400
committerAdrian Likins <alikins@redhat.com>2008-06-26 12:42:06 -0400
commit1f630443252840ff8fc6e1b590b50723688a79e8 (patch)
treefba49a06b5050a19d63aba7bd46a70737d083759 /func
parent4cf4083fb47bc00cee7c9b7a03201b2db71e8599 (diff)
downloadthird_party-func-1f630443252840ff8fc6e1b590b50723688a79e8.tar.gz
third_party-func-1f630443252840ff8fc6e1b590b50723688a79e8.tar.xz
third_party-func-1f630443252840ff8fc6e1b590b50723688a79e8.zip
add "glob" method to rpm minion module, and add test cases
patch from Pradeep Kilambi <pkilambi@redhat.com> (with a small change to handle arch being "None" for gpg-pubkey packages)
Diffstat (limited to 'func')
-rw-r--r--func/minion/modules/rpms.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/func/minion/modules/rpms.py b/func/minion/modules/rpms.py
index ae26cb4..66d9129 100644
--- a/func/minion/modules/rpms.py
+++ b/func/minion/modules/rpms.py
@@ -42,3 +42,28 @@ class RpmModule(func_module.FuncModule):
else:
results.append([name, epoch, version, release, arch])
return results
+
+ def glob(self, pattern, flatten=True):
+ """
+ Return a list of installed packages that match a pattern
+ """
+ ts = rpm.TransactionSet()
+ mi = ts.dbMatch()
+ results = []
+ if not mi:
+ return
+ mi.pattern('name', rpm.RPMMIRE_GLOB, pattern)
+ for hdr in mi:
+ name = hdr['name']
+ epoch = (hdr['epoch'] or 0)
+ version = hdr['version']
+ release = hdr['release']
+ # gpg-pubkeys have no arch
+ arch = (hdr['arch'] or "")
+
+ if flatten:
+ results.append("%s %s %s %s %s" % (name, epoch, version,
+ release, arch))
+ else:
+ results.append([name, epoch, version, release, arch])
+ return results