summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2007-10-25 15:44:13 -0400
committerMichael DeHaan <mdehaan@redhat.com>2007-10-25 15:44:13 -0400
commit8d1b292046848a3cd4201c4cfd531d141ef167ba (patch)
tree4afe8f3bc546d58a177771d705af36aa28bbd591
parent0a7afd78d699958283bb0adff8235ea9d1538280 (diff)
Added rpm package tracking, which shows the full name, epoch, version, release, and arch for every packaged installed on the system, for use with func-inventory and other apps that want it. The module supports a string return for diffs in func-inventory, and also can return arrays for other scripts.
-rw-r--r--func/minion/modules/rpms.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/func/minion/modules/rpms.py b/func/minion/modules/rpms.py
new file mode 100644
index 0000000..901a9d6
--- /dev/null
+++ b/func/minion/modules/rpms.py
@@ -0,0 +1,48 @@
+# Copyright 2007, Red Hat, Inc
+# Michael DeHaan <mdehaan@redhat.com>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+from modules import func_module
+import rpm
+
+class RpmModule(func_module.FuncModule):
+
+ def __init__(self):
+ self.methods = {
+ "inventory" : self.inventory,
+ "info" : self.inventory
+ }
+ func_module.FuncModule.__init__(self)
+
+ def inventory(self, flatten=True):
+ """
+ Returns information on all installed packages.
+ By default, 'flatten' is passed in as True, which makes printouts very clean in diffs
+ for use by func-inventory. If you are writting another software application, using flatten=False will
+ prevent the need to parse the returns.
+ """
+ ts = rpm.TransactionSet()
+ mi = ts.dbMatch()
+ results = []
+ for hdr in mi:
+ name = hdr['name']
+ epoch = hdr['epoch']
+ if epoch is None:
+ epoch = 0
+ version = hdr['version']
+ release = hdr['release']
+ arch = hdr['arch']
+ if flatten:
+ results.append("%s %s %s %s %s" % (name,epoch,version,release,arch))
+ else:
+ results.append([name,epoch,version,release,arch])
+ return results
+
+methods = RpmModule()
+register_rpc = methods.register_rpc