Debian Codegraph @

debian/remove-unbuilt

raw
1 #! /usr/bin/python3
2
3 import optparse
4 import sys
5
6 def main():
7 usage = """usage: %prog [OPTIONS] <control file> <exclude list>
8 strip not-built packages from the control file.
9 """
10 parser = optparse.OptionParser(usage)
11 parser.add_option("--skip-dbg-packages", dest="skip_dbg_packages",
12 action="store_true", default=False,
13 help="skip debug packages in the control file")
14 parser.add_option("--skip-arm32ml-packages", dest="skip_arm32ml_packages",
15 action="store_true", default=False,
16 help="skip arm32 multilib packages in the control file")
17 parser.add_option("--skip-common-packages", dest="skip_common_packages",
18 action="store_true", default=False,
19 help="skip packages built by the next GCC in the control file")
20 (options, args) = parser.parse_args()
21
22 if len(args) > 4 or len(args) < 4:
23 parser.error("takes 4 arguments (<control file> <invalid list> <arm32ml list> <common list>)")
24 (control_file, exclude_list, arm32ml_list, common_list) = args
25
26 with open(exclude_list, 'r') as f:
27 excludes = set([s.strip() for s in f.readlines()])
28 with open(arm32ml_list, 'r') as f:
29 arm32mls = set([s.strip() for s in f.readlines()])
30 with open(common_list, 'r') as f:
31 commons = set([s.strip() for s in f.readlines()])
32 if options.skip_common_packages:
33 arm32mls = arm32mls.difference(commons)
34 if options.skip_arm32ml_packages:
35 commons = commons.difference(arm32mls)
36
37 sys.stderr.write("%d packages in the exclude list\n" % len(excludes))
38 skip = False
39 excluded = 0
40 with open(control_file, 'r') as f:
41 for line in f:
42 if line.startswith('Package:'):
43 pkg = line.split()[-1].strip()
44 if pkg in excludes:
45 skip = True
46 if options.skip_dbg_packages and '-dbg' in pkg:
47 skip = True
48 if options.skip_arm32ml_packages and pkg in arm32mls:
49 skip = True
50 if options.skip_common_packages and pkg in commons:
51 skip = True
52 if skip:
53 excluded += 1
54 if skip and line == '\n':
55 skip = False
56 continue
57 if not skip:
58 sys.stdout.write(line)
59 sys.stderr.write("%d packages excluded from the control file\n" % excluded)
60
61 if __name__ == '__main__':
62 main()