]> git.decadent.org.uk Git - dak.git/blob - contrib/hack.3
sync
[dak.git] / contrib / hack.3
1 #!/usr/bin/env python
2
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 $
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 # 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
25 # repetitive music.
26 #         -- Unknown
27
28 ################################################################################
29
30 import pg, sys, os, string, stat
31 import utils, db_access
32 import apt_pkg;
33
34 ################################################################################
35
36 Cnf = None;
37 projectB = None;
38
39 ################################################################################
40
41 def main ():
42     global Cnf, projectB, db_files, waste, excluded;
43
44     apt_pkg.init();
45     
46     Cnf = apt_pkg.newConfiguration();
47     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
48
49     Arguments = [('d',"debug","Christina::Options::Debug", "IntVal"),
50                  ('h',"help","Christina::Options::Help"),
51                  ('v',"version","Christina::Options::Version")];
52
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);
57
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;""");
63     ql = q.getresult();
64
65     for i in ql:
66         filename = i[0] + i[1]
67         if not os.path.exists(filename):
68             package = i[2];
69             testing_version = i[3];
70             architecture_id = i[4];
71             architecture = i[5];
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));
73             xl = x.getresult();
74             new_id = xl[0][0];
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);
78
79     sys.exit(0);
80
81 #######################################################################################
82
83 if __name__ == '__main__':
84     main()
85
86
87 #      # And yes, I'm all too well aware of how appaling this code is;
88 #      # I'm so not caring right now.
89
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.
93
94 #      # Binaries
95
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();
102
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();
109
110 #      bad_ids = {};
111 #      count_total = 0;
112 #      count_good = 0;
113 #      count_recoverable = 0;
114 #      for i in ql:
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):
121 #                  db_md5sum = i[2];
122 #                  db_size = int(i[3]);
123 #                  try:
124 #                      file = utils.open_file(morgue_filename, 'r');
125 #                  except:
126 #                      sys.stderr.write("E: can't open '%s'.\n" % (morgue_filename));
127 #                      continue;
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));
133 #                      continue;
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));
137 #                      continue;
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;
142 #              else:
143 #                  #print "E: %s" % (filename);
144 #                  baz = 0;
145 #          else:
146 #              #print "G: %s" % (filename);
147 #              count_good = count_good + 1;
148
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));
153
154 #      sys.exit(0);
155 #      projectB.query("BEGIN WORK;");
156
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();
160 #          if len(ql) != 1:
161 #              sys.exit(9);
162 #          for i in ql:
163 #              filename = i[0];
164 #              size = i[1];
165 #              md5sum = i[2];
166 #              location_id = i[3];
167 #              files_id = db_access.get_files_id(filename, size, md5sum, location_id);
168 #              if files_id == -1:
169 #                  sys.stderr.write("Rejected: INTERNAL ERROR, get_files_id() returned multiple matches for %s.\n" % (filename));
170 #                  sys.exit(8);
171 #              elif files_id == -2:
172 #                  sys.stderr.write("Rejected: md5sum and/or size mismatch on existing copy of %s.\n" % (filename));
173 #                  sys.exit(8);
174 #              if not files_id:
175 #                  #files_id = 42;
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);
178
179 #              else:
180 #                  print "%s already exists; skipping." % (filename)
181 #                  baz = 0;
182
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();
191 #          if len(ql) != 1:
192 #              sys.exit(9);
193 #          for i in ql:
194 #              package = i[0];
195 #              version = i[1];
196 #              source_name = i[2];
197 #              source_version = i[3];
198 #              source_id = None;
199 #              architecture_id = i[4];
200 #              maintainer = i[5];
201 #              maintainer = string.replace(maintainer, "'", "\\'");
202 #              maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
203 #              if source_name:
204 #                  source_id = db_access.get_source_id (source_name, source_version);
205 #                  if not source_id:
206 #                      print "Say what?";
207 #                      sys.exit(3);
208 #              if source_id:
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"));
211 #              else:
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"));
214
215 #      projectB.query("COMMIT WORK;");
216
217 #      sys.exit(0);
218
219
220
221
222 #      ## source .. already done
223 #      projectB.query("BEGIN WORK;");
224
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();
228 #          for i in ql:
229 #              filename = i[0];
230 #              md5sum = i[1];
231 #              size = i[2];
232 #              location_id = i[3];
233 #              files_id = db_access.get_files_id(filename, size, md5sum, location_id);
234 #              if files_id == -1:
235 #                  sys.stderr.write("Rejected: INTERNAL ERROR, get_files_id() returned multiple matches for %s.\n" % (filename));
236 #                  sys.exit(8);
237 #              elif files_id == -2:
238 #                  sys.stderr.write("Rejected: md5sum and/or size mismatch on existing copy of %s.\n" % (filename));
239 #                  sys.exit(8);
240 #              if not files_id:
241 #                  #files_id = 42;
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);
244
245 #              else:
246 #                  print "%s already exists; skipping." % (filename)
247 #              if filename[-4:] == '.dsc':
248 #                  dsc_files_id = files_id;
249 #              print "--"
250
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();
253 #          if len(ql) != 1:
254 #              sys.exit(9);
255 #          for i in ql:
256 #              source = i[0]
257 #              version = i[1];
258 #              maintainer = i[2];
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));
262
263 #      projectB.query("COMMIT WORK;");
264
265
266
267
268
269 #      def nevermind():
270 #          new_bad_ids = {};
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();
273 #          for ix in qxl:
274 #              filename = ix[0] + ix[1]
275 #              if os.path.exists(filename):
276 #                  continue;
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):
280 #                          db_md5sum = ix[2];
281 #                          db_size = int(ix[3]);
282 #                          try:
283 #                              file = utils.open_file(morgue_filename, 'r');
284 #                          except:
285 #                              sys.stderr.write("E: can't open '%s'.\n" % (morgue_filename));
286 #                              continue;
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));
291 #                              continue;
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));
294 #                              continue;
295 #                          new_bad_ids[ix[4]] = "";
296 #                          print "R: %s [%s]" % (filename, morgue_filename);
297 #                          utils.copy(morgue_filename, filename);
298 #                      else:
299 #                          print "E: %s" % (filename);
300
301 #                      projectB.query("BEGIN WORK;");
302
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();
306 #                          for ix in qlx:
307 #                              filename = ix[0];
308 #                              md5sum = ix[1];
309 #                              size = ix[2];
310 #                              location_id = ix[3];
311 #                              files_id = db_access.get_files_id(filename, size, md5sum, location_id);
312 #                              if files_id == -1:
313 #                                  sys.stderr.write("Rejected: INTERNAL ERROR, get_files_id() returned multiple matches for %s.\n" % (filename));
314 #                                  sys.exit(8);
315 #                              elif files_id == -2:
316 #                                  sys.stderr.write("Rejected: md5sum and/or size mismatch on existing copy of %s.\n" % (filename));
317 #                                  sys.exit(8);
318 #                              if not files_id:
319 #                                  #files_id = 42;
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);
322 #                              else:
323 #                                  print "%s already exists; skipping." % (filename)
324 #                              if filename[-4:] == '.dsc':
325 #                                  dsc_files_id = files_id;
326 #                              print "--"
327
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();
330 #                          if len(qlx) != 1:
331 #                              sys.exit(9);
332 #                          for ix in qlx:
333 #                              source = ix[0];
334 #                              version = ix[1];
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;");