]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - sort-pkgs
- do not display entries twice
[packages/rpm-build-tools.git] / sort-pkgs
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:\s+(.*?)(\s|$|-devel)')
16 DIR = '/home/users/builder/rpm/packages'
17
18 packages = {}
19 packages_res = {}
20
21 def build_requires(name):
22         global packages
23         res = []
24         with open(os.path.join(DIR, name, name + '.spec'), 'r') as f:
25                 for line in f:
26                         br = PATTERN.match(line)
27                         if br:
28                                 p = br.group(1)
29                                 if p in packages:
30                                         res.append(p)
31         return res
32
33 def print_packages(p):
34         global packages, packages_res
35
36         if not packages_res[p]:
37                 packages_res[p] = 1
38                 for pp in packages[p]:
39                         if not packages_res[pp]:
40                                 print_packages(pp)
41                 print p
42
43 if __name__ == "__main__":
44         if len(sys.argv) < 2:
45                 print "Usage: %s filename" % sys.argv[0]
46                 sys.exit(1)
47         with open(sys.argv[1], 'r') as f:
48                 for line in f:
49                         p = line.rstrip()
50                         packages[p] = []
51                         packages_res[p] = 0
52         for p in packages.keys():
53                 res = build_requires(p)
54                 if res:
55                         packages[p] = res[:]
56
57 #       for p in packages.keys():
58 #               print p, packages[p]
59
60         for p in packages.keys():
61                 print_packages(p)
This page took 0.621952 seconds and 4 git commands to generate.