2 # Create all the contents files
4 # Copyright (C) 2008, 2009 Michael Casadevall <mcasadevall@debian.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
21 # <Ganneff> there is the idea to slowly replace contents files
22 # <Ganneff> with a new generation of such files.
23 # <Ganneff> having more info.
24 # <Ganneff> of course that wont help for now where we need to generate them :)
25 ################################################################################
27 ################################################################################
29 import sys, os, popen2, tempfile, stat, time, pg
31 from daklib import database, utils
32 from daklib.dak_exceptions import *
34 ################################################################################
41 ################################################################################
43 def usage (exit_code=0):
44 print """Usage: dak generate-contents
45 Generate Contents files
47 -h, --help show this help and exit
48 -s, --suite=SUITE only write file lists for this suite
52 ################################################################################
54 def handle_dup_files(file_list):
55 # Sort the list, and then handle finding dups in the filenames key
57 # Walk the list, seeing if the current entry and the next one are the same
58 # and if so, join them together
63 ################################################################################
65 def generate_contents(suites):
67 # Ok, the contents information is in the database
69 # We need to work and get the contents, and print it out on a per
72 # Get our suites, and the architectures
74 suite_id = database.get_suite_id(s)
76 q = projectB.query("SELECT architecture FROM suite_architectures WHERE suite = '%d'" % suite_id)
79 for r in q.getresult():
80 arch_list.append(r[0])
82 arch_all_id = database.get_architecture_id("all")
84 # Got the arch all packages, now we need to get the arch dependent packages
85 # attach the arch all, stick them together, and write out the result
87 for arch_id in arch_list:
88 print "SELECT b.package, c.file, s.section FROM contents c JOIN binaries b ON (b.id=c.binary_pkg) JOIN bin_associations ba ON (b.id=ba.bin) JOIN override o ON (o.package=b.package) JOIN section s ON (s.id=o.section) WHERE (b.architecture = '%d' OR b.architecture = '%d') AND ba.suite = '%d'" % (arch_id, arch_all_id, suite_id)
89 q = projectB.query("SELECT b.package, c.file, s.section FROM contents c JOIN binaries b ON (b.id=c.binary_pkg) JOIN bin_associations ba ON (b.id=ba.bin) JOIN override o ON (o.package=b.package) JOIN section s ON (s.id=o.section) WHERE (b.architecture = '%d' OR b.architecture = '%d') AND ba.suite = '%d'" % (arch_id, arch_all_id, suite_id))
90 # We need to copy the arch_all packages table into arch packages
92 # This is for the corner case of arch dependent packages colliding
93 # with arch all packages only on some architectures.
97 for r in q.getresult():
98 arch_packages.append((r[1], (r[2] + '/' + r[0])))
100 arch_packages = handle_dup_files(arch_packages)
102 #for contents in arch_packages:
103 #print contents[0] + '\t\t\t\t' + contents[1]
105 ################################################################################
108 global Cnf, projectB, out
111 Cnf = utils.get_conf()
113 Arguments = [('h',"help","Generate-Contents::Options::Help"),
114 ('s',"suite","Generate-Contents::Options::Suite","HasArg"),
116 for i in [ "help", "suite" ]:
117 if not Cnf.has_key("Generate-Contents::Options::%s" % (i)):
118 Cnf["Generate-Contents::Options::%s" % (i)] = ""
120 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
121 Options = Cnf.SubTree("Generate-Contents::Options")
127 suites = utils.split_args(Options["Suite"])
129 suites = Cnf.SubTree("Suite").List()
131 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
132 database.init(Cnf, projectB)
134 generate_contents(suites)
136 #######################################################################################
138 if __name__ == '__main__':