-
Notifications
You must be signed in to change notification settings - Fork 4
/
whatpkgs-parallel.py
executable file
·132 lines (105 loc) · 4.18 KB
/
whatpkgs-parallel.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
#!/usr/bin/python3
"""
Tool for interacting with python3-dnf to get complicated dependency
information from yum/dnf repodata.
"""
import os
import queue
import threading
import whatpkgs
import click
import time
NUM_PROCS=os.sysconf("SC_NPROCESSORS_ONLN")
def print_package_name(filehandle, pkgname, dependencies, full):
"""
Parse the package name for the error state and
print it with the correct verbosity.
"""
printpkg = dependencies[pkgname]
if full:
filehandle.write("%d:%s-%s-%s.%s\n" % (printpkg.epoch,
printpkg.name,
printpkg.version,
printpkg.release,
printpkg.arch))
else:
filehandle.write("%s\n" % printpkg.name)
@click.group()
def main():
pass
@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('--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('--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('--path', default="./%s" % time.asctime())
def neededtoselfhost(pkgnames, hint, recommends, full_name,
pick_first, sources, system, rhel, path):
def selfhost_worker():
while True:
item = q.get()
if item is None:
break
binary_pkgs = {}
source_pkgs = {}
ambiguities = []
pkg = whatpkgs.get_pkg_by_name(query, item["pkg_name"])
whatpkgs.recurse_self_host(pkg, binary_pkgs, source_pkgs,
ambiguities, query, hint,
pick_first, recommends)
f = open(item["output_file"], 'w')
if sources:
for key in sorted(source_pkgs, key=source_pkgs.get):
# Skip the initial package
if key == item["pkg_name"]:
continue
print_package_name(f, key, source_pkgs, full_name)
else:
for key in sorted(binary_pkgs, key=binary_pkgs.get):
print_package_name(f, key, binary_pkgs, full_name)
q.task_done()
os.mkdir(path)
query = whatpkgs.get_query_object(system, rhel)
q = queue.Queue()
threads = []
for i in range(NUM_PROCS):
t = threading.Thread(target=selfhost_worker)
t.start()
threads.append(t)
for pkgname in pkgnames:
output_file = os.path.join(path, pkgname)
temp = {"pkg_name": pkgname,
"output_file": output_file}
q.put(temp)
q.join()
# stop workers
for i in range(NUM_PROCS):
q.put(None)
for t in threads:
t.join()
if __name__ == "__main__":
main()