3 # Manually reject packages for proprosed-updates
4 # Copyright (C) 2001, 2002, 2003 James Troup <james@nocrew.org>
5 # $Id: lauren,v 1.3 2003-11-20 02:37:25 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, sys, tempfile;
24 import db_access, katie, logging, utils;
27 ################################################################################
30 lauren_version = "$Revision: 1.3 $";
38 ################################################################################
40 def usage(exit_code=0):
41 print """Usage: lauren .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, projectB, Katie;
54 Cnf = utils.get_conf();
55 Arguments = [('h',"help","Lauren::Options::Help"),
56 ('m',"manual-reject","Lauren::Options::Manual-Reject", "HasArg"),
57 ('s',"no-mail", "Lauren::Options::No-Mail")];
58 for i in [ "help", "manual-reject", "no-mail" ]:
59 if not Cnf.has_key("Lauren::Options::%s" % (i)):
60 Cnf["Lauren::Options::%s" % (i)] = "";
62 arguments = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
64 Options = Cnf.SubTree("Lauren::Options");
68 utils.fubar("need at least one .changes filename as an argument.");
70 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
71 db_access.init(Cnf, projectB);
73 Katie = katie.Katie(Cnf);
74 Logger = Katie.Logger = logging.Logger(Cnf, "lauren");
76 bcc = "X-Katie: lauren %s" % (lauren_version);
77 if Cnf.has_key("Dinstall::Bcc"):
78 Katie.Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"]);
80 Katie.Subst["__BCC__"] = bcc;
83 arg = utils.validate_changes_file_arg(arg);
84 Katie.pkg.changes_file = arg;
87 os.chdir(Cnf["Suite::Proposed-Updates::CopyKatie"]);
94 prompt = "Manual reject, [S]kip, Quit ?";
98 while prompt.find(answer) == -1:
99 answer = utils.our_raw_input(prompt);
100 m = katie.re_default_answer.search(prompt);
103 answer = answer[:1].upper()
106 aborted = reject(Options["Manual-Reject"]);
116 ################################################################################
118 def reject (reject_message = ""):
119 files = Katie.pkg.files;
121 changes_file = Katie.pkg.changes_file;
123 # If we weren't given a manual rejection message, spawn an editor
124 # so the user can add one in...
125 if not reject_message:
126 temp_filename = tempfile.mktemp();
127 fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
129 editor = os.environ.get("EDITOR","vi")
132 os.system("%s %s" % (editor, temp_filename))
133 file = utils.open_file(temp_filename);
134 reject_message = "".join(file.readlines());
136 print "Reject message:";
137 print utils.prefix_multi_line_string(reject_message," ", include_blank_lines=1);
138 prompt = "[R]eject, Edit, Abandon, Quit ?"
140 while prompt.find(answer) == -1:
141 answer = utils.our_raw_input(prompt);
142 m = katie.re_default_answer.search(prompt);
145 answer = answer[:1].upper();
146 os.unlink(temp_filename);
154 # Reject the .changes file
155 Katie.force_reject([changes_file]);
157 # Setup the .reason file
158 reason_filename = changes_file[:-8] + ".reason";
159 reject_filename = Cnf["Dir::Queue::Reject"] + '/' + reason_filename;
161 # If we fail here someone is probably trying to exploit the race
162 # so let's just raise an exception ...
163 if os.path.exists(reject_filename):
164 os.unlink(reject_filename);
165 reject_fd = os.open(reject_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644);
167 # Build up the rejection email
168 user_email_address = utils.whoami() + " <%s>" % (Cnf["Dinstall::MyAdminAddress"]);
170 Katie.Subst["__REJECTOR_ADDRESS__"] = user_email_address;
171 Katie.Subst["__MANUAL_REJECT_MESSAGE__"] = reject_message;
172 Katie.Subst["__STABLE_REJECTOR__"] = Cnf["Lauren::StableRejector"];
173 Katie.Subst["__MORE_INFO_URL__"] = Cnf["Lauren::MoreInfoURL"];
174 Katie.Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"];
175 reject_mail_message = utils.TemplateSubst(Katie.Subst,Cnf["Dir::Templates"]+"/lauren.stable-rejected");
177 # Write the rejection email out as the <foo>.reason file
178 os.write(reject_fd, reject_mail_message);
181 # Remove the packages from proposed-updates
182 suite_id = db_access.get_suite_id('proposed-updates');
184 projectB.query("BEGIN WORK");
185 # Remove files from proposed-updates suite
186 for file in files.keys():
187 if files[file]["type"] == "dsc":
188 package = dsc["source"];
189 version = dsc["version"]; # NB: not files[file]["version"], that has no epoch
190 q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version));
193 utils.fubar("reject: Couldn't find %s_%s in source table." % (package, version));
194 source_id = ql[0][0];
195 projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id));
196 elif files[file]["type"] == "deb":
197 package = files[file]["package"];
198 version = files[file]["version"];
199 architecture = files[file]["architecture"];
200 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));
203 # Horrible hack to work around partial replacement of
204 # packages with newer versions (from different source
205 # packages). This, obviously, should instead check for a
206 # newer version of the package and only do the
207 # warn&continue thing if it finds one.
209 utils.warn("reject: Couldn't find %s_%s_%s in binaries table." % (package, version, architecture));
211 binary_id = ql[0][0];
212 projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id));
213 projectB.query("COMMIT WORK");
215 # Send the rejection mail if appropriate
216 if not Options["No-Mail"]:
217 utils.send_mail(reject_mail_message);
219 # Finally remove the .katie file
220 katie_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyKatie"], os.path.basename(changes_file[:-8]+".katie"));
221 os.unlink(katie_file);
223 Logger.log(["rejected", changes_file]);
226 ################################################################################
228 if __name__ == '__main__':