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-common-packages", dest="skip_common_packages",
12 action="store_true", default=False,
13 help="skip packages built by the next GCC in the control file")
14 (options, args) = parser.parse_args()
15
16 if len(args) > 2 or len(args) < 2:
17 parser.error("takes 2 arguments (<control file> <common list>)")
18 (control_file, common_list) = args
19
20 with open(common_list, 'r') as f:
21 commons = set([s.strip() for s in f.readlines()])
22
23 sys.stderr.write("%d packages in the common list\n" % len(commons))
24 skip = False
25 excluded = 0
26 with open(control_file, 'r') as f:
27 for line in f:
28 if line.startswith('Package:'):
29 pkg = line.split()[-1].strip()
30 if options.skip_common_packages and pkg in commons:
31 skip = True
32 if skip:
33 excluded += 1
34 if skip and line == '\n':
35 skip = False
36 continue
37 if not skip:
38 sys.stdout.write(line)
39 sys.stderr.write("%d packages excluded from the control file\n" % excluded)
40
41 if __name__ == '__main__':
42 main()