3 # Given as input a Packages and a Sources file, produces as output a new
4 # Packages containing fake packages which are installable if and only if the
5 # corresponding source package has satisfiable build dependencies.
7 # Copyright (C) 2008 Stefano Zacchiroli <zack@debian.org>
8 # This program is free software: you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free Software
10 # Foundation, either version 3 of the License, or (at your option) any later
13 # $Id: add-sources.py 5957 2008-08-16 18:32:17Z zack $
18 from optparse import OptionParser
19 from debian_bundle import deb822
21 usage = 'Usage: cat Packages | add-sources [OPTION...] Sources ARCH > Packages.new'
22 cli = OptionParser(usage=usage)
23 cli.add_option('-p', '--prefix', dest='prefix', default='source---',
24 help='set the prefix for fake source packages to PREFIX (default: source---)',
26 (options, args) = cli.parse_args()
30 sources_file = args[0]
31 architecture = args[1]
34 global architecture, options
35 pkg = deb822.Packages()
36 pkg['Package'] = options.prefix + src['Package']
40 if dep['arch'] is None:
43 (polarity, _) = dep['arch'][0]
44 if polarity: # list is inclusive
45 for_me = (True, architecture) in dep['arch']
46 else: # list is exclusive
47 for_me = not ((False, architecture) in dep['arch'])
52 def mk_bin_rels(fields, relations):
57 def get_rels(fields, relations):
60 if relations.has_key(name):
61 rels.extend(relations[name])
64 src_rels = get_rels(fields, relations)
66 for or_deps in src_rels:
67 my_or_deps = map(strip_arch, filter(dep_for_me, or_deps))
69 bin_rels.append(my_or_deps)
73 def str_of_relations(rels):
74 # XXX this is cut and paste from python-debian's deb822.py, more
75 # precisely it matches the str() method of the PkgRelation class
76 # TODO to be removed as soon as python-debian 0.1.12 hits unstable
77 def pp_arch(arch_spec):
78 (excl, arch) = arch_spec
83 def pp_atomic_dep(dep):
85 if dep.has_key('version') and dep['version'] is not None:
86 s += ' (%s %s)' % dep['version']
87 if dep.has_key('arch') and dep['arch'] is not None:
88 s += ' [%s]' % string.join(map(pp_arch, dep['arch']))
90 pp_or_dep = lambda deps: string.join(map(pp_atomic_dep, deps), ' | ')
91 return string.join(map(pp_or_dep, rels), ', ')
93 for field in ['Version', 'Priority', 'Section', 'Maintainer']:
94 if src.has_key(field):
95 pkg[field] = src[field]
96 bin_depends = mk_bin_rels(['build-depends', 'build-depends-indep'],
99 #pkg['Depends'] = deb822.PkgRelation.str(bin_depends)
100 pkg['Depends'] = str_of_relations(bin_depends)
101 bin_conflicts = mk_bin_rels(['build-conflicts', 'build-conflicts-indep'],
104 #pkg['Conflicts'] = deb822.PkgRelation.str(bin_conflicts)
105 pkg['Conflicts'] = str_of_relations(bin_conflicts)
106 pkg['Description'] = 'dummy counterpart of "%s" source package' % \
108 pkg['Description'] += "\n I don't exist, go away."
109 pkg['Architecture'] = 'all'
113 #for pkg in deb822.Packages.iter_paragraphs(sys.stdin):
114 for line in sys.stdin:
117 for src in deb822.Sources.iter_paragraphs(file(sources_file)):
118 if src['Architecture'] in ['any', 'all'] \
119 or architecture in src['Architecture'].split():
120 pkg = pkg_of_src(src)