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 ################################################################################
23 import dak.lib.database, dak.lib.queue, dak.lib.logging, dak.lib.utils
26 ################################################################################
35 ################################################################################
37 def usage(exit_code=0):
38 print """Usage: dak reject-proposed-updates .CHANGES[...]
39 Manually reject the .CHANGES file(s).
41 -h, --help show this help and exit.
42 -m, --message=MSG use this message for the rejection.
43 -s, --no-mail don't send any mail."""
46 ################################################################################
49 global Cnf, Logger, Options, projectB, Upload
51 Cnf = dak.lib.utils.get_conf()
52 Arguments = [('h',"help","Reject-Proposed-Updates::Options::Help"),
53 ('m',"manual-reject","Reject-Proposed-Updates::Options::Manual-Reject", "HasArg"),
54 ('s',"no-mail", "Reject-Proposed-Updates::Options::No-Mail")]
55 for i in [ "help", "manual-reject", "no-mail" ]:
56 if not Cnf.has_key("Reject-Proposed-Updates::Options::%s" % (i)):
57 Cnf["Reject-Proposed-Updates::Options::%s" % (i)] = ""
59 arguments = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
61 Options = Cnf.SubTree("Reject-Proposed-Updates::Options")
65 dak.lib.utils.fubar("need at least one .changes filename as an argument.")
67 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
68 dak.lib.database.init(Cnf, projectB)
70 Upload = dak.lib.queue.Upload(Cnf)
71 Logger = Upload.Logger = dak.lib.logging.Logger(Cnf, "reject-proposed-updates")
73 bcc = "X-DAK: dak rejected-proposed-updates\nX-Katie: this header is obsolete"
74 if Cnf.has_key("Dinstall::Bcc"):
75 Upload.Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"])
77 Upload.Subst["__BCC__"] = bcc
80 arg = dak.lib.utils.validate_changes_file_arg(arg)
81 Upload.pkg.changes_file = arg
84 os.chdir(Cnf["Suite::Proposed-Updates::CopyDotDak"])
91 prompt = "Manual reject, [S]kip, Quit ?"
95 while prompt.find(answer) == -1:
96 answer = dak.lib.utils.our_raw_input(prompt)
97 m = dak.lib.queue.re_default_answer.search(prompt)
100 answer = answer[:1].upper()
103 aborted = reject(Options["Manual-Reject"])
113 ################################################################################
115 def reject (reject_message = ""):
116 files = Upload.pkg.files
118 changes_file = Upload.pkg.changes_file
120 # If we weren't given a manual rejection message, spawn an editor
121 # so the user can add one in...
122 if not reject_message:
123 temp_filename = dak.lib.utils.temp_filename()
124 editor = os.environ.get("EDITOR","vi")
127 os.system("%s %s" % (editor, temp_filename))
128 file = dak.lib.utils.open_file(temp_filename)
129 reject_message = "".join(file.readlines())
131 print "Reject message:"
132 print dak.lib.utils.prefix_multi_line_string(reject_message," ", include_blank_lines=1)
133 prompt = "[R]eject, Edit, Abandon, Quit ?"
135 while prompt.find(answer) == -1:
136 answer = dak.lib.utils.our_raw_input(prompt)
137 m = dak.lib.queue.re_default_answer.search(prompt)
140 answer = answer[:1].upper()
141 os.unlink(temp_filename)
149 # Reject the .changes file
150 Upload.force_reject([changes_file])
152 # Setup the .reason file
153 reason_filename = changes_file[:-8] + ".reason"
154 reject_filename = Cnf["Dir::Queue::Reject"] + '/' + reason_filename
156 # If we fail here someone is probably trying to exploit the race
157 # so let's just raise an exception ...
158 if os.path.exists(reject_filename):
159 os.unlink(reject_filename)
160 reject_fd = os.open(reject_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644)
162 # Build up the rejection email
163 user_email_address = dak.lib.utils.whoami() + " <%s>" % (Cnf["Dinstall::MyAdminAddress"])
165 Upload.Subst["__REJECTOR_ADDRESS__"] = user_email_address
166 Upload.Subst["__MANUAL_REJECT_MESSAGE__"] = reject_message
167 Upload.Subst["__STABLE_REJECTOR__"] = Cnf["Reject-Proposed-Updates::StableRejector"]
168 Upload.Subst["__MORE_INFO_URL__"] = Cnf["Reject-Proposed-Updates::MoreInfoURL"]
169 Upload.Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"]
170 reject_mail_message = dak.lib.utils.TemplateSubst(Upload.Subst,Cnf["Dir::Templates"]+"/reject-proposed-updates.rejected")
172 # Write the rejection email out as the <foo>.reason file
173 os.write(reject_fd, reject_mail_message)
176 # Remove the packages from proposed-updates
177 suite_id = dak.lib.database.get_suite_id('proposed-updates')
179 projectB.query("BEGIN WORK")
180 # Remove files from proposed-updates suite
181 for file in files.keys():
182 if files[file]["type"] == "dsc":
183 package = dsc["source"]
184 version = dsc["version"]; # NB: not files[file]["version"], that has no epoch
185 q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version))
188 dak.lib.utils.fubar("reject: Couldn't find %s_%s in source table." % (package, version))
190 projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id))
191 elif files[file]["type"] == "deb":
192 package = files[file]["package"]
193 version = files[file]["version"]
194 architecture = files[file]["architecture"]
195 q = projectB.query("SELECT b.id FROM binaries b, architecture a WHERE b.package = '%s' AND b.version = '%s' AND (a.arch_string = '%s' OR a.arch_string = 'all') AND b.architecture = a.id" % (package, version, architecture))
198 # Horrible hack to work around partial replacement of
199 # packages with newer versions (from different source
200 # packages). This, obviously, should instead check for a
201 # newer version of the package and only do the
202 # warn&continue thing if it finds one.
204 dak.lib.utils.warn("reject: Couldn't find %s_%s_%s in binaries table." % (package, version, architecture))
207 projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id))
208 projectB.query("COMMIT WORK")
210 # Send the rejection mail if appropriate
211 if not Options["No-Mail"]:
212 dak.lib.utils.send_mail(reject_mail_message)
214 # Finally remove the .dak file
215 dot_dak_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyDotDak"], os.path.basename(changes_file[:-8]+".dak"))
216 os.unlink(dot_dak_file)
218 Logger.log(["rejected", changes_file])
221 ################################################################################
223 if __name__ == '__main__':