]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - sort-pkgs
unset GIT_EDITOR together with other GIT_* vars
[packages/rpm-build-tools.git] / sort-pkgs
CommitLineData
94e9b4e3 1#!/usr/bin/python3
1859b517
WF
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
94e9b4e3
WF
15BR_PATTERN = re.compile('BuildRequires:\s+(.*?)(\s|$)')
16PACKAGE_PATTERN_WITH_N = re.compile('%package\s+-n\s+(.*)')
17PACKAGE_PATTERN = re.compile('%package\s+(.*)')
18
19DIR = os.getenv("HOME") + '/rpm/packages'
20
21BUILD_REQUIRES = {}
22PACKAGES = {}
23SPECS = {}
24VISITED = {}
25
26
27def parse_spec(name):
28 global PACKAGES, SPECS, BUILD_REQUIRES, VISITED
29 res = []
30 try:
31 with open(os.path.join(DIR, name, name + '.spec'), 'r') as f:
32 for line in f:
33 br = BR_PATTERN.match(line)
34 if br:
35 p = br.group(1)
36 res.append(p)
37 if line.startswith('%package'):
38 pn = PACKAGE_PATTERN_WITH_N.match(line)
39 if pn:
40 package = pn.group(1)
41 PACKAGES[package] = name
42 else:
43 pn = PACKAGE_PATTERN.match(line)
44 if pn:
45 ext = pn.group(1)
46 if ext:
47 package = name + '-' + ext
48 PACKAGES[package] = name
49 BUILD_REQUIRES[name] = res[:]
50 PACKAGES[name] = name
51 SPECS[name] = True
52 VISITED[name] = False
53 except:
54 pass
55
56
57def print_spec(spec):
58 global PACKAGES, SPECS, BUILD_REQUIRES, VISITED
59
60 if not VISITED[spec]:
61 VISITED[spec] = True
62 for br in BUILD_REQUIRES[spec]:
63 name = PACKAGES.get(br, '')
64 if name in SPECS:
65 if not VISITED[name]:
66 print_spec(name)
67 print(spec)
68
1859b517
WF
69
70if __name__ == "__main__":
94e9b4e3
WF
71 if len(sys.argv) < 2:
72 print("Usage: %s filename" % sys.argv[0])
73 sys.exit(1)
74 with open(sys.argv[1], 'r') as f:
75 for line in f:
76 spec = line.rstrip()
77 parse_spec(spec)
78
79 for spec in SPECS:
80 print_spec(spec)
This page took 0.05306 seconds and 4 git commands to generate.