]> git.decadent.org.uk Git - dak.git/blob - jenna
Initial revision
[dak.git] / jenna
1 #!/usr/bin/env python
2
3 # Generate file list which is then fed to apt-ftparchive to generate Packages and Sources files
4 # Copyright (C) 2000  James Troup <james@nocrew.org>
5 # $Id: jenna,v 1.1 2000-11-24 00:20:11 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 # BTAF: "GOD *DAMMIT*!!  What the FUCK happened to my free will??"
24 #
25 # -- http://www.angryflower.com/timelo.gif
26
27 #######################################################################################
28
29 import pg, string, os, sys
30 import apt_pkg
31 import db_access, utils
32
33 projectB = None
34 Cnf = None
35
36 def generate_src_list(suite, component, output):
37     sources = {}
38
39     suite_id = db_access.get_suite_id(suite);
40     
41     if component == "-":
42         q = projectB.query("SELECT s.source, s.version, l.path, f.filename, s.id FROM source s, src_associations sa, location l, files f WHERE sa.source = s.id AND sa.suite = '%d' AND l.id = f.location AND s.file = f.id"
43                            % (suite_id));
44     else:
45         q = projectB.query("SELECT s.source, s.version, l.path, f.filename, s.id FROM source s, src_associations sa, location l, component c, files f WHERE lower(c.name) = '%s' AND (c.id = l.component OR l.component = NULL) AND sa.source = s.id AND sa.suite = '%d' AND l.id = f.location AND s.file = f.id"
46                            % (component, suite_id));
47     entries = q.getresult();
48     for entry in entries:
49         source = entry[0]
50         version = entry[1]
51         filename = entry[2]+entry[3];
52         id = entry[4]
53         add_new = 0
54         if os.path.exists(filename):
55             if sources.has_key(source):
56                 if apt_pkg.VersionCompare(sources[source]["version"], version) == -1:
57                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
58                         print "deleting %s (%s) in favour of newer version %s..." % (source, sources[source]["version"], version)
59                         projectB.query("DELETE FROM src_associations WHERE source = %s AND suite = %d" % (sources[source]["id"], suite_id))
60                     else:
61                         if Cnf.Find("Jenna::Options::Verbose"):
62                             print "[untouchable] would delete %s (%s) in favour of newer version %s..." % (source, sources[source]["version"], version)
63                     sources[source] = { "id": id, "version": version, "filename": filename }
64                 else:
65                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
66                         print "deleting %s (%s) in favour of newer version %s..." % (source, version, sources[source]["version"])
67                         projectB.query("DELETE FROM src_associations WHERE source = %s AND suite = %d" % (id, suite_id))
68                     else:
69                         if Cnf.Find("Jenna::Options::Verbose"):
70                             print "[untouchable] would delete %s (%s) in favour of newer version %s..." % (source, version, sources[source]["version"])
71             else:
72                 sources[source] = { "id": id, "version": version, "filename": filename }
73         else:
74             if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
75                 sys.stderr.write("WARNING: deleting %s because it doesn't exist.\n" % (filename));
76                 projectB.query("DELETE FROM src_associations WHERE source = %s AND suite = %d" % (id, suite_id))
77
78     # Write the list of files out
79     source_keys = sources.keys();
80     source_keys.sort();
81     for source in source_keys:
82         output.write(sources[source]["filename"]+'\n')
83     
84 def generate_bin_list(suite, component, architecture, output, type):
85     packages = {}
86
87     suite_id = db_access.get_suite_id(suite);
88     
89     if component == "-":
90         q = projectB.query("SELECT b.package, b.version, l.path, f.filename, b.id FROM architecture a, binaries b, bin_associations ba, location l, files f WHERE ( a.arch_string = '%s' OR a.arch_string = 'all' ) AND a.id = b.architecture AND ba.bin = b.id AND ba.suite = '%d' AND l.id = f.location AND b.file = f.id AND b.type = '%s'" % (architecture, suite_id, type));
91     else:
92         q = projectB.query("SELECT b.package, b.version, l.path, f.filename, b.id FROM architecture a, binaries b, bin_associations ba, location l, component c, files f WHERE lower(c.name) = '%s' AND (c.id = l.component OR l.component = NULL) AND (a.arch_string = '%s' OR a.arch_string = 'all') AND a.id = b.architecture AND ba.bin = b.id AND ba.suite = '%d' AND l.id = f.location AND b.file = f.id AND b.type = '%s'" % (component, architecture, suite_id, type));
93     entries = q.getresult();
94     for entry in entries:
95         package = entry[0]
96         version = entry[1]
97         filename = entry[2]+entry[3];
98         id = entry[4]
99         add_new = 0
100         
101         # Hack to handle screwed up sid distro [FIXME: this may have issues, remove ASAP]
102         if not os.path.exists(filename):
103             sid_filename = string.replace(filename, "/woody/", "/potato/");
104             if os.path.exists(sid_filename):
105                 filename = sid_filename;
106                 
107         if os.path.exists(filename):
108             if packages.has_key(package):
109                 if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
110                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
111                         print "deleting %s (%s) in favour of newer version %s..." % (package, packages[package]["version"], version)
112                         projectB.query("DELETE FROM bin_associations WHERE bin = %s AND suite = %d" % (packages[package]["id"], suite_id))
113                     else:
114                         if Cnf.Find("Jenna::Options::Verbose"):
115                             print "[untouchable] would delete %s (%s) in favour of newer version %s..." % (package, packages[package]["version"], version)
116                     packages[package] = { "id": id, "version": version, "filename": filename }
117                 else:
118                     if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
119                         print "deleting %s (%s) in favour of newer version %s..." % (package, version, packages[package]["version"])
120                         projectB.query("DELETE FROM bin_associations WHERE bin = %s AND suite = %d" % (id, suite_id))
121                     else:
122                         if Cnf.Find("Jenna::Options::Verbose"):
123                             print "[untochable] would delete %s (%s) in favour of newer version %s..." % (package, version, packages[package]["version"])
124             else:
125                 packages[package] = { "id": id, "version": version, "filename": filename }
126         else:
127             if not Cnf.Find("Suite::%s::Untouchable" % (suite)):
128                 sys.stderr.write("WARNING: deleting %s because it doesn't exist.\n" % (filename));
129                 projectB.query("DELETE FROM bin_associations WHERE bin = %s AND suite = %d" % (id, suite_id))
130
131     # Write the list of files out
132     package_keys = packages.keys();
133     package_keys.sort();
134     for package in package_keys:
135         output.write(packages[package]["filename"]+'\n')
136     
137     
138
139 def main():
140     global Cnf, projectB;
141     
142     projectB = pg.connect('projectb', 'localhost');
143     
144     apt_pkg.init();
145     
146     Cnf = apt_pkg.newConfiguration();
147     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
148
149     Arguments = [('a',"architecture","Jenna::Options::Architecture", "HasArg"),
150                  ('c',"component","Jenna::Options::Component", "HasArg"),
151                  ('d',"debug","Jenna::Options::Debug", "IntVal"),
152                  ('h',"help","Jenna::Options::Help"),
153                  ('s',"suite", "Jenna::Options::Suite", "HasArg"),
154                  ('v',"verbose","Jenna::Options::Verbose"),
155                  ('V',"version","Jenna::Options::Version")];
156
157     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
158
159     db_access.init(Cnf, projectB);
160
161     if Cnf["Jenna::Options::Suite"] == "":
162         Cnf["Jenna::Options::Suite"] = string.join(Cnf.SubTree("Suite").List());
163     for suite in string.split(Cnf["Jenna::Options::Suite"]):
164         suite = string.lower(suite);
165         components = Cnf["Jenna::Options::Component"];
166         if not Cnf.has_key("Suite::%s::Components" % (suite)):
167             components = "-";
168         if components == "":
169             components = string.join(Cnf.SubTree("Suite::%s::Components" % (suite)).List());
170         for component in string.split(components):
171             component = string.lower(component)
172             architectures = Cnf["Jenna::Options::Architecture"];
173             if architectures == "":
174                 architectures = string.join(Cnf.SubTree("Suite::%s::Architectures" % (suite)).List());
175             for architecture in string.split(architectures):
176                 architecture = string.lower(architecture)
177                 if architecture == "all":
178                     continue
179                 if architecture == "source":
180                     print "Processing dists/%s/%s/%s..." % (suite, component, architecture);
181                     output = utils.open_file("%s/%s_%s_%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w")
182                     generate_src_list(suite, component, output);
183                     output.close();
184                 else:
185                     print "Processing dists/%s/%s/binary-%s..." % (suite, component, architecture);
186                     output = utils.open_file("%s/%s_%s_binary-%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w");
187                     generate_bin_list(suite, component, architecture, output, "deb");
188                     output.close();
189                     if component == "main": # FIXME: must be a cleaner way to say debian-installer is main only?
190                         print "Processing dists/%s/%s/debian-installer/binary-%s..." % (suite,component, architecture);
191                         output = utils.open_file("%s/%s_%s_debian-installer_binary-%s.list" % (Cnf["Dir::ListsDir"], suite, component, architecture), "w");
192                         generate_bin_list(suite, component, architecture, output, "udeb");
193                         output.close();
194
195 if __name__ == '__main__':
196     main()
197