]> git.decadent.org.uk Git - dak.git/blob - cindy
lose second argument to open_file since we use default, change foo == [] to not foo.
[dak.git] / cindy
1 #!/usr/bin/env python
2
3 # Output override files for apt-ftparchive and indices/
4 # Copyright (C) 2000, 2001  James Troup <james@nocrew.org>
5 # $Id: cindy,v 1.5 2001-11-04 22:28:44 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 # X-Listening-To: Sanitarium / Master of the Puppets - Metallica
24
25 ################################################################################
26
27 import pg, sys, string
28 import utils, db_access, natalie
29 import apt_pkg;
30
31 ################################################################################
32
33 Cnf = None;
34 projectB = None;
35 override = {}
36
37 ################################################################################
38
39 def process(suite, component, type):
40     global override;
41     
42     suite_id = db_access.get_suite_id(suite);
43     if suite_id == -1:
44         utils.fubar("Suite '%s' not recognised." % (suite));
45
46     component_id = db_access.get_component_id(component);
47     if component_id == -1:
48         utils.fubar("Component '%s' not recognised." % (component));
49
50     type_id = db_access.get_override_type_id(type);
51     if type_id == -1:
52         utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type));
53     dsc_type_id = db_access.get_override_type_id("dsc");
54
55     if type == "deb" or type == "udeb":
56         packages = {};
57         q = projectB.query("SELECT DISTINCT b.package FROM binaries b, bin_associations ba WHERE b.id = ba.bin AND ba.suite = %s" % (suite_id));
58         for i in q.getresult():
59             packages[i[0]] = "";
60
61     src_packages = {};
62     q = projectB.query("SELECT DISTINCT s.source FROM source s, src_associations sa WHERE s.id = sa.source AND sa.suite = %s" % (suite_id));
63     for i in q.getresult():
64         src_packages[i[0]] = "";
65
66     q = projectB.query("SELECT package, priority, section, maintainer FROM override WHERE suite = %s AND component = %s AND type = %s" % (suite_id, component_id, type_id));
67     projectB.query("BEGIN WORK");
68     for i in q.getresult():
69         package = i[0];
70         if type == "deb" or type == "udeb":
71             if not packages.has_key(package):
72                 if not src_packages.has_key(package):
73                     print "DELETING: %s" % (package);
74                     #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
75                     #% (package, suite_id, component_id, type_id));
76                 else:
77                     print "MAKING SOURCE: %s" % (package);
78                     #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
79                     #% (package, suite_id, component_id, type_id));
80                     # Then if source doesn't already have a copy, insert it into source
81                     q = projectB.query("SELECT package FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, dsc_type_id));
82                     if not q.getresult():
83                         #projectB.query("INSERT INTO override (package, suite, component, priority, section, type, maintainer) VALUES ('%s', %s, %s, %s, %s, %s, '%s')" % (package, suite_id, component_id, i[1], i[2], dsc_type_id, i[3]));
84                         print "(nop)"
85         else: # dsc
86             if not src_packages.has_key(package):
87                 print "DELETING: %s" % (package);
88                 #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
89                 #% (package, suite_id, component_id, type_id));
90     projectB.query("COMMIT WORK");
91             
92
93 ################################################################################
94
95 def main ():
96     global Cnf, projectB, override;
97
98     apt_pkg.init();
99     
100     Cnf = apt_pkg.newConfiguration();
101     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
102     Arguments = [('D',"debug","Denise::Options::Debug", "IntVal"),
103                  ('h',"help","Denise::Options::Help"),
104                  ('V',"version","Denise::Options::Version")];
105     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
106
107     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
108     db_access.init(Cnf, projectB);
109
110     for suite in [ "stable", "unstable" ]:
111         print "Processing %s..." % (suite);
112         for component in Cnf.SubTree("Component").List():
113             if component == "mixed":
114                 continue; # Ick
115             for type in Cnf.SubTree("OverrideType").List():
116                 print "Processing %s [%s - %s]..." % (suite, component, type);
117                 process(suite, component, type);
118
119 #######################################################################################
120
121 if __name__ == '__main__':
122     main()
123