3 """ Manually reject packages for proprosed-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 ################################################################################
25 from daklib.dbconn import *
26 from daklib import daklog
27 from daklib.queue import Upload
28 from daklib import utils
29 from daklib.regexes import re_default_answer
31 ################################################################################
38 ################################################################################
40 def usage(exit_code=0):
41 print """Usage: dak reject-proposed-updates .CHANGES[...]
42 Manually reject the .CHANGES file(s).
44 -h, --help show this help and exit.
45 -m, --message=MSG use this message for the rejection.
46 -s, --no-mail don't send any mail."""
49 ################################################################################
52 global Cnf, Logger, Options
54 Cnf = utils.get_conf()
55 Arguments = [('h',"help","Reject-Proposed-Updates::Options::Help"),
56 ('m',"manual-reject","Reject-Proposed-Updates::Options::Manual-Reject", "HasArg"),
57 ('s',"no-mail", "Reject-Proposed-Updates::Options::No-Mail")]
58 for i in [ "help", "manual-reject", "no-mail" ]:
59 if not Cnf.has_key("Reject-Proposed-Updates::Options::%s" % (i)):
60 Cnf["Reject-Proposed-Updates::Options::%s" % (i)] = ""
62 arguments = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
64 Options = Cnf.SubTree("Reject-Proposed-Updates::Options")
68 utils.fubar("need at least one .changes filename as an argument.")
73 Logger = daklog.Logger(Cnf, "reject-proposed-updates")
75 bcc = "X-DAK: dak rejected-proposed-updates\nX-Katie: lauren $Revision: 1.4 $"
78 arg = utils.validate_changes_file_arg(arg)
80 os.chdir(Cnf["Suite::Proposed-Updates::CopyDotDak"])
85 if Cnf.has_key("Dinstall::Bcc"):
86 u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"])
88 u.Subst["__BCC__"] = bcc
95 prompt = "Manual reject, [S]kip, Quit ?"
99 while prompt.find(answer) == -1:
100 answer = utils.our_raw_input(prompt)
101 m = re_default_answer.search(prompt)
104 answer = answer[:1].upper()
107 aborted = reject(u, Options["Manual-Reject"])
117 ################################################################################
119 def reject (u, reject_message = ""):
122 changes_file = u.pkg.changes_file
124 # If we weren't given a manual rejection message, spawn an editor
125 # so the user can add one in...
126 if not reject_message:
127 (fd, temp_filename) = utils.temp_filename()
128 editor = os.environ.get("EDITOR","vi")
131 os.system("%s %s" % (editor, temp_filename))
133 reject_message = "".join(f.readlines())
135 print "Reject message:"
136 print utils.prefix_multi_line_string(reject_message," ", include_blank_lines=1)
137 prompt = "[R]eject, Edit, Abandon, Quit ?"
139 while prompt.find(answer) == -1:
140 answer = utils.our_raw_input(prompt)
141 m = re_default_answer.search(prompt)
144 answer = answer[:1].upper()
145 os.unlink(temp_filename)
153 # Reject the .changes file
154 u.force_reject([changes_file])
156 # Setup the .reason file
157 reason_filename = changes_file[:-8] + ".reason"
158 reject_filename = Cnf["Dir::Queue::Reject"] + '/' + reason_filename
160 # If we fail here someone is probably trying to exploit the race
161 # so let's just raise an exception ...
162 if os.path.exists(reject_filename):
163 os.unlink(reject_filename)
164 reject_fd = os.open(reject_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644)
166 # Build up the rejection email
167 user_email_address = utils.whoami() + " <%s>" % (Cnf["Dinstall::MyAdminAddress"])
169 u.Subst["__REJECTOR_ADDRESS__"] = user_email_address
170 u.Subst["__MANUAL_REJECT_MESSAGE__"] = reject_message
171 u.Subst["__STABLE_REJECTOR__"] = Cnf["Reject-Proposed-Updates::StableRejector"]
172 u.Subst["__STABLE_MAIL__"] = Cnf["Reject-Proposed-Updates::StableMail"]
173 u.Subst["__MORE_INFO_URL__"] = Cnf["Reject-Proposed-Updates::MoreInfoURL"]
174 u.Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"]
175 reject_mail_message = utils.TemplateSubst(u.Subst, Cnf["Dir::Templates"]+"/reject-proposed-updates.rejected")
177 # Write the rejection email out as the <foo>.reason file
178 os.write(reject_fd, reject_mail_message)
181 session = DBConn().session()
183 # Remove the packages from proposed-updates
184 suite_name = 'proposed-updates'
186 # Remove files from proposed-updates suite
187 for f in files.keys():
188 if files[f]["type"] == "dsc":
189 package = dsc["source"]
190 version = dsc["version"]; # NB: not files[f]["version"], that has no epoch
192 source = get_sources_from_name(package, version, session=session)
194 utils.fubar("reject: Couldn't find %s_%s in source table." % (package, version))
198 for sa in source.srcassociations:
199 if sa.suite.suite_name == suite_name:
202 elif files[f]["type"] == "deb":
203 package = files[f]["package"]
204 version = files[f]["version"]
205 architecture = files[f]["architecture"]
207 binary = get_binaries_from_name(package, version [architecture, 'all'])
209 # Horrible hack to work around partial replacement of
210 # packages with newer versions (from different source
211 # packages). This, obviously, should instead check for a
212 # newer version of the package and only do the
213 # warn&continue thing if it finds one.
215 utils.warn("reject: Couldn't find %s_%s_%s in binaries table." % (package, version, architecture))
217 for ba in binary[0].binassociations:
218 if ba.suite.suite_name == suite_name:
223 # Send the rejection mail if appropriate
224 if not Options["No-Mail"]:
225 utils.send_mail(reject_mail_message)
227 # Finally remove the .dak file
228 dot_dak_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyDotDak"], os.path.basename(changes_file[:-8]+".dak"))
229 os.unlink(dot_dak_file)
231 Logger.log(["rejected", changes_file])
234 ################################################################################
236 if __name__ == '__main__':