3 # Generate file list which is then fed to apt-ftparchive to generate Packages and Sources files
4 # Copyright (C) 2000, 2001 James Troup <james@nocrew.org>
5 # $Id: jenna,v 1.13 2001-08-21 15:47:47 troup Exp $
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.
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.
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
21 #######################################################################################
23 # BTAF: "GOD *DAMMIT*!! What the FUCK happened to my free will??"
25 # -- http://www.angryflower.com/timelo.gif
27 #######################################################################################
29 import pg, string, os, sys
31 import db_access, utils, claire, logging
37 def generate_src_list(suite, component, output, dislocated_files):
40 suite_id = db_access.get_suite_id(suite);
43 q = projectB.query("SELECT s.source, l.path, f.filename, 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 ORDER BY s.source, s.version"
46 q = projectB.query("SELECT s.source, l.path, f.filename, 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 ORDER BY s.source, s.version"
47 % (component, suite_id));
48 entries = q.getresult();
50 (source, path, filename, file_id) = entry;
51 if dislocated_files.has_key(file_id):
52 filename = dislocated_files[file_id];
54 filename = path + filename;
55 if sources.has_key(source):
56 utils.warn("%s in %s / %s / source is duplicated." % (source, suite, component));
58 sources[source] = filename;
60 # Write the list of files out
61 source_keys = sources.keys();
63 for source in source_keys:
64 output.write(sources[source]+'\n')
66 #########################################################################################
68 def generate_bin_list(suite, component, architecture, output, type, dislocated_files):
71 suite_id = db_access.get_suite_id(suite);
74 q = projectB.query("SELECT b.package, l.path, f.filename, 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' ORDER BY b.package, b.version, a.arch_string" % (architecture, suite_id, type));
76 q = projectB.query("SELECT b.package, l.path, f.filename, 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' ORDER BY b.package, b.version, a.arch_string" % (component, architecture, suite_id, type));
77 entries = q.getresult();
79 (package, path, filename, file_id) = entry;
80 if dislocated_files.has_key(file_id):
81 filename = dislocated_files[file_id];
83 filename = path + filename;
84 if packages.has_key(package):
85 utils.warn("%s in %s / %s / %s / %s is duplicated." % (package, suite, component, architecture, type));
87 packages[package] = filename;
89 # Write the list of files out
90 package_keys = packages.keys();
92 for package in package_keys:
93 output.write(packages[package]+'\n')
95 #########################################################################################
98 # <elmo> I'm doing it in python btw.. nothing against your monster
99 # SQL, but the python wins in terms of speed and readiblity
103 # <aj> you are not!!!
104 # <aj> you mock my SQL!!!!
105 # <elmo> you want have contest of skillz??????
106 # <aj> all your skillz are belong to my sql!!!!
107 # <elmo> yo momma are belong to my python!!!!
108 # <aj> yo momma was SQLin' like a pig last night!
111 # If something has gone from arch:all to arch:any or vice-versa,
112 # clean out the old versions here. The rest of jenna won't do this
113 # because it's lame. I have no idea. </aj>
115 def clean_duplicate_packages(suite):
116 Logger.log(["Cleaning duplicate packages", suite]);
118 suite_id = db_access.get_suite_id(suite)
119 q = projectB.query("""
121 b1.id, b1.version, a1.arch_string,
122 b2.id, b2.version, a2.arch_string
123 FROM bin_associations ba1, binaries b1, architecture a1,
124 bin_associations ba2, binaries b2, architecture a2
125 WHERE ba1.suite = ba2.suite AND ba1.suite = %s
126 AND ba1.bin = b1.id AND b1.architecture = a1.id
127 AND ba2.bin = b2.id AND b2.architecture = a2.id
128 AND b1.package = b2.package
129 AND (a1.id = a2.id OR a1.arch_string = 'all' OR a2.arch_string = 'all')
131 AND versioncmp(b1.version, b2.version) <= 0
132 ORDER BY b1.package, b1.version, a1.arch_string;""" % (suite_id))
137 (package, oldid, oldver, oldarch, newid, newver, newarch) = i
138 if not seen.has_key(oldid):
140 Logger.log(["Removing", package, oldver, oldarch, newver, newarch]);
141 projectB.query("DELETE FROM bin_associations WHERE suite = %s AND bin = %s" % (suite_id, oldid))
143 Logger.log(["Superceded", package, oldver, oldarch, newver, newarch]);
145 # If something has moved from one component to another we need to
146 # clean out the old versions here. The rest of jenna won't do this
147 # because it works on a per-component level for flexibility.
149 def clean_suite (suite):
150 Logger.log(["Cleaning out packages", suite]);
152 suite_id = db_access.get_suite_id(suite)
153 q = projectB.query("""
154 SELECT b.id, b.package, a.arch_string, b.version, l.path, f.filename, c.name
155 FROM binaries b, bin_associations ba, files f, location l, architecture a, component c
156 WHERE ba.suite = %s AND ba.bin = b.id AND b.file = f.id AND
157 f.location = l.id AND l.component = c.id AND b.architecture = a.id
159 SELECT s.id, s.source, 'source', s.version, l.path, f.filename, c.name
160 FROM source s, src_associations sa, files f, location l, component c
161 WHERE sa.suite = %s AND sa.source = s.id AND s.file = f.id AND
162 f.location = l.id AND l.component = c.id;""" % (suite_id, suite_id));
166 (id, package, architecture, version, path, filename, component) = i;
167 filename = path + filename;
168 if architecture == "source":
169 delete_table = "src_associations";
170 delete_col = "source";
172 delete_table = "bin_associations";
174 key = "%s~%s" % (package, architecture);
175 if os.path.exists(filename):
177 (other_version, other_component, other_id) = d[key];
178 if apt_pkg.VersionCompare(version, other_version) != 1:
179 (keep_version, keep_component) = (other_version, other_component)
180 (delete_id, delete_version, delete_component) = (id, version, component)
182 (keep_version, keep_component) = (version, component)
183 (delete_id, delete_version, delete_component) = (other_id, other_version, other_component)
184 d[key] = (version, component, id);
185 if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
186 Logger.log(["deleting", package, architecture, delete_version, delete_component, keep_version, keep_component]);
187 projectB.query("DELETE FROM %s WHERE suite = %s AND %s = %s" % (delete_table, suite_id, delete_col, delete_id));
189 Logger.log(["[untouchable]", package, architecture, delete_version, delete_component, keep_version, keep_component]);
191 d[key] = (version, component, id);
193 utils.warn("%s is in %s but doesn't appear to exist?" % (filename, suite));
195 #########################################################################################
198 global Cnf, projectB, Logger;
199 dislocated_files = {};
203 Cnf = apt_pkg.newConfiguration();
204 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
206 Arguments = [('a',"architecture","Jenna::Options::Architecture", "HasArg"),
207 ('c',"component","Jenna::Options::Component", "HasArg"),
208 ('d',"debug","Jenna::Options::Debug", "IntVal"),
209 ('h',"help","Jenna::Options::Help"),
210 ('s',"suite", "Jenna::Options::Suite", "HasArg"),
211 ('v',"verbose","Jenna::Options::Verbose"),
212 ('V',"version","Jenna::Options::Version")];
214 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
216 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
217 db_access.init(Cnf, projectB);
218 Logger = logging.Logger(Cnf, "jenna");
220 if Cnf["Jenna::Options::Suite"] == "":
221 Cnf["Jenna::Options::Suite"] = string.join(Cnf.SubTree("Suite").List());
222 for suite in string.split(Cnf["Jenna::Options::Suite"]):
223 suite = string.lower(suite);
224 if suite == 'stable':
225 dislocated_files = claire.find_dislocated_stable(Cnf, projectB);
227 dislocated_files = {};
229 clean_duplicate_packages(suite)
230 components = Cnf["Jenna::Options::Component"];
231 if not Cnf.has_key("Suite::%s::Components" % (suite)):
234 components = string.join(Cnf.SubTree("Suite::%s::Components" % (suite)).List());
235 for component in string.split(components):
236 component = string.lower(component)
237 architectures = Cnf["Jenna::Options::Architecture"];
238 if architectures == "":
239 architectures = string.join(Cnf.SubTree("Suite::%s::Architectures" % (suite)).List());
240 for architecture in string.split(architectures):
241 architecture = string.lower(architecture)
242 if architecture == "all":
244 if architecture == "source":
245 Logger.log(["Processing dists/%s/%s/%s..." % (suite, component, architecture)]);
246 output = utils.open_file("%s/%s_%s_%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w")
247 generate_src_list(suite, component, output, dislocated_files);
250 Logger.log(["Processing dists/%s/%s/binary-%s..." % (suite, component, architecture)]);
251 output = utils.open_file("%s/%s_%s_binary-%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w");
252 generate_bin_list(suite, component, architecture, output, "deb", dislocated_files);
254 if component == "main" and (suite == "unstable" or suite == "testing"): # FIXME: must be a cleaner way to say debian-installer is main only?
255 Logger.log(["Processing dists/%s/%s/debian-installer/binary-%s..." % (suite,component, architecture)]);
256 output = utils.open_file("%s/%s_%s_debian-installer_binary-%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w");
257 generate_bin_list(suite, component, architecture, output, "udeb", dislocated_files);
261 #########################################################################################
263 if __name__ == '__main__':