]> git.decadent.org.uk Git - dak.git/blob - contrib/hack.5
sync
[dak.git] / contrib / hack.5
1 #!/usr/bin/env python
2
3 # ???
4 # Copyright (C) 2000, 2001  James Troup <james@nocrew.org>
5 # $Id: hack.5,v 1.1 2001-05-17 01:01:51 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, re
31 import utils, db_access
32 import apt_pkg;
33
34 ################################################################################
35
36 Cnf = None;
37 projectB = None;
38
39 re_parse_bin_filename = re.compile(r"(.+?)_(.+?)_(.+?)\.(.+?)")
40 re_parse_src_filename = re.compile(r"(.+?)_(.+?)\.dsc")
41
42 ################################################################################
43
44 def main ():
45     global Cnf, projectB, db_files, waste, excluded;
46
47     apt_pkg.init();
48     
49     Cnf = apt_pkg.newConfiguration();
50     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
51
52     Arguments = [('d',"debug","Christina::Options::Debug", "IntVal"),
53                  ('h',"help","Christina::Options::Help"),
54                  ('v',"version","Christina::Options::Version")];
55
56     changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
57     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
58     db_access.init(Cnf, projectB);
59
60     for changes_file in changes_files:
61         #print changes_file
62         changes = utils.parse_changes(changes_file, 0)
63         files = utils.build_file_list(changes, "");
64         for file in files.keys():
65             if file[-4:] == ".deb":
66                 m = re_parse_bin_filename.match(file)
67                 package = m.group(1);
68                 version = m.group(2);
69                 architecture = m.group(3);
70                 type = m.group(4)
71                 q = projectB.query("SELECT b.id FROM binaries b, bin_associations ba, architecture a WHERE b.id = ba.bin AND ba.suite = 3 AND b.package = '%s' AND b.version = '%s' AND a.id = b.architecture AND a.arch_string = '%s'" % (package, version, architecture));
72                 ql = q.getresult();
73                 if len(ql) == 0:
74                     #print "[MISSING] Package: %s, version: %s, architecture: %s" % (package, version, architecture);
75                     foo = 0;
76                 elif len(ql) == 1:
77                     id = ql[0][0];
78                     print "DELETE FROM bin_associations WHERE bin = %s AND suite = 3;" % (id);
79                     projectB.query("DELETE FROM bin_associations WHERE bin = %s AND suite = 3;" % (id));
80                     #print "[%s] Package: %s, version: %s, architecture: %s" % (id, package, version, architecture);
81                 else:
82                     print "[FUBAR]"
83
84             elif file[-4:] == ".dsc":
85                 m = re_parse_src_filename.match(file)
86                 package = m.group(1);
87                 version = m.group(2);
88                 q = projectB.query("SELECT s.id FROM source s, src_associations sa WHERE s.id = sa.source AND sa.suite = 3 AND s.source = '%s' AND s.version = '%s'" % (package, version));
89                 ql = q.getresult();
90                 if len(ql) == 0:
91                     #print "[MISSING] Package: %s, version: %s, architecture: source" % (package, version);
92                     foo = 0;
93                 elif len(ql) == 1:
94                     id = ql[0][0];
95                     print "DELETE FROM src_associations WHERE source = %s AND suite = 3;" % (id);
96                     projectB.query("DELETE FROM src_associations WHERE source = %s AND suite = 3;" % (id));
97                     #print "[%s] Package: %s, version: %s, architecture: source" % (id, package, version);
98                 else:
99                     print "[FUBAR]"
100
101 #######################################################################################
102
103 if __name__ == '__main__':
104     main()
105