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