]> git.decadent.org.uk Git - dak.git/blob - halle
read all configs when utils is imported, allowing utils to make use ofconfig values...
[dak.git] / halle
1 #!/usr/bin/env python
2
3 # Remove obsolete .changes files from proposed-updates
4 # Copyright (C) 2001  James Troup <james@nocrew.org>
5 # $Id: halle,v 1.3 2001-11-18 19:57:58 rmurray 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 import os, pg, re, sys, string
24 import utils, db_access
25 import apt_pkg, apt_inst;
26
27 ################################################################################
28
29 Cnf = None;
30 projectB = None;
31 pu = {};
32
33 re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).deb$");
34
35 ################################################################################
36
37
38 def check_changes (filename):
39     try:
40         changes = utils.parse_changes(filename, 0)
41         files = utils.build_file_list(changes, "");
42     except:
43         utils.warn("Couldn't read changes file '%s'." % (filename));
44         return;
45     num_files = len(files.keys());
46     for file in files.keys():
47         re_isadeb = re.compile (r".*\.u?deb$");
48
49         if utils.re_isadeb.match(file) != None:
50             m = re_isdeb.match(file);
51             pkg = m.group(1);
52             version = m.group(2);
53             arch = m.group(3);
54             if Options["debug"]:
55                 print "BINARY: %s ==> %s_%s_%s" % (file, pkg, version, arch);
56         else:
57             m = utils.re_issource.match(file)
58             if m != None:
59                 pkg = m.group(1);
60                 version = m.group(2);
61                 type = m.group(3);
62                 if type != "dsc":
63                     del files[file];
64                     num_files = num_files - 1;
65                     continue;
66                 arch = "source";
67                 if Options["debug"]:
68                     print "SOURCE: %s ==> %s_%s_%s" % (file, pkg, version, arch);
69             else:
70                 utils.fubar("unknown type, fix me");
71         if not pu.has_key(pkg):
72             utils.fubar("%s doesn't seem to exist in p-u?? (from %s [%s])" % (pkg, file, filename));
73         if not pu[pkg].has_key(arch):
74             utils.fubar("%s doesn't seem to exist for %s in p-u?? (from %s [%s])" % (pkg, arch, file, filename));
75         pu_version = utils.re_no_epoch.sub('', pu[pkg][arch]);
76         if pu_version == version:
77             if Options["verbose"]:
78                 print "%s: ok" % (file);
79         else:
80             if Options["verbose"]:
81                 print "%s: superseded, removing. [%s]" % (file, pu_version);
82             del files[file];
83
84     new_num_files = len(files.keys());
85     if new_num_files == 0:
86         print "%s: no files left, superseded by %s" % (filename, pu_version);
87         dest = Cnf["Dir::Morgue"] + "/misc/";
88         utils.move(filename, dest);
89     elif new_num_files < num_files:
90         print "%s: lost files, MWAAP." % (filename);
91     else:
92         if Options["verbose"]:
93             print "%s: ok" % (filename);
94
95 ################################################################################
96
97 def check_joey (filename):
98     file = utils.open_file(filename);
99
100     cwd = os.getcwd();
101     os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::RootDir"]));
102
103     for line in file.readlines():
104         line = line[:-1];
105         if string.find(line, 'install') != -1:
106             split_line = string.split(line);
107             install_type = split_line[0];
108             if [ "install", "install-u", "sync-install" ].count(install_type) == 0:
109                 utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line));
110             changes_filename = split_line[1]
111             if len(split_line) != 2:
112                 utils.fubar("Parse error (more than 2 elements): %s" % (line));
113             if Options["debug"]:
114                 print "Processing %s..." % (changes_filename);
115             check_changes(changes_filename);
116
117     os.chdir(cwd);
118
119 ################################################################################
120
121 def init_pu ():
122     global pu;
123
124     q = projectB.query("""
125 SELECT b.package, b.version, a.arch_string
126   FROM bin_associations ba, binaries b, suite su, architecture a
127   WHERE b.id = ba.bin AND ba.suite = su.id
128     AND su.suite_name = 'proposed-updates' AND a.id = b.architecture
129 UNION SELECT s.source, s.version, 'source'
130   FROM src_associations sa, source s, suite su
131   WHERE s.id = sa.source AND sa.suite = su.id
132     AND su.suite_name = 'proposed-updates'
133 ORDER BY package, version, arch_string;
134 """);
135     ql = q.getresult();
136     for i in ql:
137         pkg = i[0];
138         version = i[1];
139         arch = i[2];
140         if not pu.has_key(pkg):
141             pu[pkg] = {};
142         pu[pkg][arch] = version;
143
144 def main ():
145     global Cnf, projectB, Options;
146
147     Cnf = utils.get_conf()
148
149     Arguments = [('q',"quiet","Halle::Options::Quiet"),
150                  ('v',"verbose","Halle::Options::Verbose"),
151                  ('D',"debug","Halle::Options::Debug"),
152                  ('h',"help","Halle::Options::Help"),
153                  ('V',"version","Halle::Options::Version")];
154     for i in [ "quiet", "verbose", "help", "debug" ]:
155         if not Cnf.has_key("Halle::Options::%s" % (i)):
156             Cnf["Halle::Options::%s" % (i)] = "";
157
158     arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
159     Options = Cnf.SubTree("Halle::Options")
160
161     if Options["Help"]:
162         usage(0);
163     if not arguments:
164         utils.fubar("need at least one package name as an argument.");
165
166     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
167     db_access.init(Cnf, projectB);
168
169     init_pu();
170
171     for file in arguments:
172         if file[-8:] == ".changes":
173             check_changes(file);
174         elif file[-5:] == ".joey":
175             check_joey(file);
176         else:
177             utils.fubar("Unrecognised file type: '%s'." % (file));
178
179 #######################################################################################
180
181 if __name__ == '__main__':
182     main()
183