]>
Commit | Line | Data |
---|---|---|
1859b517 WF |
1 | #!/usr/bin/python |
2 | ||
3 | """ | |
4 | This script tries to set ordering in which packages ought to be sent to builders. | |
5 | Input: file with names of packages (without the .spec suffix). One package name per line. | |
6 | Output: sorted packages on stdout. | |
7 | ||
8 | If the script goes in a infinite loop, that means there is a cycle or other bug. | |
9 | """ | |
10 | ||
11 | import os | |
12 | import re | |
13 | import sys | |
14 | ||
15 | PATTERN = re.compile('BuildRequires:\t(.*)-devel') | |
16 | DIR = '/home/users/builder/rpm/packages' | |
17 | ||
18 | packages = {} | |
19 | packages_res = {} | |
20 | ||
21 | def build_requires(name): | |
22 | res = [] | |
23 | with open(os.path.join(DIR, name, name + '.spec'), 'r') as f: | |
24 | for line in f: | |
25 | br = PATTERN.match(line) | |
26 | if br: | |
27 | p = br.group(1) | |
28 | if p in packages: | |
29 | res.append(p) | |
30 | return res | |
31 | ||
32 | def print_packages(p): | |
33 | if packages_res[p] == 1: | |
34 | return | |
35 | for pp in packages[p]: | |
36 | print_packages(pp) | |
37 | packages_res[p] = 1 | |
38 | print p#, packages[p] | |
39 | ||
40 | if __name__ == "__main__": | |
41 | if len(sys.argv) < 2: | |
42 | print "Usage: %s filename" % sys.argv[0] | |
43 | sys.exit(1) | |
44 | with open(sys.argv[1], 'r') as f: | |
45 | for line in f: | |
46 | p = line.rstrip() | |
47 | packages[p] = [] | |
48 | packages_res[p] = 0 | |
49 | for p in packages.keys(): | |
50 | res = build_requires(p) | |
51 | if res: | |
52 | packages[p] = res[:] | |
53 | ||
54 | # for p in packages.keys(): | |
55 | # print p, packages[p] | |
56 | ||
57 | for p in packages.keys(): | |
58 | print_packages(p) |