4 This script tries to set ordering in which packages ought to be sent to builders.
5 Input: file with names of packages. If not given packages are read from stdin. One package name per line.
6 Output: sorted packages on stdout.
8 If the script goes in a infinite loop, that means there is a cycle or other bug.
15 BR_PATTERN = re.compile('BuildRequires:\s+(.*?)(\s|$)')
16 PACKAGE_PATTERN_WITH_N = re.compile('%package\s+-n\s+(.*)')
17 PACKAGE_PATTERN = re.compile('%package\s+(.*)')
21 DIR = rpm.expandMacro('%_topdir')
22 except ModuleNotFoundError:
25 DIR = subprocess.check_output(['rpm', '-E', '%_topdir']).decode('utf-8').strip()
27 DIR = os.getenv("HOME") + '/rpm/packages'
36 global PACKAGES, SPECS, BUILD_REQUIRES, VISITED
39 with open(os.path.join(DIR, name, name + '.spec'), 'r') as f:
41 br = BR_PATTERN.match(line)
45 if line.startswith('%package'):
46 pn = PACKAGE_PATTERN_WITH_N.match(line)
49 PACKAGES[package] = name
51 pn = PACKAGE_PATTERN.match(line)
55 package = name + '-' + ext
56 PACKAGES[package] = name
57 BUILD_REQUIRES[name] = res[:]
66 global PACKAGES, SPECS, BUILD_REQUIRES, VISITED
70 for br in BUILD_REQUIRES[spec]:
71 name = PACKAGES.get(br, '')
78 if __name__ == "__main__":
79 with (len(sys.argv) > 1 and open(sys.argv[1], 'r') or sys.stdin) as f:
81 spec = os.path.basename(os.path.normpath(line.rstrip())).removesuffix('.spec')