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