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="keep 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="keep arm32 multilib packages in the control file")
17 (options, args) = parser.parse_args()
18
19 if len(args) > 2 or len(args) < 2:
20 parser.error("takes 2 arguments (control file and exclude list)")
21 (control_file, exclude_list) = args
22
23 with open(exclude_list, 'r') as f:
24 excludes = set([s.strip() for s in f.readlines()])
25
26 sys.stderr.write("%d packages in the exclude list\n" % len(excludes))
27 skip = False
28 excluded = 0
29 with open(control_file, 'r') as f:
30 for line in f:
31 if line.startswith('Package:'):
32 pkg = line.split()[-1].strip()
33 if pkg in excludes:
34 skip = True
35 if options.skip_dbg_packages and '-dbg' in pkg:
36 skip = True
37 if options.skip_arm32ml_packages:
38 if 'libhf' in pkg or 'libsf' in pkg or 'multilib-arm' in pkg:
39 skip = True
40 if skip:
41 excluded += 1
42 if skip and line == '\n':
43 skip = False
44 continue
45 if not skip:
46 sys.stdout.write(line)
47 sys.stderr.write("%d packages excluded from the control file\n" % excluded)
48
49 if __name__ == '__main__':
50 main()