3 # Remove obsolete .changes files from proposed-updates
4 # Copyright (C) 2001, 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
22 import os, pg, re, sys
23 import dak.lib.utils, dak.lib.database
26 ################################################################################
33 re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).u?deb$")
35 ################################################################################
37 def usage (exit_code=0):
38 print """Usage: dak clean-proposed-updates [OPTION] <CHANGES FILE | ADMIN FILE>[...]
39 Remove obsolete changes files from proposed-updates.
41 -v, --verbose be more verbose about what is being done
42 -h, --help show this help and exit
44 Need either changes files or an admin.txt file with a '.joey' suffix."""
47 ################################################################################
49 def check_changes (filename):
51 changes = dak.lib.utils.parse_changes(filename)
52 files = dak.lib.utils.build_file_list(changes)
54 dak.lib.utils.warn("Couldn't read changes file '%s'." % (filename))
56 num_files = len(files.keys())
57 for file in files.keys():
58 if dak.lib.utils.re_isadeb.match(file):
59 m = re_isdeb.match(file)
64 print "BINARY: %s ==> %s_%s_%s" % (file, pkg, version, arch)
66 m = dak.lib.utils.re_issource.match(file)
77 print "SOURCE: %s ==> %s_%s_%s" % (file, pkg, version, arch)
79 dak.lib.utils.fubar("unknown type, fix me")
80 if not pu.has_key(pkg):
82 dak.lib.utils.warn("%s doesn't seem to exist in p-u?? (from %s [%s])" % (pkg, file, filename))
84 if not pu[pkg].has_key(arch):
86 dak.lib.utils.warn("%s doesn't seem to exist for %s in p-u?? (from %s [%s])" % (pkg, arch, file, filename))
88 pu_version = dak.lib.utils.re_no_epoch.sub('', pu[pkg][arch])
89 if pu_version == version:
90 if Options["verbose"]:
91 print "%s: ok" % (file)
93 if Options["verbose"]:
94 print "%s: superseded, removing. [%s]" % (file, pu_version)
97 new_num_files = len(files.keys())
98 if new_num_files == 0:
99 print "%s: no files left, superseded by %s" % (filename, pu_version)
100 dest = Cnf["Dir::Morgue"] + "/misc/"
101 dak.lib.utils.move(filename, dest)
102 elif new_num_files < num_files:
103 print "%s: lost files, MWAAP." % (filename)
105 if Options["verbose"]:
106 print "%s: ok" % (filename)
108 ################################################################################
110 def check_joey (filename):
111 file = dak.lib.utils.open_file(filename)
114 os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"]))
116 for line in file.readlines():
118 if line.find('install') != -1:
119 split_line = line.split()
120 if len(split_line) != 2:
121 dak.lib.utils.fubar("Parse error (not exactly 2 elements): %s" % (line))
122 install_type = split_line[0]
123 if install_type not in [ "install", "install-u", "sync-install" ]:
124 dak.lib.utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line))
125 changes_filename = split_line[1]
127 print "Processing %s..." % (changes_filename)
128 check_changes(changes_filename)
132 ################################################################################
137 q = projectB.query("""
138 SELECT b.package, b.version, a.arch_string
139 FROM bin_associations ba, binaries b, suite su, architecture a
140 WHERE b.id = ba.bin AND ba.suite = su.id
141 AND su.suite_name = 'proposed-updates' AND a.id = b.architecture
142 UNION SELECT s.source, s.version, 'source'
143 FROM src_associations sa, source s, suite su
144 WHERE s.id = sa.source AND sa.suite = su.id
145 AND su.suite_name = 'proposed-updates'
146 ORDER BY package, version, arch_string
153 if not pu.has_key(pkg):
155 pu[pkg][arch] = version
158 global Cnf, projectB, Options
160 Cnf = dak.lib.utils.get_conf()
162 Arguments = [('d', "debug", "Clean-Proposed-Updates::Options::Debug"),
163 ('v',"verbose","Clean-Proposed-Updates::Options::Verbose"),
164 ('h',"help","Clean-Proposed-Updates::Options::Help")]
165 for i in [ "debug", "verbose", "help" ]:
166 if not Cnf.has_key("Clean-Proposed-Updates::Options::%s" % (i)):
167 Cnf["Clean-Proposed-Updates::Options::%s" % (i)] = ""
169 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
170 Options = Cnf.SubTree("Clean-Proposed-Updates::Options")
175 dak.lib.utils.fubar("need at least one package name as an argument.")
177 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
178 dak.lib.database.init(Cnf, projectB)
182 for file in arguments:
183 if file.endswith(".changes"):
185 elif file.endswith(".joey"):
188 dak.lib.utils.fubar("Unrecognised file type: '%s'." % (file))
190 #######################################################################################
192 if __name__ == '__main__':