3 # Remove obsolete .changes files from proposed-updates
4 # Copyright (C) 2001, 2002, 2003, 2004 James Troup <james@nocrew.org>
5 # $Id: halle,v 1.12 2004-03-11 00:20:51 troup Exp $
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.
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.
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
21 ################################################################################
23 import os, pg, re, sys;
24 import utils, db_access;
27 ################################################################################
34 re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).deb$");
36 ################################################################################
38 def usage (exit_code=0):
39 print """Usage: halle [OPTION] <CHANGES FILE | ADMIN FILE>[...]
40 Remove obsolete changes files from proposed-updates.
42 -v, --verbose be more verbose about what is being done
43 -h, --help show this help and exit
45 Need either changes files or an admin.txt file with a '.joey' suffix."""
48 ################################################################################
50 def check_changes (filename):
52 changes = utils.parse_changes(filename);
53 files = utils.build_file_list(changes);
55 utils.warn("Couldn't read changes file '%s'." % (filename));
57 num_files = len(files.keys());
58 for file in files.keys():
59 if utils.re_isadeb.match(file):
60 m = re_isdeb.match(file);
65 print "BINARY: %s ==> %s_%s_%s" % (file, pkg, version, arch);
67 m = utils.re_issource.match(file)
78 print "SOURCE: %s ==> %s_%s_%s" % (file, pkg, version, arch);
80 utils.fubar("unknown type, fix me");
81 if not pu.has_key(pkg):
83 utils.warn("%s doesn't seem to exist in p-u?? (from %s [%s])" % (pkg, file, filename));
85 if not pu[pkg].has_key(arch):
87 utils.warn("%s doesn't seem to exist for %s in p-u?? (from %s [%s])" % (pkg, arch, file, filename));
89 pu_version = utils.re_no_epoch.sub('', pu[pkg][arch]);
90 if pu_version == version:
91 if Options["verbose"]:
92 print "%s: ok" % (file);
94 if Options["verbose"]:
95 print "%s: superseded, removing. [%s]" % (file, pu_version);
98 new_num_files = len(files.keys());
99 if new_num_files == 0:
100 print "%s: no files left, superseded by %s" % (filename, pu_version);
101 dest = Cnf["Dir::Morgue"] + "/misc/";
102 utils.move(filename, dest);
103 elif new_num_files < num_files:
104 print "%s: lost files, MWAAP." % (filename);
106 if Options["verbose"]:
107 print "%s: ok" % (filename);
109 ################################################################################
111 def check_joey (filename):
112 file = utils.open_file(filename);
115 os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"]));
117 for line in file.readlines():
118 line = line.rstrip();
119 if line.find('install') != -1:
120 split_line = line.split();
121 if len(split_line) != 2:
122 utils.fubar("Parse error (not exactly 2 elements): %s" % (line));
123 install_type = split_line[0];
124 if install_type not in [ "install", "install-u", "sync-install" ]:
125 utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line));
126 changes_filename = split_line[1]
128 print "Processing %s..." % (changes_filename);
129 check_changes(changes_filename);
133 ################################################################################
138 q = projectB.query("""
139 SELECT b.package, b.version, a.arch_string
140 FROM bin_associations ba, binaries b, suite su, architecture a
141 WHERE b.id = ba.bin AND ba.suite = su.id
142 AND su.suite_name = 'proposed-updates' AND a.id = b.architecture
143 UNION SELECT s.source, s.version, 'source'
144 FROM src_associations sa, source s, suite su
145 WHERE s.id = sa.source AND sa.suite = su.id
146 AND su.suite_name = 'proposed-updates'
147 ORDER BY package, version, arch_string;
154 if not pu.has_key(pkg):
156 pu[pkg][arch] = version;
159 global Cnf, projectB, Options;
161 Cnf = utils.get_conf()
163 Arguments = [('d', "debug", "Halle::Options::Debug"),
164 ('v',"verbose","Halle::Options::Verbose"),
165 ('h',"help","Halle::Options::Help")];
166 for i in [ "debug", "verbose", "help" ]:
167 if not Cnf.has_key("Halle::Options::%s" % (i)):
168 Cnf["Halle::Options::%s" % (i)] = "";
170 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
171 Options = Cnf.SubTree("Halle::Options")
176 utils.fubar("need at least one package name as an argument.");
178 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
179 db_access.init(Cnf, projectB);
183 for file in arguments:
184 if file.endswith(".changes"):
186 elif file.endswith(".joey"):
189 utils.fubar("Unrecognised file type: '%s'." % (file));
191 #######################################################################################
193 if __name__ == '__main__':