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 generate_contents(suites):
56 # Ok, the contents information is in the database
58 # We need to work and get the contents, and print it out on a per
61 # Read in the contents file header
63 if Cnf.has_key("Generate-Contents::Header"):
64 h = open(Cnf["Generate-Contents::Header"], "r")
68 # Get our suites, and the architectures
70 suite_id = database.get_suite_id(s)
72 q = projectB.query("SELECT s.architecture, a.arch_string FROM suite_architectures s JOIN architecture a ON (s.architecture=a.id) WHERE suite = '%d'" % suite_id)
75 for r in q.getresult():
76 if r[1] != "source" and r[1] != "all":
77 arch_list.append((r[0], r[1]))
79 arch_all_id = database.get_architecture_id("all")
81 # Time for the query from hell. Essentially, we need to get the assiocations, the filenames, the paths,
82 # and all that fun stuff from the database.
84 for arch_id in arch_list:
85 q = projectB.query("""SELECT p.path||'/'||n.file, comma_separated_list(s.section||'/'||b.package) FROM content_associations c JOIN content_file_paths p ON (c.filepath=p.id) JOIN content_file_names n ON (c.filename=n.id) 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' AND b.type = 'deb' GROUP BY (p.path||'/'||n.file)""" % (arch_id[0], arch_all_id, suite_id))
87 f = gzip.open(Cnf["Dir::Root"] + "dists/%s/Contents-%s.gz" % (s, arch_id[1]), "w")
92 for contents in q.getresult():
93 f.write(contents[0] + "\t\t\t" + contents[-1] + "\n")
97 # The MORE fun part. Ok, udebs need their own contents files, udeb, and udeb-nf (not-free)
98 # This is HORRIBLY debian specific :-/
101 section_id = database.get_section_id('debian-installer') # all udebs should be here)
104 q = projectB.query("""SELECT p.path||'/'||n.file, comma_separated_list(s.section||'/'||b.package) FROM content_associations c JOIN content_file_paths p ON (c.filepath=p.id) JOIN content_file_names n ON (c.filename=n.id) 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 s.id = '%d' AND ba.suite = '%d' AND b.type = 'udeb' GROUP BY (p.path||'/'||n.file)""" % (section_id, suite_id))
106 f = gzip.open(Cnf["Dir::Root"] + "dists/%s/Contents-udeb.gz" % (s), "w")
111 for contents in q.getresult():
112 f.write(contents[0] + "\t\t\t" + contents[-1] + "\n")
116 # Once more, with non-free
117 section_id = database.get_section_id('non-free/debian-installer') # all udebs should be here)
120 q = projectB.query("""SELECT p.path||'/'||n.file, comma_separated_list(s.section||'/'||b.package) FROM content_associations c JOIN content_file_paths p ON (c.filepath=p.id) JOIN content_file_names n ON (c.filename=n.id) 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 s.id = '%d' AND ba.suite = '%d' AND b.type = 'udeb' GROUP BY (p.path||'/'||n.file)""" % (section_id, suite_id))
122 f = gzip.open(Cnf["Dir::Root"] + "dists/%s/Contents-udeb-nf.gz" % (s), "w")
127 for contents in q.getresult():
128 f.write(contents[0] + "\t\t\t" + contents[-1] + "\n")
132 ################################################################################
135 global Cnf, projectB, out
138 Cnf = utils.get_conf()
140 Arguments = [('h',"help","Generate-Contents::Options::Help"),
141 ('s',"suite","Generate-Contents::Options::Suite","HasArg"),
144 for i in [ "help", "suite" ]:
145 if not Cnf.has_key("Generate-Contents::Options::%s" % (i)):
146 Cnf["Generate-Contents::Options::%s" % (i)] = ""
148 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
149 Options = Cnf.SubTree("Generate-Contents::Options")
155 suites = utils.split_args(Options["Suite"])
157 suites = Cnf.SubTree("Suite").List()
159 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
160 database.init(Cnf, projectB)
162 generate_contents(suites)
164 #######################################################################################
166 if __name__ == '__main__':