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 $
15 # build-essential packages. All build-dependencies and build-conflicts
16 # to one of these packages is simply ignored.
17 # TODO: this list should be obtained from the binary package file,
18 # by grep-dctrl -F Build-Essential --pattern=yes -s Package -n
19 # but then we have to change the way this command is called.
20 buildessentials = ['apt', 'binutils', 'cpio', 'cpp', 'dpkg-dev',
21 'g++', 'gcc', 'libc6-dev', 'make', 'patch',
22 'perl', 'perl-modules']
28 from optparse import OptionParser
29 from debian_bundle import deb822
31 usage = 'Usage: cat Packages | add-sources [OPTION...] Sources ARCH > Packages.new'
32 cli = OptionParser(usage=usage)
33 cli.add_option('-p', '--prefix', dest='prefix', default='source---',
34 help='set the prefix for fake source packages to PREFIX (default: source---)',
36 (options, args) = cli.parse_args()
40 sources_file = args[0]
41 architecture = args[1]
44 global architecture, options
45 pkg = deb822.Packages()
46 pkg['Package'] = options.prefix + src['Package']
50 if buildessentials.count(dep['name']) > 0:
52 elif dep['arch'] is None:
55 (polarity, _) = dep['arch'][0]
56 if polarity: # list is inclusive
57 for_me = (True, architecture) in dep['arch']
58 else: # list is exclusive
59 for_me = not ((False, architecture) in dep['arch'])
64 def mk_bin_rels(fields, relations):
69 def get_rels(fields, relations):
72 if relations.has_key(name):
73 rels.extend(relations[name])
76 src_rels = get_rels(fields, relations)
78 for or_deps in src_rels:
79 my_or_deps = map(strip_arch, filter(dep_for_me, or_deps))
81 bin_rels.append(my_or_deps)
85 def str_of_relations(rels):
86 # XXX this is cut and paste from python-debian's deb822.py, more
87 # precisely it matches the str() method of the PkgRelation class
88 # TODO to be removed as soon as python-debian 0.1.12 hits unstable
89 def pp_arch(arch_spec):
90 (excl, arch) = arch_spec
95 def pp_atomic_dep(dep):
97 if dep.has_key('version') and dep['version'] is not None:
98 s += ' (%s %s)' % dep['version']
99 if dep.has_key('arch') and dep['arch'] is not None:
100 s += ' [%s]' % string.join(map(pp_arch, dep['arch']))
102 pp_or_dep = lambda deps: string.join(map(pp_atomic_dep, deps), ' | ')
103 return string.join(map(pp_or_dep, rels), ', ')
105 for field in ['Version', 'Priority', 'Section', 'Maintainer', 'Architecture']:
106 if src.has_key(field):
107 pkg[field] = src[field]
108 bin_depends = mk_bin_rels(['build-depends', 'build-depends-indep'],
111 #pkg['Depends'] = deb822.PkgRelation.str(bin_depends)
112 pkg['Depends'] = str_of_relations(bin_depends)
113 bin_conflicts = mk_bin_rels(['build-conflicts', 'build-conflicts-indep'],
116 #pkg['Conflicts'] = deb822.PkgRelation.str(bin_conflicts)
117 pkg['Conflicts'] = str_of_relations(bin_conflicts)
118 pkg['Description'] = 'dummy counterpart of "%s" source package' % \
120 pkg['Description'] += "\n I don't exist, go away."
124 #for pkg in deb822.Packages.iter_paragraphs(sys.stdin):
126 for line in sys.stdin:
128 # stanzas have to be separated by a blank line
129 if line and not line.isspace(): print
130 for src in deb822.Sources.iter_paragraphs(file(sources_file)):
131 if src['Architecture'] in ['any', 'all']:
132 pkg = pkg_of_src(src)
134 elif architecture in src['Architecture'].split():
135 pkg = pkg_of_src(src)
136 pkg['Architecture'] = architecture