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 $
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 # 'Too afraid to touch; too afraid you'll like too much'
25 ################################################################################
27 import pg, sys, os, string
28 import utils, db_access
29 import apt_inst, apt_pkg;
31 ################################################################################
36 ################################################################################
39 global Cnf, projectB, db_files, waste, excluded;
43 Cnf = apt_pkg.newConfiguration();
44 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
46 Arguments = [('d',"debug","Christina::Options::Debug", "IntVal"),
47 ('h',"help","Christina::Options::Help"),
48 ('v',"version","Christina::Options::Version")];
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);
56 morgue = Cnf["Dir::Morgue"] + '/' + Cnf["Rhona::MorgueSubDir"];
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);
64 #filename = "%s/%s_%s_%s.deb" % (morgue, package, eversion, arch);
65 filename = "%s/%s_%s.deb" % (morgue, package, eversion);
68 if os.access(filename, os.R_OK) == 0:
71 control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename,"r")));
72 deb_arch = control.Find("Architecture");
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));
80 print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
84 x = projectB.query("SELECT * FROM source WHERE id = %s" % (ql[11]));
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]));
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);
97 projectB.query("BEGIN WORK");
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):
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]));
116 projectB.query("COMMIT WORK");
117 filename = old_filename;
119 projectB.query("BEGIN WORK");
120 new_filename = ql[6] + ql[1];
121 print filename + " -> " + new_filename;
122 if os.path.exists(new_filename):
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]));
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]));
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]));
136 projectB.query("COMMIT WORK");
138 #######################################################################################
140 if __name__ == '__main__':
143 #######################################################################################
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);
150 # if arch == "source":
151 # filename = "%s/%s_%s.dsc" % (morgue, package, eversion);
154 # if os.access(filename, os.R_OK) == 0:
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();
161 # print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
163 # projectB.query("BEGIN WORK");
166 # new_filename = i[6] + i[1];
167 # filename = morgue + '/' + os.path.basename(new_filename);
168 # if os.access(filename, os.R_OK) == 0:
170 # print filename + " -> " + new_filename;
171 # if os.path.exists(new_filename):
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]));
186 # projectB.query("COMMIT WORK");
188 #######################################################################################
190 #######################################################################################
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);
198 # if arch != "source":
199 # filename = "%s/%s_%s_%s.deb" % (morgue, package, version, arch);
201 # filename = "%s/%s_%s.dsc" % (morgue, package, version);
202 # if os.access(filename, os.R_OK):
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:
213 # if arch != "source":
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();
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();
222 # #print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
225 # unstable_version = ql[0][0];
226 # print package+" "+unstable_version+" "+arch;
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();
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();
235 # #print "YOU LOSE: "+package+"~"+version+"~"+arch+"~"+repr(ql)
238 # unstable_version = ql[0][0];
239 # print package+" "+unstable_version+" "+arch;
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));
246 #######################################################################################
248 # Pretty print bad stuff code
250 # key = package+'~'+version;
251 # if not bad.has_key(key):
253 # bad[key].append(arch);
258 # print i+": "+repr(bad[i]);
262 # Check if is in DB code
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();
270 # q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version));
271 # ql = q.getresult();