X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Freject_proposed_updates.py;h=a61db174bd076bfc65bd817d3d5c9fc1595f002b;hb=f8996e240d9d0278bce098e23be63db0bcc6fbee;hp=58c7e88e431a28a4d56c388eb4afa009342cf3c9;hpb=06ce98c8111a8b09e5603dbbd34324a216412d69;p=dak.git diff --git a/dak/reject_proposed_updates.py b/dak/reject_proposed_updates.py index 58c7e88e..a61db174 100755 --- a/dak/reject_proposed_updates.py +++ b/dak/reject_proposed_updates.py @@ -20,8 +20,11 @@ ################################################################################ import os, pg, sys -import dak.lib.database, dak.lib.queue, dak.lib.logging, dak.lib.utils import apt_pkg +from daklib import database +from daklib import logging +from daklib import queue +from daklib import utils ################################################################################ @@ -48,38 +51,38 @@ Manually reject the .CHANGES file(s). def main(): global Cnf, Logger, Options, projectB, Upload - Cnf = dak.lib.utils.get_conf() + Cnf = utils.get_conf() Arguments = [('h',"help","Reject-Proposed-Updates::Options::Help"), ('m',"manual-reject","Reject-Proposed-Updates::Options::Manual-Reject", "HasArg"), ('s',"no-mail", "Reject-Proposed-Updates::Options::No-Mail")] for i in [ "help", "manual-reject", "no-mail" ]: - if not Cnf.has_key("Reject-Proposed-Updates::Options::%s" % (i)): - Cnf["Reject-Proposed-Updates::Options::%s" % (i)] = "" + if not Cnf.has_key("Reject-Proposed-Updates::Options::%s" % (i)): + Cnf["Reject-Proposed-Updates::Options::%s" % (i)] = "" arguments = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv) Options = Cnf.SubTree("Reject-Proposed-Updates::Options") if Options["Help"]: - usage() + usage() if not arguments: - dak.lib.utils.fubar("need at least one .changes filename as an argument.") + utils.fubar("need at least one .changes filename as an argument.") projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])) - dak.lib.database.init(Cnf, projectB) + database.init(Cnf, projectB) - Upload = dak.lib.queue.Upload(Cnf) - Logger = Upload.Logger = dak.lib.logging.Logger(Cnf, "reject-proposed-updates") + Upload = queue.Upload(Cnf) + Logger = Upload.Logger = logging.Logger(Cnf, "reject-proposed-updates") - bcc = "X-DAK: dak rejected-proposed-updates\nX-Katie: this header is obsolete" + bcc = "X-DAK: dak rejected-proposed-updates\nX-Katie: lauren $Revision: 1.4 $" if Cnf.has_key("Dinstall::Bcc"): Upload.Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"]) else: Upload.Subst["__BCC__"] = bcc for arg in arguments: - arg = dak.lib.utils.validate_changes_file_arg(arg) + arg = utils.validate_changes_file_arg(arg) Upload.pkg.changes_file = arg - Upload.init_vars() + Upload.init_vars() cwd = os.getcwd() os.chdir(Cnf["Suite::Proposed-Updates::CopyDotDak"]) Upload.update_vars() @@ -93,8 +96,8 @@ def main(): answer = "XXX" while prompt.find(answer) == -1: - answer = dak.lib.utils.our_raw_input(prompt) - m = dak.lib.queue.re_default_answer.search(prompt) + answer = utils.our_raw_input(prompt) + m = queue.re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -120,21 +123,21 @@ def reject (reject_message = ""): # If we weren't given a manual rejection message, spawn an editor # so the user can add one in... if not reject_message: - temp_filename = dak.lib.utils.temp_filename() + temp_filename = utils.temp_filename() editor = os.environ.get("EDITOR","vi") answer = 'E' while answer == 'E': os.system("%s %s" % (editor, temp_filename)) - file = dak.lib.utils.open_file(temp_filename) - reject_message = "".join(file.readlines()) - file.close() + f = utils.open_file(temp_filename) + reject_message = "".join(f.readlines()) + f.close() print "Reject message:" - print dak.lib.utils.prefix_multi_line_string(reject_message," ", include_blank_lines=1) + print utils.prefix_multi_line_string(reject_message," ", include_blank_lines=1) prompt = "[R]eject, Edit, Abandon, Quit ?" answer = "XXX" while prompt.find(answer) == -1: - answer = dak.lib.utils.our_raw_input(prompt) - m = dak.lib.queue.re_default_answer.search(prompt) + answer = utils.our_raw_input(prompt) + m = queue.re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -156,42 +159,43 @@ def reject (reject_message = ""): # If we fail here someone is probably trying to exploit the race # so let's just raise an exception ... if os.path.exists(reject_filename): - os.unlink(reject_filename) + os.unlink(reject_filename) reject_fd = os.open(reject_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644) # Build up the rejection email - user_email_address = dak.lib.utils.whoami() + " <%s>" % (Cnf["Dinstall::MyAdminAddress"]) + user_email_address = utils.whoami() + " <%s>" % (Cnf["Dinstall::MyAdminAddress"]) Upload.Subst["__REJECTOR_ADDRESS__"] = user_email_address Upload.Subst["__MANUAL_REJECT_MESSAGE__"] = reject_message Upload.Subst["__STABLE_REJECTOR__"] = Cnf["Reject-Proposed-Updates::StableRejector"] + Upload.Subst["__STABLE_MAIL__"] = Cnf["Reject-Proposed-Updates::StableMail"] Upload.Subst["__MORE_INFO_URL__"] = Cnf["Reject-Proposed-Updates::MoreInfoURL"] Upload.Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"] - reject_mail_message = dak.lib.utils.TemplateSubst(Upload.Subst,Cnf["Dir::Templates"]+"/reject-proposed-updates.rejected") + reject_mail_message = utils.TemplateSubst(Upload.Subst,Cnf["Dir::Templates"]+"/reject-proposed-updates.rejected") # Write the rejection email out as the .reason file os.write(reject_fd, reject_mail_message) os.close(reject_fd) # Remove the packages from proposed-updates - suite_id = dak.lib.database.get_suite_id('proposed-updates') + suite_id = database.get_suite_id('proposed-updates') projectB.query("BEGIN WORK") # Remove files from proposed-updates suite - for file in files.keys(): - if files[file]["type"] == "dsc": + for f in files.keys(): + if files[f]["type"] == "dsc": package = dsc["source"] - version = dsc["version"]; # NB: not files[file]["version"], that has no epoch + version = dsc["version"]; # NB: not files[f]["version"], that has no epoch q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version)) ql = q.getresult() if not ql: - dak.lib.utils.fubar("reject: Couldn't find %s_%s in source table." % (package, version)) + utils.fubar("reject: Couldn't find %s_%s in source table." % (package, version)) source_id = ql[0][0] projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id)) - elif files[file]["type"] == "deb": - package = files[file]["package"] - version = files[file]["version"] - architecture = files[file]["architecture"] + elif files[f]["type"] == "deb": + package = files[f]["package"] + version = files[f]["version"] + architecture = files[f]["architecture"] 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)) ql = q.getresult() @@ -201,7 +205,7 @@ def reject (reject_message = ""): # newer version of the package and only do the # warn&continue thing if it finds one. if not ql: - dak.lib.utils.warn("reject: Couldn't find %s_%s_%s in binaries table." % (package, version, architecture)) + utils.warn("reject: Couldn't find %s_%s_%s in binaries table." % (package, version, architecture)) else: binary_id = ql[0][0] projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id)) @@ -209,7 +213,7 @@ def reject (reject_message = ""): # Send the rejection mail if appropriate if not Options["No-Mail"]: - dak.lib.utils.send_mail(reject_mail_message) + utils.send_mail(reject_mail_message) # Finally remove the .dak file dot_dak_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyDotDak"], os.path.basename(changes_file[:-8]+".dak"))