3 # Whee! Fix testing fubarity
4 # Copyright (C) 2000, 2001 James Troup <james@nocrew.org>
5 # $Id: hack.3,v 1.1 2001-03-14 20:32:05 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 # Computer games don't affect kids. I mean if Pacman affected our generation as
24 # kids, we'd all run around in a darkened room munching pills and listening to
28 ################################################################################
30 import pg, sys, os, string, stat
31 import utils, db_access
34 ################################################################################
39 ################################################################################
42 global Cnf, projectB, db_files, waste, excluded;
46 Cnf = apt_pkg.newConfiguration();
47 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
49 Arguments = [('d',"debug","Christina::Options::Debug", "IntVal"),
50 ('h',"help","Christina::Options::Help"),
51 ('v',"version","Christina::Options::Version")];
53 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
54 projectB = pg.connect('projectb', 'localhost');
55 christina = pg.connect('christina', 'localhost');
56 db_access.init(Cnf, projectB);
58 q = christina.query("""
59 SELECT l.path, f.filename, b.package, b.version, b.architecture, a.arch_string
60 FROM bin_associations ba, binaries b, files f, location l, architecture a
61 WHERE ba.suite = 4 AND ba.bin = b.id AND f.id = b.file
62 AND f.location = l.id AND a.id = b.architecture;""");
66 filename = i[0] + i[1]
67 if not os.path.exists(filename):
69 testing_version = i[3];
70 architecture_id = i[4];
72 x = projectB.query("SELECT b.id, b.version FROM bin_associations ba, binaries b WHERE ba.suite = 5 AND ba.bin = b.id AND b.package = '%s' AND b.architecture = %s" % (package, architecture_id));
75 unstable_version = xl[0][1];
76 #print "%s [%s]: %s ==> %s" % (package, architecture, testing_version, unstable_version);
77 print "%s %s %s" % (package, unstable_version, architecture);
81 #######################################################################################
83 if __name__ == '__main__':
87 # # And yes, I'm all too well aware of how appaling this code is;
88 # # I'm so not caring right now.
90 # # Basic plan: From a known-good backup, get a list of what should
91 # # be in testing and search for every file. If it's not in the
92 # # pool, check in the morgue and double check the md5sum + size.
96 # q = christina.query("""
97 # SELECT l.path, f.filename, f.md5sum, f.size, b.id
98 # FROM bin_associations ba, binaries b, files f, location l
99 # WHERE ba.suite = 4 AND ba.bin = b.id AND f.id = b.file
100 # AND f.location = l.id;""");
101 # ql = q.getresult();
103 # # q = christina.query("""
104 # # SELECT l.path, f.filename, f.md5sum, f.size, s.id
105 # # FROM src_associations sa, source s, files f, location l, dsc_files df
106 # # WHERE sa.suite = 4 AND sa.source = s.id AND f.id = df.file AND f.location = l.id
107 # # AND df.source = s.id;""");
108 # # ql = q.getresult();
113 # count_recoverable = 0;
115 # filename = i[0] + i[1]
116 # count_total = count_total + 1;
117 # if not os.path.exists(filename):
118 # basename = os.path.basename(filename)
119 # morgue_filename = string.join([Cnf["Dir::Morgue"],Cnf["Rhona::MorgueSubDir"],basename],'/');
120 # if os.path.exists(morgue_filename):
122 # db_size = int(i[3]);
124 # file = utils.open_file(morgue_filename, 'r');
126 # sys.stderr.write("E: can't open '%s'.\n" % (morgue_filename));
128 # md5sum = apt_pkg.md5sum(file);
129 # size = os.stat(morgue_filename)[stat.ST_SIZE];
130 # if md5sum != db_md5sum:
131 # #print "E: %s" % (filename);
132 # #sys.stderr.write("E: **WARNING** md5sum mismatch for '%s' ('%s' [current] vs. '%s' [db]).\n" % (morgue_filename, md5sum, db_md5sum));
134 # if size != db_size:
135 # #print "E: %s" % (filename);
136 # #sys.stderr.write("E: **WARNING** size mismatch for '%s' ('%s' [current] vs. '%s' [db]).\n" % (morgue_filename, size, db_size));
138 # bad_ids[i[4]] = "";
139 # print "R: %s [%s]" % (filename, morgue_filename);
140 # ###utils.copy(morgue_filename, filename);
141 # count_recoverable = count_recoverable + 1;
143 # #print "E: %s" % (filename);
146 # #print "G: %s" % (filename);
147 # count_good = count_good + 1;
149 # print "Good: %d / %d (%.2f%%)" % (count_good, count_total, (float(count_good)/count_total*100));
150 # print "Recoverable: %d / %d (%.2f%%)" % (count_recoverable, count_total, (float(count_recoverable)/count_total*100));
151 # count_bad = count_total - count_good - count_recoverable;
152 # print "Bad: %d / %d (%.2f%%)" % (count_bad, count_total, (float(count_bad)/count_total*100));
155 # projectB.query("BEGIN WORK;");
157 # for id in bad_ids.keys():
158 # q = christina.query("SELECT f.filename, f.size, f.md5sum, f.location FROM files f, binaries b WHERE b.id = %d and b.file = f.id;" % (id));
159 # ql = q.getresult();
166 # location_id = i[3];
167 # files_id = db_access.get_files_id(filename, size, md5sum, location_id);
169 # sys.stderr.write("Rejected: INTERNAL ERROR, get_files_id() returned multiple matches for %s.\n" % (filename));
171 # elif files_id == -2:
172 # sys.stderr.write("Rejected: md5sum and/or size mismatch on existing copy of %s.\n" % (filename));
176 # files_id = db_access.set_files_id(filename, size, md5sum, location_id);
177 # print "INSERT(ed) INTO files (filename, size, md5sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, location_id);
180 # print "%s already exists; skipping." % (filename)
183 # q = christina.query("""
184 # SELECT b.package, b.version, s.source, s.version, b.architecture, m.name
185 # FROM binaries b, source s, maintainer m
186 # WHERE b.id = %s AND s.id = b.source AND m.id = b.maintainer
187 # UNION SELECT b.package, b.version, null, null, b.architecture, m.name
188 # FROM binaries b, maintainer m
189 # WHERE b.id = %s AND b.source is null AND b.maintainer = m.id;""" % (id, id));
190 # ql = q.getresult();
196 # source_name = i[2];
197 # source_version = i[3];
199 # architecture_id = i[4];
201 # maintainer = string.replace(maintainer, "'", "\\'");
202 # maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
204 # source_id = db_access.get_source_id (source_name, source_version);
209 # print "INSERT INTO binaries (package, version, maintainer, source, architecture, file, type) VALUES ('%s', '%s', %d, %d, %d, %s, '%s')" % (package, version, maintainer_id, source_id, architecture_id, files_id, "deb");
210 # projectB.query("INSERT INTO binaries (package, version, maintainer, source, architecture, file, type) VALUES ('%s', '%s', %d, %d, %d, %s, '%s')" % (package, version, maintainer_id, source_id, architecture_id, files_id, "deb"));
212 # print "INSERT INTO binaries (package, version, maintainer, architecture, file, type) VALUES ('%s', '%s', %d, %d, %s, '%s')" % (package, version, maintainer_id, architecture_id, files_id, "deb");
213 # projectB.query("INSERT INTO binaries (package, version, maintainer, architecture, file, type) VALUES ('%s', '%s', %d, %d, %s, '%s')" % (package, version, maintainer_id, architecture_id, files_id, "deb"));
215 # projectB.query("COMMIT WORK;");
222 # ## source .. already done
223 # projectB.query("BEGIN WORK;");
225 # for id in bad_ids.keys():
226 # q = christina.query("SELECT f.filename, f.md5sum, f.size, f.location FROM files f, dsc_files df WHERE df.source = %s and f.id = df.file;""" % (id));
227 # ql = q.getresult();
232 # location_id = i[3];
233 # files_id = db_access.get_files_id(filename, size, md5sum, location_id);
235 # sys.stderr.write("Rejected: INTERNAL ERROR, get_files_id() returned multiple matches for %s.\n" % (filename));
237 # elif files_id == -2:
238 # sys.stderr.write("Rejected: md5sum and/or size mismatch on existing copy of %s.\n" % (filename));
242 # files_id = db_access.set_files_id(filename, size, md5sum, location_id);
243 # print "INSERT(ed) INTO files (filename, size, md5sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, location_id);
246 # print "%s already exists; skipping." % (filename)
247 # if filename[-4:] == '.dsc':
248 # dsc_files_id = files_id;
251 # q = christina.query("SELECT s.source, s.version, m.name FROM source s, maintainer m WHERE s.id = %s and s.maintainer = m.id;""" % (id));
252 # ql = q.getresult();
259 # maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
260 # print "INSERT INTO source (source, version, maintainer, file) VALUES ('%s', '%s', %d, %d)" % (source, version, maintainer_id, dsc_files_id);
261 # projectB.query("INSERT INTO source (source, version, maintainer, file) VALUES ('%s', '%s', %d, %d)" % (source, version, maintainer_id, dsc_files_id));
263 # projectB.query("COMMIT WORK;");
271 # qx = christina.query("SELECT l.path, f.filename, f.md5sum, f.size, s.id FROM source s, files f, location l, dsc_files df WHERE f.id = df.file AND f.location = l.id AND df.source = s.id AND s.source = '%s' AND s.version = '%s';" % (source_name, source_version));
272 # qxl = qx.getresult();
274 # filename = ix[0] + ix[1]
275 # if os.path.exists(filename):
277 # basename = os.path.basename(filename)
278 # morgue_filename = string.join([Cnf["Dir::Morgue"],Cnf["Rhona::MorgueSubDir"],basename],'/');
279 # if os.path.exists(morgue_filename):
281 # db_size = int(ix[3]);
283 # file = utils.open_file(morgue_filename, 'r');
285 # sys.stderr.write("E: can't open '%s'.\n" % (morgue_filename));
287 # md5sum = apt_pkg.md5sum(file);
288 # size = os.stat(morgue_filename)[stat.ST_SIZE];
289 # if md5sum != db_md5sum:
290 # sys.stderr.write("E: **WARNING** md5sum mismatch for '%s' ('%s' [current] vs. '%s' [db]).\n" % (morgue_filename, md5sum, db_md5sum));
292 # if size != db_size:
293 # sys.stderr.write("E: **WARNING** size mismatch for '%s' ('%s' [current] vs. '%s' [db]).\n" % (morgue_filename, size, db_size));
295 # new_bad_ids[ix[4]] = "";
296 # print "R: %s [%s]" % (filename, morgue_filename);
297 # utils.copy(morgue_filename, filename);
299 # print "E: %s" % (filename);
301 # projectB.query("BEGIN WORK;");
303 # for new_id in new_bad_ids.keys():
304 # qx = christina.query("SELECT f.filename, f.md5sum, f.size, f.location FROM files f, dsc_files df WHERE df.source = %s and f.id = df.file;""" % (new_id));
305 # qlx = qx.getresult();
310 # location_id = ix[3];
311 # files_id = db_access.get_files_id(filename, size, md5sum, location_id);
313 # sys.stderr.write("Rejected: INTERNAL ERROR, get_files_id() returned multiple matches for %s.\n" % (filename));
315 # elif files_id == -2:
316 # sys.stderr.write("Rejected: md5sum and/or size mismatch on existing copy of %s.\n" % (filename));
320 # files_id = db_access.set_files_id(filename, size, md5sum, location_id);
321 # print "INSERT(ed) INTO files (filename, size, md5sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, location_id);
323 # print "%s already exists; skipping." % (filename)
324 # if filename[-4:] == '.dsc':
325 # dsc_files_id = files_id;
328 # qx = christina.query("SELECT s.source, s.version, m.name FROM source s, maintainer m WHERE s.id = %s and s.maintainer = m.id;""" % (new_id));
329 # qlx = qx.getresult();
335 # maintainer = ix[2];
336 # maintainer = string.replace(maintainer, "'", "\\'");
337 # maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
338 # print "INSERT INTO source (source, version, maintainer, file) VALUES ('%s', '%s', %d, %d)" % (source, version, maintainer_id, dsc_files_id);
339 # projectB.query("INSERT INTO source (source, version, maintainer, file) VALUES ('%s', '%s', %d, %d)" % (source, version, maintainer_id, dsc_files_id));
340 # projectB.query("COMMIT WORK;");