Convenience wrapper around rpm hdr class rpm hdr provides all the RPM

 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
"""
Convenience wrapper around rpm.hdr class.
rpm.hdr provides all the RPM fields by the indexes defined in rpm module, which
is not convenient. This wrapper adds RpmHeader class with .field_name access to
the RPM header values.
Accessors are not generated on-the-fly, so dir(RpmHeader) and code completion in
interactive shell will work properly.
"""
class RpmHeader(object):
def __init__(self, hdr):
self.hdr = hdr
def __repr__(self):
if self.epoch:
return "<RPM header %d:%s-%s.%s>" % (self.epoch, self.name, self.version, self.release)
else:
return "<RPM header %s-%s.%s>" % (self.name, self.version, self.release)
def _add_getter_to_rpmheader(name, value):
def getter(self):
return self.hdr[value]
setattr(RpmHeader, name, property(getter))
def _populate_rpm_header_class():
import rpm
for tag in dir(rpm):
if tag.startswith('RPMTAG_'):
_add_getter_to_rpmheader(tag[7:].lower(), getattr(rpm, tag))
_populate_rpm_header_class()
def read_file(f):
import rpm
return map(RpmHeader, rpm.readHeaderListFromFile(f))