]> git.decadent.org.uk Git - dak.git/blob - contrib/hack.6
sync
[dak.git] / contrib / hack.6
1 #!/usr/bin/env python
2
3 # Fix testing
4 # Copyright (C) 2000, 2001  James Troup <james@nocrew.org>
5 # $Id: hack.6,v 1.1 2001-06-05 22:31:33 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 # 'Too afraid to touch; too afraid you'll like too much'
24
25 ################################################################################
26
27 import pg, sys, os, string
28 import utils, db_access
29 import apt_inst, apt_pkg;
30
31 ################################################################################
32
33 Cnf = None;
34 projectB = None;
35
36 ################################################################################
37
38 def main ():
39     global Cnf, projectB, db_files, waste, excluded;
40
41     apt_pkg.init();
42     
43     Cnf = apt_pkg.newConfiguration();
44     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
45
46     Arguments = [('d',"debug","Christina::Options::Debug", "IntVal"),
47                  ('h',"help","Christina::Options::Help"),
48                  ('v',"version","Christina::Options::Version")];
49
50     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
51     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
52     christina = pg.connect('christina', Cnf["DB::Host"], int(Cnf["DB::Port"]));
53     db_access.init(Cnf, projectB);
54
55     total = 0; found = 0;
56     morgue = Cnf["Dir::Morgue"] + '/' + Cnf["Rhona::MorgueSubDir"];
57
58     xxx = utils.open_file ("xxx", 'r');
59     for line in xxx.readlines():
60         (package, version, arch) = string.split(line);
61         eversion = utils.re_no_epoch.sub('', version);
62         total = total + 1;
63         if arch != "source":
64             #filename = "%s/%s_%s_%s.deb" % (morgue, package, eversion, arch);
65             filename = "%s/%s_%s.deb" % (morgue, package, eversion);
66         else:
67             continue
68         if os.access(filename, os.R_OK) == 0:
69             continue;
70
71         control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename,"r")));
72         deb_arch = control.Find("Architecture");
73         if arch != deb_arch:
74             continue;
75
76         arch_id = db_access.get_architecture_id (arch);
77         q = christina.query("SELECT f.*, l.path, b.* FROM binaries b, files f, location l WHERE b.package = '%s' AND b.architecture = %s AND b.version = '%s' AND b.file = f.id AND l.id = f.location" % (package, arch_id, version));
78         ql = q.getresult();
79         if len(ql) != 1:
80             print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
81             continue;
82         ql = ql[0];
83
84         x = projectB.query("SELECT * FROM source WHERE id = %s" % (ql[11]));
85         xl = x.getresult();
86         if len(xl) != 1:
87             old_filename = filename;
88             z = christina.query("SELECT f.*, l.path, s.*, df.* FROM source s, files f, location l, dsc_files df WHERE s.id = %s AND df.source = s.id AND df.file = f.id AND l.id = f.location" % (ql[11]));
89             zl = z.getresult();
90             if len(zl) < 1:
91                 print old_filename
92                 print repr(ql);
93                 print "SELECT f.*, l.path, s.*, df.* FROM source s, files f, location l, dsc_files df WHERE s.id = %s AND df.source = s.id AND df.file = f.id AND l.id = f.location" % (ql[11]);
94                 print " ==> "+repr(zl);
95                 #sys.exit(3);
96             else:
97                 projectB.query("BEGIN WORK");
98                 gack = [];
99                 for i in zl:
100                     new_filename = i[6] + i[1];
101                     filename = morgue + '/' + os.path.basename(new_filename);
102                     if os.access(filename, os.R_OK):
103                         print filename + " -> " + new_filename;
104                         if os.path.exists(new_filename):
105                             sys.exit(3);
106                         #utils.move(filename, new_filename);
107                         print "INSERT INTO files (id, filename, size, md5sum, location) VALUES (%s, '%s', %s, '%s', %s)" % (i[:5]);
108                         #projectB.query("INSERT INTO files (id, filename, size, md5sum, location) VALUES (%s, '%s', %s, '%s', %s)" % (i[:5]));
109                         gack.append("INSERT INTO dsc_files (id, source, file) VALUES (%s, %s, %s)" % (i[12:]));
110                         if new_filename[-4:] == ".dsc":
111                             print "INSERT INTO source (id, source, version, maintainer, file) VALUES (%s, '%s', '%s', %s, %s)" % (i[7:12]);
112                             #projectB.query("INSERT INTO source (id, source, version, maintainer, file) VALUES (%s, '%s', '%s', %s, %s)" % (i[7:12]));
113                 for i in gack:
114                     print i;
115                     #projectB.query(i);
116             projectB.query("COMMIT WORK");
117             filename = old_filename;
118         
119         projectB.query("BEGIN WORK");
120         new_filename = ql[6] + ql[1];
121         print filename + " -> " + new_filename;
122         if os.path.exists(new_filename):
123             sys.exit(3);
124         utils.move(filename, new_filename);
125         print "INSERT INTO files (id, filename, size, md5sum, location) VALUES (%s, '%s', %s, '%s', %s)" % (ql[:5]);
126         projectB.query("INSERT INTO files (id, filename, size, md5sum, location) VALUES (%s, '%s', %s, '%s', %s)" % (ql[:5]));
127         if ql[11] == 0:
128             print "INSERT INTO binaries (id, package, version, maintainer, architecture, file, type) VALUES (%s, '%s', '%s', %s, %s, %s, '%s')" % (ql[7], ql[8], ql[9], ql[10], ql[12], ql[13], ql[14]);
129             projectB.query("INSERT INTO binaries (id, package, version, maintainer, architecture, file, type) VALUES (%s, '%s', '%s', %s, %s, %s, '%s')" % (ql[7], ql[8], ql[9], ql[10], ql[12], ql[13], ql[14]));
130         else:
131             print "INSERT INTO binaries (id, package, version, maintainer, source, architecture, file, type) VALUES (%s, '%s', '%s', %s, %s, %s, %s, '%s')" % (ql[7:]);
132             projectB.query("INSERT INTO binaries (id, package, version, maintainer, source, architecture, file, type) VALUES (%s, '%s', '%s', %s, %s, %s, %s, '%s')" % (ql[7:]));
133         print "INSERT INTO bin_associations (suite, bin) VALUES (%s, %s)" % (4, ql[7]);
134         projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%s, %s)" % (4, ql[7]));
135
136         projectB.query("COMMIT WORK");
137
138 #######################################################################################
139
140 if __name__ == '__main__':
141     main()
142
143 #######################################################################################
144
145 #      xxx = utils.open_file ("xxx", 'r');
146 #      for line in xxx.readlines():
147 #          (package, version, arch) = string.split(line);
148 #          eversion = utils.re_no_epoch.sub('', version);
149 #          total = total + 1;
150 #          if arch == "source":
151 #              filename = "%s/%s_%s.dsc" % (morgue, package, eversion);
152 #          else:
153 #              continue
154 #          if os.access(filename, os.R_OK) == 0:
155 #              continue;
156
157 #          arch_id = db_access.get_architecture_id (arch);
158 #          q = christina.query("SELECT f.*, l.path, s.*, df.* FROM source s, files f, location l, dsc_files df WHERE s.source = '%s' AND s.version = '%s' AND df.source = s.id AND df.file = f.id AND l.id = f.location" % (package, version));
159 #          ql = q.getresult();
160 #          if len(ql) < 1:
161 #              print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
162 #              continue;
163 #          projectB.query("BEGIN WORK");
164 #          gack = [];
165 #          for i in ql:
166 #              new_filename = i[6] + i[1];
167 #              filename = morgue + '/' + os.path.basename(new_filename);
168 #              if os.access(filename, os.R_OK) == 0:
169 #                  continue;
170 #              print filename + " -> " + new_filename;
171 #              if os.path.exists(new_filename):
172 #                  sys.exit(3);
173 #              utils.move(filename, new_filename);
174 #              print "INSERT INTO files (id, filename, size, md5sum, location) VALUES (%s, '%s', %s, '%s', %s)" % (i[:5]);
175 #              projectB.query("INSERT INTO files (id, filename, size, md5sum, location) VALUES (%s, '%s', %s, '%s', %s)" % (i[:5]));
176 #              gack.append("INSERT INTO dsc_files (id, source, file) VALUES (%s, %s, %s)" % (i[12:]));
177 #              if new_filename[-4:] == ".dsc":
178 #                  print "INSERT INTO source (id, source, version, maintainer, file) VALUES (%s, '%s', '%s', %s, %s)" % (i[7:12]);
179 #                  projectB.query("INSERT INTO source (id, source, version, maintainer, file) VALUES (%s, '%s', '%s', %s, %s)" % (i[7:12]));
180 #                  print "INSERT INTO src_associations (suite, source) VALUES (%s, %s)" % (4, i[7]);
181 #                  projectB.query("INSERT INTO src_associations (suite, source) VALUES (%s, %s)" % (4, i[7]));
182 #              #print repr(i)
183 #          for i in gack:
184 #              print i;
185 #              projectB.query(i);
186 #          projectB.query("COMMIT WORK");
187
188 #######################################################################################
189
190 #######################################################################################
191
192 #      bad = {};
193 #      xxx = utils.open_file ("xxx", 'r');
194 #      for line in xxx.readlines():
195 #          (package, version, arch) = string.split(line);
196 #          version = utils.re_no_epoch.sub('', version);
197 #          total = total + 1;
198 #          if arch != "source":
199 #              filename = "%s/%s_%s_%s.deb" % (morgue, package, version, arch);
200 #          else:
201 #              filename = "%s/%s_%s.dsc" % (morgue, package, version);
202 #          if os.access(filename, os.R_OK):
203 #              found = found + 1;
204 #          else:
205 #              if arch != "source":
206 #                  filename = "%s/%s_%s.deb" % (morgue, package, version);
207 #                  if os.access(filename, os.R_OK):
208 #                      control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename,"r")));
209 #                      deb_arch = control.Find("Architecture");
210 #                      if arch == deb_arch:
211 #                          found = found + 1;
212 #                          continue;
213 #              if arch != "source":
214 #                  xf = 0;
215 #                  arch_id = db_access.get_architecture_id (arch);
216 #                  q = projectB.query("SELECT version FROM binaries b, bin_associations ba WHERE b.package = '%s' AND b.architecture = %s AND ba.bin = b.id AND ba.suite = 5" % (package, arch_id));
217 #                  ql = q.getresult();
218 #                  if len(ql) != 1:
219 #                      q = projectB.query("SELECT version FROM binaries b, bin_associations ba WHERE b.package = '%s' AND b.architecture = %s AND ba.bin = b.id AND ba.suite = 2" % (package, arch_id));
220 #                      ql = q.getresult();
221 #                      if len(ql) != 1:
222 #                          #print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
223 #                          continue;
224
225 #                  unstable_version = ql[0][0];
226 #                  print package+" "+unstable_version+" "+arch;
227 #                  found = found + 1;
228 #              else:
229 #                  q = projectB.query("SELECT version FROM source s, src_associations sa WHERE s.source = '%s' AND sa.source = s.id AND sa.suite = 5" % (package));
230 #                  ql = q.getresult();
231 #                  if len(ql) != 1:
232 #                      q = projectB.query("SELECT version FROM source s, src_associations sa WHERE s.source = '%s' AND sa.source = s.id AND sa.suite = 2" % (package));
233 #                      ql = q.getresult();
234 #                      if len(ql) != 1:
235 #                          #print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
236 #                          continue;
237
238 #                  unstable_version = ql[0][0];
239 #                  print package+" "+unstable_version+" "+arch;
240 #                  found = found + 1;
241
242 #      #print "Good: %d / %d (%.2f%%)" % (found, total, (float(found)/total*100));
243 #      #not_found = total - found;
244 #      #print "Bad: %d / %d (%.2f%%)" % (not_found, total, (float(not_found)/total*100));
245
246 #######################################################################################
247
248 # Pretty print bad stuff code
249
250 #              key = package+'~'+version;
251 #              if not bad.has_key(key):
252 #                  bad[key] = [];
253 #              bad[key].append(arch);
254
255 #      keys = bad.keys();
256 #      keys.sort();
257 #      for i in keys:
258 #          print i+": "+repr(bad[i]);
259
260
261
262 # Check if is in DB code
263
264 #              arch_id = db_access.get_architecture_id (arch);
265 #              q = projectB.query("SELECT id FROM binaries WHERE package = '%s' AND version = '%s' AND architecture = %s" % (package, version, arch_id));
266 #              ql = q.getresult();
267 #              if ql != []:
268 #                  found = found + 1;
269
270 #              q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version));
271 #              ql = q.getresult();
272 #              if ql != []:
273 #                  found = found + 1;