]> git.decadent.org.uk Git - dak.git/blob - dak/generate_contents.py
Start of contents scanner
[dak.git] / dak / generate_contents.py
1 #!/usr/bin/env python
2 # Create all the contents files
3
4 # Copyright (C) 2008, 2009 Michael Casadevall <mcasadevall@debian.org>
5
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.
10
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.
15
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
19
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 ################################################################################
26
27 ################################################################################
28
29 import sys, os, popen2, tempfile, stat, time, pg
30 import apt_pkg
31 from daklib import database, utils
32 from daklib.dak_exceptions import *
33
34 ################################################################################
35
36 Cnf = None
37 projectB = None
38 out = None
39 AptCnf = None
40
41 ################################################################################
42
43 def usage (exit_code=0):
44     print """Usage: dak generate-contents
45 Generate Contents files
46
47  -h, --help                 show this help and exit
48  -s, --suite=SUITE         only write file lists for this suite
49 """
50     sys.exit(exit_code)
51
52 ################################################################################
53
54 def handle_dup_files(file_list):
55     # Sort the list, and then handle finding dups in the filenames key
56
57     # Walk the list, seeing if the current entry and the next one are the same
58     # and if so, join them together
59
60
61     return file_list
62
63 ################################################################################
64
65 def generate_contents(suites):
66     global projectB, Cnf
67     # Ok, the contents information is in the database
68
69     # We need to work and get the contents, and print it out on a per
70     # architectual basis
71
72     # Get our suites, and the architectures
73     for s in suites:
74         suite_id = database.get_suite_id(s)
75
76         q = projectB.query("SELECT architecture FROM suite_architectures WHERE suite = '%d'" % suite_id)
77
78         arch_list = [ ]
79         for r in q.getresult():
80             arch_list.append(r[0])
81
82         arch_all_id = database.get_architecture_id("all")
83
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
86
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
91
92             # This is for the corner case of arch dependent packages colliding
93             # with arch all packages only on some architectures.
94             # Ugly, I know ...
95
96             arch_packages = []
97             for r in q.getresult():
98                 arch_packages.append((r[1], (r[2] + '/' + r[0])))
99
100             arch_packages = handle_dup_files(arch_packages)
101
102             #for contents in arch_packages:
103                 #print contents[0] + '\t\t\t\t' + contents[1]
104
105 ################################################################################
106
107 def main ():
108     global Cnf, projectB, out
109     out = sys.stdout
110
111     Cnf = utils.get_conf()
112
113     Arguments = [('h',"help","Generate-Contents::Options::Help"),
114                  ('s',"suite","Generate-Contents::Options::Suite","HasArg"),
115                 ]
116     for i in [ "help", "suite" ]:
117         if not Cnf.has_key("Generate-Contents::Options::%s" % (i)):
118             Cnf["Generate-Contents::Options::%s" % (i)] = ""
119
120     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
121     Options = Cnf.SubTree("Generate-Contents::Options")
122
123     if Options["Help"]:
124         usage()
125
126     if Options["Suite"]:
127         suites = utils.split_args(Options["Suite"])
128     else:
129         suites = Cnf.SubTree("Suite").List()
130
131     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
132     database.init(Cnf, projectB)
133
134     generate_contents(suites)
135
136 #######################################################################################
137
138 if __name__ == '__main__':
139     main()