forked from rpm-software-management/yum-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
show-changed-rco.py
executable file
·309 lines (261 loc) · 10.1 KB
/
show-changed-rco.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#! /usr/bin/python -tt
#!/usr/bin/python -tt
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import yum
import os
from optparse import OptionParser
from optparse import SUPPRESS_HELP
version = "1.0.0"
def _get_npkgs(self, args):
pkgs = []
for arg in args:
if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
os.path.exists(arg))):
thispkg = yum.packages.YumUrlPackage(self, self.ts, arg)
pkgs.append(thispkg)
elif self.conf.showdupesfromrepos:
pkgs.extend(self.pkgSack.returnPackages(patterns=[arg]))
else:
try:
pkgs.extend(self.pkgSack.returnNewestByName(patterns=[arg]))
except yum.Errors.PackageSackError:
pass
return pkgs
def _get_opkgs(self, npkgs, old_packages):
if old_packages:
return _get_npkgs(self, old_packages)
pkg_names = set((pkg.name for pkg in npkgs))
return self.rpmdb.searchNames(pkg_names)
def _get_oreqs(pkg, reqs):
oreqs = {}
for req in reqs:
(r,f,v) = req
if r.startswith('rpmlib('):
continue
if r not in oreqs:
oreqs[r] = set([req])
else:
oreqs[r].add(req)
return oreqs
def _get_reqs(pkg, reqs, oreqs, self_prov_check=True):
nreqs = set()
creqs = set()
for req in reqs:
(r,f,v) = req
if r.startswith('rpmlib('):
continue
if r in oreqs and req in oreqs[r]:
continue
if (r in pkg.provides_names or
(r[0] == '/' and r in (pkg.filelist + pkg.dirlist +
pkg.ghostlist))):
if not f or pkg.checkPrco('provides', req):
continue
if r in oreqs:
creqs.add(req)
else:
nreqs.add(req)
return nreqs, creqs
def _print_reqs(yb, pkg, reqs, used_repos):
out_reqs = {}
for req in reqs:
(r,f,v) = req
seen = {}
out_reqs[req] = []
for pkg in sorted(yb.rpmdb.searchProvides(req)):
key = (pkg.name, pkg.arch)
if key in seen and not yb.conf.showdupesfromrepos:
continue
seen[key] = pkg
out_reqs[req].append(pkg)
used_repos.append(pkg.ui_from_repo)
for pkg in sorted(yb.pkgSack.searchProvides(req)):
key = (pkg.name, pkg.arch)
if key in seen and not yb.conf.showdupesfromrepos:
continue
seen[key] = pkg
out_reqs[req].append(pkg)
used_repos.append(pkg.ui_from_repo)
done = set()
for req in sorted(out_reqs):
if req in done:
continue
done.add(req)
print " ", yum.misc.prco_tuple_to_string(req)
for oreq in sorted(out_reqs):
if oreq in done:
continue
if req == oreq:
continue
if out_reqs[oreq] == out_reqs[req]:
print " ", yum.misc.prco_tuple_to_string(oreq)
done.add(oreq)
for pkg in out_reqs[req]:
print " ", pkg, pkg.ui_from_repo
def _print_sum(title, used_repos, ind=" ", end=' '):
if not used_repos:
return
print title
crepos = {}
installed = 0
available = 0
for urepo in used_repos:
if urepo not in crepos:
crepos[urepo] = 0
crepos[urepo] += 1
if urepo[0] == '@':
installed += 1
else:
available += 1
if installed:
print ind, "Installed:", installed
for urepo in sorted(crepos):
if urepo[0] != '@':
continue
print "%s%s" % (ind, " "), urepo + ":", crepos[urepo]
if available:
print ind, "Available:", available
for urepo in sorted(crepos):
if urepo[0] == '@':
continue
print "%s%s" % (ind, " "), urepo + ":", crepos[urepo]
if end:
print end
def main():
parser = OptionParser(version = "Depcheck version %s" % version)
parser.add_option("--releasever", default=None,
help="set value of $releasever in yum config and repo files")
parser.add_option("--show-duplicates", action="store_true",
dest="show_dupes",
help="show all versions of packages")
parser.add_option("--show-dupes", action="store_true",
help=SUPPRESS_HELP)
parser.add_option("--repoid", action="append",
help="specify repoids to query, can be specified multiple times (default is all enabled)")
parser.add_option("--enablerepo", action="append", dest="enablerepos",
help="specify additional repoids to query, can be specified multiple times")
parser.add_option("--disablerepo", action="append", dest="disablerepos",
help="specify repoids to disable, can be specified multiple times")
parser.add_option("--repofrompath", action="append",
help="specify repoid & paths of additional repositories - unique repoid and complete path required, can be specified multiple times. Example. --repofrompath=myrepo,/path/to/repo")
parser.add_option("--old-packages", action="append",
help="packages to use to compare against, instead of installed")
parser.add_option("--ignore-arch", action="store_true",
help="ignore arch when searching for old packages")
parser.add_option("--skip-new", action="store_true",
help="skip packages without a matching old package")
parser.add_option("-C", "--cache", action="store_true",
help="run from cache only")
parser.add_option("-c", "--config", dest="conffile", default=None,
help="config file location")
(opts, args) = parser.parse_args()
yb = yum.YumBase()
yb.preconf.releasever = opts.releasever
if opts.conffile is not None:
yb.preconf.fn = opts.conffile
# setup the fake repos
for repo in opts.repofrompath or []:
tmp = tuple(repo.split(','))
if len(tmp) != 2:
yb.logger.error("Error: Bad repofrompath argument: %s" %repo)
continue
repoid,repopath = tmp
if repopath[0] == '/':
baseurl = 'file://' + repopath
else:
baseurl = repopath
yb.add_enable_repo(repoid, baseurls=[baseurl],
basecachedir=yb.conf.cachedir)
yb.logger.info("Added %s repo from %s" % (repoid, repopath))
if opts.cache:
yb.conf.cache = 1
elif not yb.setCacheDir():
yb.conf.cache = 1
if opts.show_dupes:
yb.conf.showdupesfromrepos = True
if opts.repoid:
found_repos = set()
for repo in yb.repos.findRepos('*'):
if repo.id not in opts.repoid:
repo.disable()
else:
found_repos.add(repo.id)
repo.enable()
for not_found in set(opts.repoid).difference(found_repos):
yb.logger.error('Repoid %s was not found.' % not_found)
if opts.disablerepos:
for repo_match in opts.disablerepos:
for repo in yb.repos.findRepos(repo_match):
repo.disable()
if opts.enablerepos:
for repo_match in opts.enablerepos:
for repo in yb.repos.findRepos(repo_match):
repo.enable()
npkgs = _get_npkgs(yb, args)
opkgs = {}
for pkg in sorted(_get_opkgs(yb, npkgs, opts.old_packages)):
opkgs[(pkg.name, pkg.arch)] = pkg
opkgs[pkg.name] = pkg
for pkg in sorted(npkgs):
opkg = None
oreqs = {}
oobss = {}
ocons = {}
if opts.ignore_arch:
if pkg.name in opkgs:
opkg = opkgs[pkg.name]
elif (pkg.name, pkg.arch) in opkgs:
opkg = opkgs[(pkg.name, pkg.arch)]
if opkg is None and opts.skip_new:
continue
print "New-Package:", pkg, pkg.ui_from_repo
if opkg is not None:
print "Old-Package:", opkg, opkg.ui_from_repo
oreqs = _get_oreqs(pkg, opkg.requires)
ocons = _get_oreqs(pkg, opkg.conflicts)
oobss = _get_oreqs(pkg, opkg.obsoletes)
used_repos_reqs = []
nreqs, creqs = _get_reqs(pkg, pkg.requires, oreqs)
if nreqs:
print "New-Requires:"
_print_reqs(yb, pkg, nreqs, used_repos_reqs)
if creqs:
print "Modified-Requires:"
_print_reqs(yb, pkg, creqs, used_repos_reqs)
_print_sum("Dep-Requires-Repos:", used_repos_reqs)
used_repos_cons = []
nreqs, creqs = _get_reqs(pkg, pkg.conflicts, ocons)
if nreqs:
print "New-Conflicts:"
_print_reqs(yb, pkg, nreqs, used_repos_cons)
if creqs:
print "Mod-Conflicts:"
_print_reqs(yb, pkg, creqs, used_repos_cons)
_print_sum("Dep-Conflicts-Repos:", used_repos_cons)
used_repos_obss = []
nreqs, creqs = _get_reqs(pkg, pkg.obsoletes, oobss)
if nreqs:
print "New-Obsoletes:"
_print_reqs(yb, pkg, nreqs, used_repos_obss)
if creqs:
print "Mod-Obsoletes:"
_print_reqs(yb, pkg, creqs, used_repos_obss)
_print_sum("Dep-Obsoletes-Repos:", used_repos_obss)
_print_sum("Dep-Repos:",
used_repos_reqs + used_repos_cons + used_repos_obss,
end='')
if __name__ == "__main__":
yum.misc.setup_locale()
main()