class RpmHeader object def __init__ self hdr self hdr hdr def __repr__

 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
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 rpmstub
for tag in dir(rpmstub):
if tag.startswith('RPMTAG_'):
_add_getter_to_rpmheader(tag[7:].lower(), getattr(rpm, tag))
_populate_rpm_header_class()
def read_file(f):
import rpmstub
return map(RpmHeader, rpmstub.readHeaderListFromFile(f))
s = read_file(None)
z = repr(s) ## value z => "<RPM header 7:3proxy-0.5.3h.alt1>"