It will show you all the attributes of the first package you have installed and their named keys in the RPM module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Author: Jonathan Cervidae <jonathan.cervidae@gmail.com>
# PGP Fingerprint: 2DC0 0A44 123E 6CC2 EB55 EAFB B780 421F BF4C 4CB4
# Last changed: $LastEdit: 2009-05-16 18:53:50 BST$
#
# After creating this program, googling for the tag names it found located me
# this document:
#
# http://cpansearch.perl.org/src/RJRAY/Perl-RPM-1.51/RPM/Constants.pm
#
# Which nicely describes what each of these tags are for.
import rpm
import pprint
def is_a_key(string):
for character in string:
ordinal = ord(character)
if ordinal is not 95 and ( ordinal < 65 or ordinal > 90 ):
return False
return True
header_keys = []
transaction_set = rpm.TransactionSet()
match_iterator = transaction_set.dbMatch()
# Map RPM key names to numbers
numbers_to_names = {}
for attribute_name in dir(rpm):
if not is_a_key(attribute_name):
continue
if not isinstance(rpm.__dict__[attribute_name], int):
continue
numbers_to_names[rpm.__dict__[attribute_name]] = attribute_name
header = None
while match_iterator:
try:
header = match_iterator.next()
except StopIteration:
raise RuntimeError, "Not any headers"
break
header_metadata = {}
for key in header.keys():
header_metadata[numbers_to_names[key]] = header[key]
pprint.pprint(header_metadata)
|
If you want to access RPM through python you need to know these things and the authors didn't bother to document them.
Tags: rpm