]> git.decadent.org.uk Git - dak.git/blob - contrib/fix.9
sync
[dak.git] / contrib / fix.9
1 #!/usr/bin/env python
2
3 # Fix for bug in katie where dsc_files was initialized from changes and not dsc
4 # Copyright (C) 2000  James Troup <james@nocrew.org>
5 # $Id: fix.9,v 1.2 2000-12-18 07:11:25 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 # "Look around... leaves are brown... and the sky is hazy shade of winter,
22 #  Look around... leaves are brown... there's a patch of snow on the ground."
23 #                                         -- Simon & Garfunkel / 'A Hazy Shade'
24
25 ################################################################################
26
27 import pg, sys, os, string, stat
28 import utils, db_access
29 import apt_pkg;
30
31 ################################################################################
32
33 Cnf = None;
34 projectB = None;
35
36 ################################################################################
37
38 def main ():
39     global Cnf, projectB;
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","Claire::Options::Debug", "IntVal"),
47                  ('h',"help","Claire::Options::Help"),
48                  ('v',"version","Claire::Options::Version")];
49
50     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
51
52     projectB = pg.connect('projectb', 'localhost');
53
54     db_access.init(Cnf, projectB);
55
56     for dsc_file in sys.stdin.readlines():
57         dsc_file = dsc_file[:-1];
58         base_dsc_file = os.path.basename(dsc_file);
59         print dsc_file
60         dsc = utils.parse_changes(dsc_file);
61         dsc_files = utils.build_file_list(dsc, 1);
62         q = projectB.query("SELECT s.id, l.id, l.path FROM source s, location l, files f WHERE s.source = '%s' AND s.version = '%s' AND f.id = s.file AND f.location = l.id" % (dsc["source"], dsc["version"]));
63         ql = q.getresult();
64         if ql == [] or len(ql) > 1:
65             print " EEEEEEEEEEEEEEK!!!"
66             print " ",base_dsc_file
67         source_id = ql[0][0];
68         location_id = ql[0][1];
69         location = ql[0][2];
70         dsc_files[base_dsc_file] = {};
71         dsc_files[base_dsc_file]["size"] = os.stat(dsc_file)[stat.ST_SIZE];
72         dsc_files[base_dsc_file]["md5sum"] = apt_pkg.md5sum(utils.open_file(dsc_file,"r"));
73         q = projectB.query("SELECT f.filename FROM dsc_files df, source s, files f WHERE s.id = '%s' AND df.source = s.id AND f.id = df.file" % (source_id));
74         for i in q.getresult():
75             file = os.path.basename(i[0]);
76             if not dsc_files.has_key(file):
77                 if file != base_dsc_file:
78                     print " MWAAAP! MWAAP! Can't find %s!" % (file)
79             else: 
80                 del dsc_files[file];
81         for i in dsc_files.keys():
82             filename = os.path.dirname(dsc_file) + '/' + i;
83             if not os.path.exists(filename):
84                 print " MWAAP!!!!!!!!!!!!!"
85                 print filename
86             filename = string.replace(filename, location, '');
87             #print " filename: ",filename
88             #print " size: ", dsc_files[i]["size"]
89             #print " md5sum: ",dsc_files[i]["md5sum"]
90             #print " location_id: ", location_id
91             files_id = db_access.get_files_id(filename, dsc_files[i]["size"], dsc_files[i]["md5sum"], location_id);
92             if files_id < 0 or files_id == None:
93                 print " BORK!!!!!!!!!!!!"
94                 print " ",filename
95             else:
96                 foo = 1
97                 #print "INSERT INTO dsc_files (source, file) VALUES ('%s', '%s')" % (source_id, files_id);
98                 projectB.query("INSERT INTO dsc_files (source, file) VALUES ('%s', '%s')" % (source_id, files_id));
99             print " doh:",i
100
101 #######################################################################################
102
103 if __name__ == '__main__':
104     main()
105