1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import os
18 import rpm
19 from rhn.i18n import sstr
20 from up2date_client import transaction
21
22 import gettext
23 t = gettext.translation('rhn-client-tools', fallback=True)
24
25 if not hasattr(t, 'ugettext'):
26 t.ugettext = t.gettext
27 _ = t.ugettext
28
30 """ just cause this is such a potentially useful looking method... """
31 _ts = transaction.initReadOnlyTransaction()
32 mi = _ts.dbMatch()
33 for keyword in kwargs.keys():
34 mi.pattern(keyword, rpm.RPMMIRE_GLOB, kwargs[keyword])
35
36 headerList = []
37 for h in mi:
38 headerList.append(h)
39
40 return headerList
41
43 """ given a list of package labels, run rpm -V on them
44 and return a dict keyed off that data
45 """
46 data = {}
47 missing_packages = []
48
49
50
51
52
53 retlist = []
54 for package in packages:
55
56
57
58
59
60 keywords = {'name': package[0],
61 'version': package[1],
62 'release': package[2],
63
64 'arch': package[4]
65 }
66 for key in (keywords.keys()):
67 if (keywords[key] == None) or (keywords[key] == ""):
68 del(keywords[key])
69
70 headers = installedHeaderByKeyword(**keywords)
71 if len(headers) == 0:
72 missing_packages.append(package)
73
74 for header in headers:
75 epoch = header['epoch']
76 if epoch == None:
77 epoch = ""
78
79 arch = header["arch"]
80 if arch == None:
81 arch = ""
82
83 pkg = (header['name'], header['version'],
84 header['release'], epoch,
85 arch)
86
87
88 if header["arch"] == "":
89 packageLabel = "%s-%s-%s" % (pkg[0], pkg[1], pkg[2])
90 else:
91 packageLabel = "%s-%s-%s.%s" % (pkg[0], pkg[1], pkg[2], pkg[4])
92
93 verifystring = "/usr/bin/rpmverify -V %s" % packageLabel
94
95 fd = os.popen(verifystring)
96 res = fd.readlines()
97 fd.close()
98
99 reslist = []
100 for line in res:
101 reslist.append(line.strip())
102 retlist.append([pkg, reslist])
103
104 return retlist, missing_packages
105
106
107
110 """ Return list of packages. Package is hash with keys name, epoch,
111 version, release and optionaly arch and cookie
112 """
113 pkg_list = []
114
115 if msgCallback != None:
116 msgCallback(_("Getting list of packages installed on the system"))
117
118 _ts = transaction.initReadOnlyTransaction()
119 count = 0
120 total = 0
121
122 for h in _ts.dbMatch():
123 if h == None:
124 break
125 count = count + 1
126
127 total = count
128
129 count = 0
130 for h in _ts.dbMatch():
131 if h == None:
132 break
133 package = {
134 'name': sstr(h['name']),
135 'epoch': h['epoch'],
136 'version': sstr(h['version']),
137 'release': sstr(h['release']),
138 'installtime': h['installtime']
139 }
140 if package['epoch'] == None:
141 package['epoch'] = ""
142 else:
143 package['epoch'] = "%s" % package['epoch']
144 if getArch:
145 package['arch'] = h['arch']
146
147 if package['arch']:
148 package['arch'] = sstr(package['arch'])
149 pkg_list.append(package)
150 elif getInfo:
151 if h['arch']:
152 package['arch'] = sstr(h['arch'])
153 if h['cookie']:
154 package['cookie'] = sstr(h['cookie'])
155 pkg_list.append(package)
156 else:
157 pkg_list.append(package)
158
159 if progressCallback != None:
160 progressCallback(count, total)
161 count = count + 1
162
163 pkg_list.sort(key=lambda x:(x['name'], x['epoch'], x['version'], x['release']))
164 return pkg_list
165
167 """Set rpm's verbosity mode
168 """
169 try:
170 rpm.setVerbosity(rpm.RPMLOG_DEBUG)
171 except AttributeError:
172 print("extra verbosity not supported in this version of rpm")
173