1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#!/usr/bin/python3
# -*- mode: python; coding: utf-8 -*-
# Copyright © 2002 Colin Walters <walters@gnu.org>
import sys, re, os, string, getopt
try:
opts, args = getopt.getopt(sys.argv[1:], 'd', ['debug'])
except getopt.GetoptError as e:
sys.stderr.write("Error reading arguments: %s\n" % e)
sys.exit(1)
debug = 0
for (key, val) in opts:
if key in ('-d', '--debug'):
debug = 1
target_arch = args[0]
begin_header = 'BEGIN LIST OF PACKAGES\n'
end_header = 'END LIST OF PACKAGES\n'
comment_re = re.compile("^\s+")
depends_re = re.compile('([-a-z0-9+.]+(:[-a-z0-9]+)?)\s*(\\(.+?\\))?\s*(\\[(.+?)\\])?')
line = sys.stdin.readline()
while (not len(line) == 0) and (not line == begin_header):
line = sys.stdin.readline()
if len(line) == 0:
sys.stderr.write("Couldn't find start token '%s'\n" % (begin_header,))
sys.exit(1)
line = sys.stdin.readline()
pkgs = []
while (not len(line) == 0) and (not line == end_header):
if line == '\n' or comment_re.search(line):
line = sys.stdin.readline()
continue
orlist = line.strip().split('|')
orresult = []
for pkg in orlist:
if debug:
sys.stderr.write("processing pkg '%s'\n" %(pkg,))
match = depends_re.search(pkg)
if match:
pkgname = match.group(1).strip()
verdep = match.group(3)
if not verdep:
verdep = ''
verdep = verdep.strip()
archdeps = match.group(5)
if debug:
sys.stderr.write("data: '%s' '%s' '%s'\n" % (pkgname, verdep, archdeps))
included = 1
if archdeps:
archdeps = match.group(5).strip().split()
included = 0
for arch in archdeps:
if debug:
sys.stderr.write('processing arch %s\n' % (arch,))
negated = 0
if arch[0] == '!':
negated = 1
arch = arch[1:]
if target_arch == arch and negated:
if debug:
sys.stderr.write('not including ')
included = 0
break
elif target_arch == arch and not negated:
if debug:
sys.stderr.write('including ')
included = 1
elif target_arch != arch and negated:
if debug:
sys.stderr.write('including ')
included = 1
if included:
pkgval = pkgname + ' ' + verdep
if debug:
sys.stderr.write('\norresult += ' + pkgval + '\n')
orresult.append(pkgval)
if len(orresult) > 0:
pkgs.append(orresult)
line = sys.stdin.readline()
if len(line) == 0:
sys.stderr.write("Couldn't find end token '%s'\n" % (end_header,))
sys.exit(1)
sys.stdout.write(', '.join([' | '.join([a.strip() for a in x]) for x in pkgs]))
|