]> git.decadent.org.uk Git - dak.git/blob - contrib/hack.4
sync
[dak.git] / contrib / hack.4
1 #!/usr/bin/env python
2
3 # Whee!  Fix testing fubarity
4 # Copyright (C) 2000, 2001  James Troup <james@nocrew.org>
5 # $Id: hack.4,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     # Source without dsc_file entries
59     q = projectB.query("SELECT s.id, f.id, l.path, f.filename FROM source s, files f, location l WHERE NOT EXISTS (SELECT df.* FROM dsc_files df WHERE df.source = s.id) and f.id = s.file and l.id = f.location;");
60     ql = q.getresult();
61     projectB.query("BEGIN WORK;")
62     for i in ql:
63         source_id = i[0];
64         dsc_file_id = i[1];
65         dsc_filename = i[2] + i[3];
66         dsc_dir = os.path.dirname(i[3]);
67         # We get the .dsc for free
68         print "INSERT INTO dsc_files (source, file) VALUES (%s, %s)" % (source_id, dsc_file_id);
69         projectB.query("INSERT INTO dsc_files (source, file) VALUES (%s, %s)" % (source_id, dsc_file_id));
70         # Then work out the files.id of the other files
71         dsc = utils.parse_changes(dsc_filename, 0);
72         dsc_files = utils.build_file_list(dsc, 1);
73         for dsc_file in dsc_files.keys():
74             if dsc_file[-4:] != ".dsc":
75                 filename = dsc_dir + '/' + dsc_file;
76                 x = projectB.query("SELECT id FROM files WHERE filename = '%s'" % (filename));
77                 xl = x.getresult();
78                 if len(xl) != 1:
79                     # No?  probably s/woody/potato/ BS.. try again with ~ and only the filename
80                     x = projectB.query("SELECT id FROM files WHERE filename ~ '%s$'" % (utils.regex_safe(dsc_file)));
81                     xl = x.getresult();
82                     if len(xl) != 1:
83                         print filename
84                         print xl
85                         sys.exit(9);
86                 print "INSERT INTO dsc_files (source, file) VALUES (%s, %s)" % (source_id, xl[0][0]);
87                 projectB.query("INSERT INTO dsc_files (source, file) VALUES (%s, %s)" % (source_id, xl[0][0]));
88         
89     projectB.query("COMMIT WORK;");
90     
91     sys.exit(0);
92
93 #######################################################################################
94
95 if __name__ == '__main__':
96     main()
97
98 #       source_id = i[0];
99 #          source_name = i[1];
100 #          source_version = i[2];
101 #          print "SELECT df.file FROM dsc_files df, source s WHERE s.source = '%s' AND s.version = '%s' AND df.source = s.id;" % (source_name, source_version);
102 #          x = christina.query("SELECT df.file FROM dsc_files df, source s WHERE s.source = '%s' AND s.version = '%s' AND df.source = s.id;" % (source_name, source_version));
103 #          xl = x.getresult();
104 #          if len(xl) < 2 or len(xl) > 3:
105 #              print xl
106 #              continue;
107 #              #sys.exit(9);
108 #          for j in xl:
109 #              df_source = source_id;
110 #              print "SELECT filename, location FROM files WHERE id = %s;" % (j[0]);
111 #              x1 = christina.query("SELECT filename, location FROM files WHERE id = %s;" % (j[0]));
112 #              x1l = x1.getresult();
113 #              if len(x1l) != 1:
114 #                  print x1l
115 #                  sys.exit(9);
116 #              filename = x1l[0][0];
117 #              location = x1l[0][1];
118 #              print "SELECT id FROM files WHERE filename = '%s' AND location = %s;" % (filename, location);
119 #              x2 = projectB.query("SELECT id FROM files WHERE filename = '%s' AND location = %s;" % (filename, location));
120 #              x2l = x2.getresult();
121 #              if len(x2l) != 1:
122 #                  print x2l
123 #                  sys.exit(9);
124 #              df_file = x2l[0][0];
125 #              projectB.query("INSERT INTO dsc_files (source, file) VALUES (%s, %s);" % (df_source, df_file));
126 #              print "INSERT INTO dsc_files (source, file) VALUES (%s, %s);" % (df_source, df_file);