3 """ Remove obsolete .changes files from proposed-updates """
4 # Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008 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 ################################################################################
25 from daklib.dbconn import *
26 from daklib.config import Config
27 from daklib import utils
28 from daklib.regexes import re_isdeb, re_isadeb, re_issource, re_no_epoch
30 ################################################################################
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):
53 changes = utils.parse_changes(filename)
54 files = utils.build_file_list(changes)
56 utils.warn("Couldn't read changes file '%s'." % (filename))
58 num_files = len(files.keys())
59 for f in files.keys():
60 if re_isadeb.match(f):
66 print "BINARY: %s ==> %s_%s_%s" % (f, pkg, version, arch)
68 m = re_issource.match(f)
79 print "SOURCE: %s ==> %s_%s_%s" % (f, pkg, version, arch)
81 utils.fubar("unknown type, fix me")
82 if not pu.has_key(pkg):
84 utils.warn("%s doesn't seem to exist in %s?? (from %s [%s])" % (pkg, Options["suite"], f, filename))
86 if not pu[pkg].has_key(arch):
88 utils.warn("%s doesn't seem to exist for %s in %s?? (from %s [%s])" % (pkg, arch, Options["suite"], f, filename))
90 pu_version = re_no_epoch.sub('', pu[pkg][arch])
91 if pu_version == version:
92 if Options["verbose"]:
95 if Options["verbose"]:
96 print "%s: superseded, removing. [%s]" % (f, pu_version)
99 new_num_files = len(files.keys())
100 if new_num_files == 0:
101 print "%s: no files left, superseded by %s" % (filename, pu_version)
102 dest = cnf["Dir::Morgue"] + "/misc/"
103 if not Options["no-action"]:
104 utils.move(filename, dest)
105 elif new_num_files < num_files:
106 print "%s: lost files, MWAAP." % (filename)
108 if Options["verbose"]:
109 print "%s: ok" % (filename)
111 ################################################################################
113 def check_joey (filename):
116 f = utils.open_file(filename)
119 os.chdir("%s/dists/%s" % (cnf["Dir::Root"]), Options["suite"])
121 for line in f.readlines():
123 if line.find('install') != -1:
124 split_line = line.split()
125 if len(split_line) != 2:
126 utils.fubar("Parse error (not exactly 2 elements): %s" % (line))
127 install_type = split_line[0]
128 if install_type not in [ "install", "install-u", "sync-install" ]:
129 utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line))
130 changes_filename = split_line[1]
132 print "Processing %s..." % (changes_filename)
133 check_changes(changes_filename)
137 ################################################################################
142 q = DBConn().session().execute("""
143 SELECT b.package, b.version, a.arch_string
144 FROM bin_associations ba, binaries b, suite su, architecture a
145 WHERE b.id = ba.bin AND ba.suite = su.id
146 AND su.suite_name = :suite_name AND a.id = b.architecture
147 UNION SELECT s.source, s.version, 'source'
148 FROM src_associations sa, source s, suite su
149 WHERE s.id = sa.source AND sa.suite = su.id
150 AND su.suite_name = :suite_name
151 ORDER BY package, version, arch_string
152 """ % {'suite_name': Options["suite"]})
154 for i in q.fetchall():
158 if not pu.has_key(pkg):
160 pu[pkg][arch] = version
167 Arguments = [('d', "debug", "Clean-Proposed-Updates::Options::Debug"),
168 ('v', "verbose", "Clean-Proposed-Updates::Options::Verbose"),
169 ('h', "help", "Clean-Proposed-Updates::Options::Help"),
170 ('s', "suite", "Clean-Proposed-Updates::Options::Suite", "HasArg"),
171 ('n', "no-action", "Clean-Proposed-Updates::Options::No-Action"),]
172 for i in [ "debug", "verbose", "help", "no-action" ]:
173 if not cnf.has_key("Clean-Proposed-Updates::Options::%s" % (i)):
174 cnf["Clean-Proposed-Updates::Options::%s" % (i)] = ""
176 # suite defaults to proposed-updates
177 if not cnf.has_key("Clean-Proposed-Updates::Options::Suite"):
178 cnf["Clean-Proposed-Updates::Options::Suite"] = "proposed-updates"
180 arguments = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
181 Options = cnf.SubTree("Clean-Proposed-Updates::Options")
186 utils.fubar("need at least one package name as an argument.")
193 if f.endswith(".changes"):
195 elif f.endswith(".joey"):
198 utils.fubar("Unrecognised file type: '%s'." % (f))
200 #######################################################################################
202 if __name__ == '__main__':