]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - sort-pkgs
- avoid cycles and infinite recursion
[packages/rpm-build-tools.git] / sort-pkgs
CommitLineData
1859b517
WF
1#!/usr/bin/python
2
3"""
4This script tries to set ordering in which packages ought to be sent to builders.
5Input: file with names of packages (without the .spec suffix). One package name per line.
6Output: sorted packages on stdout.
7
8If the script goes in a infinite loop, that means there is a cycle or other bug.
9"""
10
11import os
12import re
13import sys
14
fdc41000 15PATTERN = re.compile('BuildRequires:\s+(.*?)(\s|$|-devel)')
1859b517
WF
16DIR = '/home/users/builder/rpm/packages'
17
18packages = {}
19packages_res = {}
20
21def build_requires(name):
fdc41000 22 global packages
1859b517
WF
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
33def print_packages(p):
fdc41000 34 global packages, packages_res
86ee5491 35
cbc9b16a 36 packages_res[p] = 1
1859b517 37 for pp in packages[p]:
86ee5491
WF
38 if not packages_res[pp]:
39 print_packages(pp)
1859b517
WF
40 print p#, packages[p]
41
42if __name__ == "__main__":
43 if len(sys.argv) < 2:
44 print "Usage: %s filename" % sys.argv[0]
45 sys.exit(1)
46 with open(sys.argv[1], 'r') as f:
47 for line in f:
48 p = line.rstrip()
49 packages[p] = []
50 packages_res[p] = 0
51 for p in packages.keys():
52 res = build_requires(p)
53 if res:
54 packages[p] = res[:]
55
56# for p in packages.keys():
57# print p, packages[p]
58
59 for p in packages.keys():
60 print_packages(p)
This page took 0.039974 seconds and 4 git commands to generate.