]> git.decadent.org.uk Git - dak.git/blob - jenna
Update dependencies
[dak.git] / jenna
1 #!/usr/bin/env python
2
3 # Generate file list which is then fed to apt-ftparchive to generate Packages and Sources files
4 # Copyright (C) 2000  James Troup <james@nocrew.org>
5 # $Id: jenna,v 1.2 2000-12-05 04:27:48 troup Exp $
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 #######################################################################################
22
23 # BTAF: "GOD *DAMMIT*!!  What the FUCK happened to my free will??"
24 #
25 # -- http://www.angryflower.com/timelo.gif
26
27 #######################################################################################
28
29 import pg, string, os, sys
30 import apt_pkg
31 import db_access, utils, claire
32
33 projectB = None
34 Cnf = None
35
36 def generate_src_list(suite, component, output, dislocated_files):
37     sources = {}
38
39     suite_id = db_access.get_suite_id(suite);
40     
41     if component == "-":
42         q = projectB.query("SELECT s.source, s.version, l.path, f.filename, s.id, f.id FROM source s, src_associations sa, location l, files f WHERE sa.source = s.id AND sa.suite = '%d' AND l.id = f.location AND s.file = f.id"
43                            % (suite_id));
44     else:
45         q = projectB.query("SELECT s.source, s.version, l.path, f.filename, s.id, f.id FROM source s, src_associations sa, location l, component c, files f WHERE lower(c.name) = '%s' AND (c.id = l.component OR l.component = NULL) AND sa.source = s.id AND sa.suite = '%d' AND l.id = f.location AND s.file = f.id"
46                            % (component, suite_id));
47     entries = q.getresult();
48     for entry in entries:
49         source = entry[0]
50         version = entry[1]
51         filename = entry[2]+entry[3];
52         id = entry[4]
53         add_new = 0
54         file_id = entry[5];
55         if dislocated_files.has_key(file_id):
56             filename = dislocated_files[file_id];
57         if os.path.exists(filename):
58             if sources.has_key(source):
59                 if apt_pkg.VersionCompare(sources[source]["version"], version) == -1:
60                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
61                         print "deleting %s (%s) in favour of newer version %s..." % (source, sources[source]["version"], version)
62                         projectB.query("DELETE FROM src_associations WHERE source = %s AND suite = %d" % (sources[source]["id"], suite_id))
63                     else:
64                         if Cnf.Find("Jenna::Options::Verbose"):
65                             print "[untouchable] would delete %s (%s) in favour of newer version %s..." % (source, sources[source]["version"], version)
66                     sources[source] = { "id": id, "version": version, "filename": filename }
67                 else:
68                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
69                         print "deleting %s (%s) in favour of newer version %s..." % (source, version, sources[source]["version"])
70                         projectB.query("DELETE FROM src_associations WHERE source = %s AND suite = %d" % (id, suite_id))
71                     else:
72                         if Cnf.Find("Jenna::Options::Verbose"):
73                             print "[untouchable] would delete %s (%s) in favour of newer version %s..." % (source, version, sources[source]["version"])
74             else:
75                 sources[source] = { "id": id, "version": version, "filename": filename }
76         else:
77             if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
78                 sys.stderr.write("WARNING: deleting %s because it doesn't exist.\n" % (filename));
79                 projectB.query("DELETE FROM src_associations WHERE source = %s AND suite = %d" % (id, suite_id))
80
81     # Write the list of files out
82     source_keys = sources.keys();
83     source_keys.sort();
84     for source in source_keys:
85         output.write(sources[source]["filename"]+'\n')
86     
87 def generate_bin_list(suite, component, architecture, output, type, dislocated_files):
88     packages = {}
89
90     suite_id = db_access.get_suite_id(suite);
91     
92     if component == "-":
93         q = projectB.query("SELECT b.package, b.version, l.path, f.filename, b.id, f.id FROM architecture a, binaries b, bin_associations ba, location l, files f WHERE ( a.arch_string = '%s' OR a.arch_string = 'all' ) AND a.id = b.architecture AND ba.bin = b.id AND ba.suite = '%d' AND l.id = f.location AND b.file = f.id AND b.type = '%s'" % (architecture, suite_id, type));
94     else:
95         q = projectB.query("SELECT b.package, b.version, l.path, f.filename, b.id, f.id FROM architecture a, binaries b, bin_associations ba, location l, component c, files f WHERE lower(c.name) = '%s' AND (c.id = l.component OR l.component = NULL) AND (a.arch_string = '%s' OR a.arch_string = 'all') AND a.id = b.architecture AND ba.bin = b.id AND ba.suite = '%d' AND l.id = f.location AND b.file = f.id AND b.type = '%s'" % (component, architecture, suite_id, type));
96     entries = q.getresult();
97     for entry in entries:
98         package = entry[0]
99         version = entry[1]
100         filename = entry[2]+entry[3];
101         id = entry[4]
102         add_new = 0
103         file_id = entry[5];
104         if dislocated_files.has_key(file_id):
105             filename = dislocated_files[file_id];
106         
107         # Hack to handle screwed up sid distro [FIXME: this may have issues, remove ASAP]
108         if not os.path.exists(filename):
109             sid_filename = string.replace(filename, "/woody/", "/potato/");
110             if os.path.exists(sid_filename):
111                 filename = sid_filename;
112                 
113         if os.path.exists(filename):
114             if packages.has_key(package):
115                 if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
116                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
117                         print "deleting %s (%s) in favour of newer version %s..." % (package, packages[package]["version"], version)
118                         projectB.query("DELETE FROM bin_associations WHERE bin = %s AND suite = %d" % (packages[package]["id"], suite_id))
119                     else:
120                         if Cnf.Find("Jenna::Options::Verbose"):
121                             print "[untouchable] would delete %s (%s) in favour of newer version %s..." % (package, packages[package]["version"], version)
122                     packages[package] = { "id": id, "version": version, "filename": filename }
123                 else:
124                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
125                         print "deleting %s (%s) in favour of newer version %s..." % (package, version, packages[package]["version"])
126                         projectB.query("DELETE FROM bin_associations WHERE bin = %s AND suite = %d" % (id, suite_id))
127                     else:
128                         if Cnf.Find("Jenna::Options::Verbose"):
129                             print "[untochable] would delete %s (%s) in favour of newer version %s..." % (package, version, packages[package]["version"])
130             else:
131                 packages[package] = { "id": id, "version": version, "filename": filename }
132         else:
133             if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
134                 sys.stderr.write("WARNING: deleting %s because it doesn't exist.\n" % (filename));
135                 projectB.query("DELETE FROM bin_associations WHERE bin = %s AND suite = %d" % (id, suite_id))
136
137     # Write the list of files out
138     package_keys = packages.keys();
139     package_keys.sort();
140     for package in package_keys:
141         output.write(packages[package]["filename"]+'\n')
142     
143     
144
145 def main():
146     global Cnf, projectB;
147     dislocated_files = {};
148     
149     projectB = pg.connect('projectb', 'localhost');
150     
151     apt_pkg.init();
152     
153     Cnf = apt_pkg.newConfiguration();
154     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
155
156     Arguments = [('a',"architecture","Jenna::Options::Architecture", "HasArg"),
157                  ('c',"component","Jenna::Options::Component", "HasArg"),
158                  ('d',"debug","Jenna::Options::Debug", "IntVal"),
159                  ('h',"help","Jenna::Options::Help"),
160                  ('s',"suite", "Jenna::Options::Suite", "HasArg"),
161                  ('v',"verbose","Jenna::Options::Verbose"),
162                  ('V',"version","Jenna::Options::Version")];
163
164     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
165
166     db_access.init(Cnf, projectB);
167
168     if Cnf["Jenna::Options::Suite"] == "":
169         Cnf["Jenna::Options::Suite"] = string.join(Cnf.SubTree("Suite").List());
170     for suite in string.split(Cnf["Jenna::Options::Suite"]):
171         suite = string.lower(suite);
172         if suite == 'stable':
173             dislocated_files = claire.find_dislocated_stable(Cnf, projectB);
174         components = Cnf["Jenna::Options::Component"];
175         if not Cnf.has_key("Suite::%s::Components" % (suite)):
176             components = "-";
177         if components == "":
178             components = string.join(Cnf.SubTree("Suite::%s::Components" % (suite)).List());
179         for component in string.split(components):
180             component = string.lower(component)
181             architectures = Cnf["Jenna::Options::Architecture"];
182             if architectures == "":
183                 architectures = string.join(Cnf.SubTree("Suite::%s::Architectures" % (suite)).List());
184             for architecture in string.split(architectures):
185                 architecture = string.lower(architecture)
186                 if architecture == "all":
187                     continue
188                 if architecture == "source":
189                     print "Processing dists/%s/%s/%s..." % (suite, component, architecture);
190                     output = utils.open_file("%s/%s_%s_%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w")
191                     generate_src_list(suite, component, output, dislocated_files);
192                     output.close();
193                 else:
194                     print "Processing dists/%s/%s/binary-%s..." % (suite, component, architecture);
195                     output = utils.open_file("%s/%s_%s_binary-%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w");
196                     generate_bin_list(suite, component, architecture, output, "deb", dislocated_files);
197                     output.close();
198                     if component == "main": # FIXME: must be a cleaner way to say debian-installer is main only?
199                         print "Processing dists/%s/%s/debian-installer/binary-%s..." % (suite,component, architecture);
200                         output = utils.open_file("%s/%s_%s_debian-installer_binary-%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w");
201                         generate_bin_list(suite, component, architecture, output, "udeb", dislocated_files);
202                         output.close();
203
204 if __name__ == '__main__':
205     main()
206