-
Notifications
You must be signed in to change notification settings - Fork 4
/
whatpkgs.py
executable file
·805 lines (659 loc) · 29.1 KB
/
whatpkgs.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
#!/usr/bin/python3
"""
Tool for interacting with python3-dnf to get complicated dependency
information from yum/dnf repodata.
"""
import os
import platform
import sys
import pprint
import dnf
import click
from colorama import Fore, Back, Style
multi_arch = None
primary_arch = platform.machine()
if primary_arch == "x86_64":
multi_arch = "i686"
def splitFilename(filename):
"""
Pass in a standard style rpm fullname
Return a name, version, release, epoch, arch, e.g.::
foo-1.0-1.i386.rpm returns foo, 1.0, 1, i386
1:bar-9-123a.ia64.rpm returns bar, 9, 123a, 1, ia64
Copied from rpmUtils.miscUtils in yum
"""
if filename[-4:] == '.rpm':
filename = filename[:-4]
archIndex = filename.rfind('.')
arch = filename[archIndex+1:]
relIndex = filename[:archIndex].rfind('-')
rel = filename[relIndex+1:archIndex]
verIndex = filename[:relIndex].rfind('-')
ver = filename[verIndex+1:relIndex]
epochIndex = filename.find(':')
if epochIndex == -1:
epoch = ''
else:
epoch = filename[:epochIndex]
name = filename[epochIndex + 1:verIndex]
return name, ver, rel, epoch, arch
class NoSuchPackageException(Exception):
"""
Exception class for requested packages that do not exist
"""
def __init__(self, pkgname):
Exception.__init__(self,
"Package name %s returned no packages" % pkgname)
class TooManyPackagesException(Exception):
"""
Exception class for packages that appear multiple times in the repos
"""
def __init__(self, pkgname):
Exception.__init__(self,
"Too many packages returned for %s" % pkgname)
def _setup_static_repo(base, reponame, path):
repo = dnf.repo.Repo(reponame, base.conf)
repo.mirrorlist = None
repo.metalink = None
repo.baseurl = "file://" + path
repo.name = reponame
try:
repo._id = reponame
except AttributeError:
print("DNF 2.x required.", file=sys.stderr)
sys.exit(1)
base.repos.add(repo)
repo.load()
repo.enable()
repo._md_expire_cache()
def setup_repo(use_system, use_rhel, version="25"):
"""
Enable only the official Fedora repositories
Returns: dnf.Base containing all the package metadata from the standard
repositories for binary RPMs
"""
base = dnf.Base()
if use_system:
base.read_all_repos()
repo = base.repos.all()
repo.disable()
repo = base.repos.get_matching("fedora")
repo.enable()
repo = base.repos.get_matching("updates")
repo.enable()
repo = base.repos.get_matching("fedora-source")
repo.enable()
repo = base.repos.get_matching("updates-source")
repo.enable()
elif use_rhel:
# Load the static data for RHEL
dir_path = os.path.dirname(os.path.realpath(__file__))
repo_path = os.path.join(dir_path,
"sampledata/repodata/RHEL-7/7.3-Beta/Server/%s/os/" % primary_arch)
_setup_static_repo(base, "static-rhel7.3beta-binary", repo_path)
repo_path = os.path.join(dir_path,
"sampledata/repodata/RHEL-7/7.3-Beta/Server-optional/%s/os/" %
primary_arch)
_setup_static_repo(base,
"static-rhel7.3beta-optional-binary",
repo_path)
repo_path = os.path.join(dir_path,
"sampledata/repodata/RHEL-7/7.3-Beta/Server/source/tree/")
_setup_static_repo(base, "static-rhel7.3beta-source", repo_path)
repo_path = os.path.join(dir_path,
"sampledata/repodata/RHEL-7/7.3-Beta/Server-optional/source/tree/")
_setup_static_repo(base,
"static-rhel7.3beta-optional-source",
repo_path)
else:
# Load the static data for Fedora
dir_path = os.path.dirname(os.path.realpath(__file__))
repo_path = os.path.join(dir_path,
"sampledata/repodata/fedora/linux/development/%s/Everything/%s/"
"/os" % (version, primary_arch))
_setup_static_repo(base, "static-f%s-beta-binary" % version, repo_path)
repo_path = os.path.join(dir_path,
"sampledata/repodata/fedora/linux/development/%s/Everything/source"
"/tree/" % version)
_setup_static_repo(base, "static-f%s-beta-source" % version, repo_path)
# Add override repositories for modularity
repo_path = os.path.join(dir_path,
"sampledata/repodata/fedora/linux/development/%s/gencore-override"
"/%s/os" % (version, primary_arch))
_setup_static_repo(base,
"static-gencore-override-f%s-binary" % version,
repo_path)
repo_path = os.path.join(dir_path,
"sampledata/repodata/fedora/linux/development/%s/gencore-override"
"/source/tree/" % version)
_setup_static_repo(base, "static-gencore-override-source", repo_path)
base.fill_sack(load_system_repo=False, load_available_repos=True)
return base
def get_query_object(use_system, use_rhel, version):
"""
Get query objects for binary packages and source packages
Returns: query object for source and binaries
"""
base = setup_repo(use_system, use_rhel, version)
return base.sack.query()
def get_pkg_by_name(q, pkgname, arch=None):
"""
Try to find the package name as primary_arch, multi_arch and then noarch.
This function will return exactly one result. If it finds zero or multiple
packages that match the name, it will throw an error.
"""
# If we were requested to search for a specific architecture
if arch:
matched = q.filter(name=pkgname, latest=True, arch=arch)
if len(matched) > 1:
raise TooManyPackagesException(pkgname)
if len(matched) == 1:
# Exactly one package matched.
return matched[0]
raise NoSuchPackageException(pkgname)
# Otherwise, check the primary arch, multi-arch and noarch packages
matched = q.filter(name=pkgname, latest=True, arch=primary_arch)
if len(matched) > 1:
raise TooManyPackagesException(pkgname)
if len(matched) == 1:
# Exactly one package matched. We'll prioritize the archful package if
# the same package would satisfy a multi-arch version as well.
# Technically it's possible for there to also be a noarch package
# with the same name, which is an edge case I'm not optimizing for
# yet.
return matched[0]
if multi_arch:
matched = q.filter(name=pkgname, latest=True, arch=multi_arch)
if len(matched) > 1:
raise TooManyPackagesException(pkgname)
if len(matched) == 1:
# Exactly one package matched
# Technically it's possible for there to also be a noarch package
# with the same name, which is an edge case I'm not optimizing for
# yet.
return matched[0]
matched = q.filter(name=pkgname, latest=True, arch='noarch')
if len(matched) > 1:
raise TooManyPackagesException(pkgname)
if len(matched) == 1:
# Exactly one package matched
return matched[0]
raise NoSuchPackageException(pkgname)
def get_srpm_for_package(query, pkg):
# Get just the base name of the SRPM
try:
(sourcename, _, _, _, _) = splitFilename(pkg.sourcerpm)
except Exception:
print("Failure: %s(%s)" % (pkg.sourcerpm, pkg.name))
raise
matched = query.filter(name=sourcename, latest=True, arch='src')
if len(matched) > 1:
raise TooManyPackagesException(pkg.name)
if len(matched) == 1:
# Exactly one package matched
return matched[0]
raise NoSuchPackageException(pkg.name)
def get_srpm_for_package_name(query, pkgname):
"""
For a given package, retrieve a reference to its source RPM
"""
pkg = get_pkg_by_name(query, pkgname)
return get_srpm_for_package(query, pkg)
def append_requirement(reqs, parent, pkg, filters, whatreqs):
"""
Check if this package is in the filter list. If it is, then
do not add it to the list of packages to recurse into.
"""
if whatreqs is not None and pkg.name in whatreqs:
print("%s is pulled in by %s" % (pkg.name, parent.name),
file=sys.stderr)
if filters is None or pkg.name not in filters:
reqs.append(pkg)
def get_requirements(parent, reqs, dependencies, ambiguities,
query, hints, filters, whatreqs, pick_first):
"""
Share code for recursing into requires or recommends
"""
requirements = []
for require in reqs:
required_packages = query.filter(provides=require, latest=True,
arch=primary_arch)
# Check for multi-arch packages satisfying it
if len(required_packages) == 0 and multi_arch:
required_packages = query.filter(provides=require, latest=True,
arch=multi_arch)
# Check for noarch packages satisfying it
if len(required_packages) == 0:
required_packages = query.filter(provides=require, latest=True,
arch='noarch')
# If there are no dependencies, just return
if len(required_packages) == 0:
print("No package for [%s] required by [%s-%s-%s.%s]" % (
str(require),
parent.name, parent.version,
parent.release, parent.arch),
file=sys.stderr)
continue
# Check for multiple possible packages
if len(required_packages) > 1:
# Handle 'hints' list
found = False
for choice in hints:
for rpkg in required_packages:
if rpkg.name == choice:
# This has been disambiguated; use this one
found = True
append_requirement(requirements, parent, rpkg,
filters, whatreqs)
break
if found:
# Don't keep looking once we find a match
break
if not found:
if pick_first:
# First try to use something we've already discovered
for rpkg in required_packages:
if rpkg.name in dependencies:
return
# The user instructed processing to just take the first
# entry in the list.
for rpkg in required_packages:
if rpkg.arch == 'noarch' or rpkg.arch == \
primary_arch or rpkg.arch == multi_arch:
append_requirement(requirements, parent, rpkg,
filters, whatreqs)
break
continue
# Packages not solved by 'hints' list
# should be added to the ambiguities list
unresolved = {}
for rpkg in required_packages:
unresolved["%s#%s" % (rpkg.name, rpkg.arch)] = rpkg
ambiguities.append(unresolved)
continue
# Exactly one package matched, so proceed down into it.
append_requirement(requirements, parent, required_packages[0],
filters, whatreqs)
return requirements
def recurse_package_deps(pkg, dependencies, ambiguities,
query, hints, filters, whatreqs,
pick_first, follow_recommends):
"""
Recursively search through dependencies and add them to the list
"""
depname = "%s#%s" % (pkg.name, pkg.arch)
if depname in dependencies:
# Don't recurse the same dependency twice
return
dependencies[depname] = pkg
# Process Requires:
deps = get_requirements(pkg, pkg.requires, dependencies,
ambiguities, query, hints,
filters, whatreqs,
pick_first)
try:
# Process Requires(pre|post)
prereqs = get_requirements(pkg, pkg.requires_pre, dependencies,
ambiguities, query, hints,
filters, whatreqs,
pick_first)
deps.extend(prereqs)
except AttributeError:
print("DNF 2.x required.", file=sys.stderr)
sys.exit(1)
if follow_recommends:
recommends = get_requirements(pkg, pkg.recommends, dependencies,
ambiguities, query, hints,
filters, whatreqs,
pick_first)
deps.extend(recommends)
for dep in deps:
recurse_package_deps(dep, dependencies, ambiguities, query,
hints, filters, whatreqs,
pick_first, follow_recommends)
def recurse_self_host(binary_pkg, binaries, sources,
ambiguities, query, hints,
filters, whatreqs,
pick_first, follow_recommends):
"""
Recursively determine all build dependencies for this package
"""
depname = "%s#%s" % (binary_pkg.name, binary_pkg.arch)
if depname in binaries:
# Don't process the same binary RPM twice
return
binaries[depname] = binary_pkg
# Process strict Requires:
deps = get_requirements(binary_pkg, binary_pkg.requires, binaries,
ambiguities, query, hints,
filters, whatreqs, pick_first)
# Process Requires(pre|post):
prereqs = get_requirements(binary_pkg, binary_pkg.requires_pre,
binaries, ambiguities, query, hints,
filters, whatreqs, pick_first)
deps.extend(prereqs)
if follow_recommends:
# Process Recommends:
recommends = get_requirements(binary_pkg, binary_pkg.recommends,
binaries, ambiguities, query, hints,
filters, whatreqs, pick_first)
deps.extend(recommends)
# Now get the build dependencies for this package
source_pkg = get_srpm_for_package(query, binary_pkg)
if source_pkg.name not in sources:
# Don't process the same Source RPM twice
sources[source_pkg.name] = source_pkg
# Get the BuildRequires for this Source RPM
buildreqs = get_requirements(source_pkg, source_pkg.requires,
binaries, ambiguities, query, hints,
filters, whatreqs, pick_first)
deps.extend(buildreqs)
for dep in deps:
recurse_self_host(dep, binaries, sources, ambiguities, query, hints,
filters, whatreqs, pick_first, follow_recommends)
def print_package_name(pkgname, dependencies, full):
"""
Parse the package name for the error state and
print it with the correct verbosity.
"""
printpkg = dependencies[pkgname]
if full:
print("%d:%s-%s-%s.%s" % (printpkg.epoch,
printpkg.name,
printpkg.version,
printpkg.release,
printpkg.arch))
else:
if printpkg.arch == multi_arch:
print("%s#%s" % (printpkg.name, printpkg.arch))
else:
print("%s" % printpkg.name)
def resolve_ambiguity(dependencies, ambiguity):
"""
Determine if any of the contents of an ambiguous lookup
is already resolved by something in the dependencies.
"""
for key in sorted(ambiguity, key=ambiguity.get):
if key in dependencies:
return True
return False
def _split_pkgname(name):
splitname = name.rsplit("#", 2)
pkgname = splitname[0]
arch = None
if len(splitname) > 1:
arch = splitname[1]
return (pkgname, arch)
@click.group()
def main():
pass
@main.command(short_help="Get package dependencies")
@click.argument('pkgnames', nargs=-1)
@click.option('--hint', multiple=True,
help="""
Specify a package to be selected when more than one package could satisfy a
dependency. This option may be specified multiple times.
For example, it is recommended to use --hint=glibc-minimal-langpack
""")
@click.option('--filter', multiple=True,
help="""
Specify a package to be skipped during processing. This option may be
specified multiple times.
This is useful when some packages are provided by a lower-level module
already contains the package and its dependencies.
""")
@click.option('--whatreqs', multiple=True,
help="""
Specify a package that you want to identify what pulls it into the complete
set. This option may be specified multiple times.
""")
@click.option('--recommends/--no-recommends', default=True)
@click.option('--merge/--no-merge', default=False)
@click.option('--full-name/--no-full-name', default=False)
@click.option('--pick-first/--no-pick-first', default=False,
help="""
If multiple packages could satisfy a dependency and no --hint package will
fulfill the requirement, automatically select one from the list.
Note: this result may differ between runs depending upon how the list is
sorted. It is recommended to use --hint instead, where practical.
""")
@click.option('--system/--no-system', default=False,
help="If --system is specified, use the 'fedora', 'updates', "
"'source' and 'updates-source' repositories from the local "
"system configuration. Otherwise, use the static data from "
"the sampledata directory.")
@click.option('--rhel/--no-rhel', default=False,
help="If --system is not specified, the use of --rhel will "
"give back results from the RHEL sample data. Otherwise, "
"Fedora sample data will be used.")
@click.option('--version', default="25",
help="Specify the version of the OS sampledata to compare "
"against.")
def neededby(pkgnames, hint, filter, whatreqs, recommends, merge, full_name,
pick_first, system, rhel, version):
"""
Look up the dependencies for each specified package and
display them in a human-parseable format.
"""
query = get_query_object(system, rhel, version)
dependencies = {}
ambiguities = []
for fullpkgname in pkgnames:
(pkgname, arch) = _split_pkgname(fullpkgname)
if pkgname in filter:
# Skip this if we explicitly filtered it out
continue
pkg = get_pkg_by_name(query, pkgname, arch)
if not merge:
# empty the dependencies list and start over
dependencies = {}
ambiguities = []
recurse_package_deps(pkg, dependencies, ambiguities, query, hint,
filter, whatreqs, pick_first, recommends)
# Check for unresolved deps in the list that are present in the
# dependencies. This happens when one package has an ambiguous dep but
# another package has an explicit dep on the same package.
# This list comprehension just returns the set of dictionaries that
# are not resolved by other entries
ambiguities = [x for x in ambiguities
if not resolve_ambiguity(dependencies, x)]
if not merge:
# If we're printing individually, create a header
print(Fore.GREEN + Back.BLACK + "=== %s.%s ===" % (
pkg.name, pkg.arch) + Style.RESET_ALL)
# Print just this package's dependencies
for key in sorted(dependencies, key=dependencies.get):
# Skip the initial package
if key == pkgname:
continue
print_package_name(key, dependencies, full_name)
if len(ambiguities) > 0:
print(Fore.RED + Back.BLACK + "=== Unresolved Requirements ===" +
Style.RESET_ALL)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(ambiguities)
if merge:
# Print the complete set of dependencies together
for key in sorted(dependencies, key=dependencies.get):
print_package_name(key, dependencies, full_name)
if len(ambiguities) > 0:
print(Fore.RED + Back.BLACK + "=== Unresolved Requirements ===" +
Style.RESET_ALL)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(ambiguities)
@main.command(short_help="Get Source RPM")
@click.argument('pkgnames', nargs=-1)
@click.option('--full-name/--no-full-name', default=False)
@click.option('--system/--no-system', default=False,
help="If --system is specified, use the 'fedora', 'updates', "
"'source' and 'updates-source' repositories from the local "
"system configuration. Otherwise, use the static data from "
"the sampledata directory.")
@click.option('--rhel/--no-rhel', default=False,
help="If --system is not specified, the use of --rhel will "
"give back results from the RHEL sample data. Otherwise, "
"Fedora sample data will be used.")
@click.option('--version', default="25",
help="Specify the version of the OS sampledata to compare "
"against.")
def getsourcerpm(pkgnames, full_name, system, rhel, version):
"""
Look up the SRPMs from which these binary RPMs were generated.
This list will be displayed deduplicated and sorted.
"""
query = get_query_object(system, rhel, version)
srpm_names = {}
for fullpkgname in pkgnames:
(pkgname, arch) = _split_pkgname(fullpkgname)
pkg = get_srpm_for_package_name(query, pkgname)
srpm_names[pkg.name] = pkg
for key in sorted(srpm_names, key=srpm_names.get):
print_package_name(key, srpm_names, full_name)
@main.command(short_help="Get build dependencies")
@click.argument('pkgnames', nargs=-1)
@click.option('--hint', multiple=True,
help="""
Specify a package to be selected when more than one package could satisfy a
dependency. This option may be specified multiple times.
For example, it is recommended to use --hint=glibc-minimal-langpack
For build dependencies, the default is to exclude Recommends: from the
dependencies of the BuildRequires.
""")
@click.option('--recommends/--no-recommends', default=False)
@click.option('--merge/--no-merge', default=False)
@click.option('--full-name/--no-full-name', default=False)
@click.option('--sources/--no-sources', default=True)
@click.option('--pick-first/--no-pick-first', default=False,
help="""
If multiple packages could satisfy a dependency and no --hint package will
fulfill the requirement, automatically select one from the list.
Note: this result may differ between runs depending upon how the list is
sorted. It is recommended to use --hint instead, where practical.
""")
@click.option('--filter', multiple=True,
help="""
Specify a package to be skipped during processing. This option may be
specified multiple times.
This is useful when some packages are provided by a lower-level module
already contains the package and its dependencies.
""")
@click.option('--whatreqs', multiple=True,
help="""
Specify a package that you want to identify what pulls it into the complete
set. This option may be specified multiple times.
""")
@click.option('--system/--no-system', default=False,
help="If --system is specified, use the 'fedora', 'updates', "
"'source' and 'updates-source' repositories from the local "
"system configuration. Otherwise, use the static data from "
"the sampledata directory.")
@click.option('--rhel/--no-rhel', default=False,
help="If --system is not specified, the use of --rhel will "
"give back results from the RHEL sample data. Otherwise, "
"Fedora sample data will be used.")
@click.option('--version', default="25",
help="Specify the version of the OS sampledata to compare "
"against.")
def neededtoselfhost(pkgnames, hint, recommends, merge, full_name,
pick_first, filter, whatreqs,
sources, system, rhel, version):
"""
Look up the build dependencies for each specified package
and all of their dependencies, recursively and display them
in a human-parseable format.
"""
query = get_query_object(system, rhel, version)
binary_pkgs = {}
source_pkgs = {}
ambiguities = []
for fullpkgname in pkgnames:
(pkgname, arch) = _split_pkgname(fullpkgname)
if pkgname in filter:
# Skip this if we explicitly filtered it out
continue
pkg = get_pkg_by_name(query, pkgname, arch)
if not merge:
binary_pkgs = {}
source_pkgs = {}
ambiguities = []
recurse_self_host(pkg, binary_pkgs, source_pkgs,
ambiguities, query, hint, filter,
whatreqs, pick_first, recommends)
# Check for unresolved deps in the list that are present in the
# dependencies. This happens when one package has an ambiguous dep but
# another package has an explicit dep on the same package.
# This list comprehension just returns the set of dictionaries that
# are not resolved by other entries
# We only search the binary packages here. This is a reduction; no
# additional packages are discovered so we don't need to regenrate
# the source RPM list.
ambiguities = [x for x in ambiguities
if not resolve_ambiguity(binary_pkgs, x)]
if not merge:
# If we're printing individually, create a header
print(Fore.GREEN + Back.BLACK + "=== %s.%s ===" % (
pkg.name, pkg.arch) + Style.RESET_ALL)
# Print just this package's dependencies
if sources:
for key in sorted(source_pkgs, key=source_pkgs.get):
# Skip the initial package
if key == pkgname:
continue
print_package_name(key, source_pkgs, full_name)
else:
for key in sorted(binary_pkgs, key=binary_pkgs.get):
# Skip the initial package
if key == pkgname:
continue
print_package_name(key, binary_pkgs, full_name)
if len(ambiguities) > 0:
print(Fore.RED + Back.BLACK +
"=== Unresolved Requirements ===" +
Style.RESET_ALL)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(ambiguities)
if merge:
if sources:
for key in sorted(source_pkgs, key=source_pkgs.get):
print_package_name(key, source_pkgs, full_name)
else:
for key in sorted(binary_pkgs, key=binary_pkgs.get):
print_package_name(key, binary_pkgs, full_name)
if len(ambiguities) > 0:
print(Fore.RED + Back.BLACK +
"=== Unresolved Requirements ===" +
Style.RESET_ALL)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(ambiguities)
@main.command(short_help="Debug missing Provides")
@click.argument('requires', nargs=1)
@click.option('--system/--no-system', default=False,
help="If --system is specified, use the 'fedora', 'updates', "
"'source' and 'updates-source' repositories from the local "
"system configuration. Otherwise, use the static data from "
"the sampledata directory.")
@click.option('--rhel/--no-rhel', default=False,
help="If --system is not specified, the use of --rhel will "
"give back results from the RHEL sample data. Otherwise, "
"Fedora sample data will be used.")
@click.option('--version', default="25",
help="Specify the version of the OS sampledata to compare "
"against.")
def debugprovides(requires, system, rhel, version):
query = get_query_object(system, rhel, version)
required_packages = query.filter(provides=requires, latest=True,
arch=primary_arch)
if len(required_packages) == 0 and multi_arch:
required_packages = query.filter(provides=requires, latest=True,
arch=multi_arch)
if len(required_packages) == 0:
required_packages = query.filter(provides=requires, latest=True,
arch='noarch')
# If there are no dependencies, just return
if len(required_packages) == 0:
print("No package for [%s]" % (str(requires)), file=sys.stderr)
sys.exit(1)
for pkg in required_packages:
print(repr(pkg))
if __name__ == "__main__":
main()