X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=katie;h=ad48fa0e5dcc9099fb85efb22ff8aa875398e5fd;hb=d0a891d7eb8d79b747f031392dd29de3acd68d84;hp=01c6cf2d6c07d149e11e11c6a4da9542ce3a0974;hpb=5585dd6c37241f7d914976cad162d74650d75622;p=dak.git diff --git a/katie b/katie index 01c6cf2d..ad48fa0e 100755 --- a/katie +++ b/katie @@ -1,8 +1,8 @@ #!/usr/bin/env python # Installs Debian packages -# Copyright (C) 2000, 2001 James Troup -# $Id: katie,v 1.74 2002-03-08 03:21:57 rmurray Exp $ +# Copyright (C) 2000, 2001, 2002 James Troup +# $Id: katie,v 1.84 2002-05-23 12:18:32 troup Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ import db_access, katie, logging, utils; ############################################################################### # Globals -katie_version = "$Revision: 1.74 $"; +katie_version = "$Revision: 1.84 $"; Cnf = None; Options = None; @@ -59,6 +59,8 @@ Subst = None; install_count = 0; install_bytes = 0.0; +installing_to_stable = 0; + ############################################################################### # FIXME: this should go away to some Debian specific file @@ -71,7 +73,7 @@ class Urgency_Log: self.Cnf = Cnf; self.timestamp = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())); # Create the log directory if it doesn't exist - self.log_dir = Cnf["Dir::UrgencyLogDir"]; + self.log_dir = Cnf["Dir::UrgencyLog"]; if not os.path.exists(self.log_dir): umask = os.umask(00000); os.makedirs(self.log_dir, 02775); @@ -116,18 +118,20 @@ def check(): and not Katie.source_exists(source_package, source_version): reject("no source found for %s %s (%s)." % (source_package, source_version, file)); - for suite in changes["distribution"].keys(): - # Check the package is still in the override tables - if not Katie.in_override_p(files[file]["package"], files[file]["component"], suite, files[file].get("dbtype",""), file): - reject("%s is NEW for %s." % (file, suite)); - + # Version and file overwrite checks + if not installing_to_stable: if files[file]["type"] == "deb": - reject(Katie.check_binaries_against_db(file, suite)); + reject(Katie.check_binary_against_db(file)); elif files[file]["type"] == "dsc": reject(Katie.check_source_against_db(file)); (reject_msg, is_in_incoming) = Katie.check_dsc_against_db(file); reject(reject_msg); + # Check the package is still in the override tables + for suite in changes["distribution"].keys(): + if not Katie.in_override_p(files[file]["package"], files[file]["component"], suite, files[file].get("dbtype",""), file): + reject("%s is NEW for %s." % (file, suite)); + ############################################################################### def init(): @@ -205,7 +209,10 @@ def action (): if answer == 'R': do_reject (); elif answer == 'I': - install (); + if not installing_to_stable: + install(); + else: + stable_install(summary, short_summary); elif answer == 'Q': sys.exit(0) @@ -220,11 +227,11 @@ def do_reject (): Subst["__REJECTOR_ADDRESS__"] = Cnf["Dinstall::MyEmailAddress"]; Subst["__REJECT_MESSAGE__"] = reject_message; Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"]; - reject_mail_message = utils.TemplateSubst(Subst,utils.open_file(Cnf["Dir::TemplatesDir"]+"/katie.unaccept").read()); + reject_mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/katie.unaccept"); # Write the rejection email out as the .reason file reason_filename = os.path.basename(pkg.changes_file[:-8]) + ".reason"; - reject_filename = Cnf["Dir::QueueRejectDir"] + '/' + reason_filename; + reject_filename = Cnf["Dir::Queue::Reject"] + '/' + reason_filename; # 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): @@ -299,7 +306,9 @@ def install (): source = files[file]["source package"] source_version = files[file]["source version"]; filename = files[file]["pool name"] + file; - if not file[file].has_key("files id") or not files[file]["files id"]: + if not files[file].has_key("location id") or not files[file]["location id"]: + files[file]["location id"] = db_access.get_location_id(Cnf["Dir::Pool"],files[file]["component"],utils.where_am_i()); + if not files[file].has_key("files id") or not files[file]["files id"]: files[file]["files id"] = db_access.set_files_id (filename, files[file]["size"], files[file]["md5sum"], files[file]["location id"]) source_id = db_access.get_source_id (source, source_version); if source_id: @@ -329,7 +338,7 @@ def install (): legacy_filename = qid["path"]+qid["filename"]; pool_location = utils.poolify (changes["source"], files[file]["component"]); pool_filename = pool_location + os.path.basename(qid["filename"]); - destination = Cnf["Dir::PoolDir"] + pool_location + destination = Cnf["Dir::Pool"] + pool_location utils.move(legacy_filename, destination); # Then Update the DB's files table q = projectB.query("UPDATE files SET filename = '%s', location = '%s' WHERE id = '%s'" % (pool_filename, dsc_location_id, qid["files_id"])); @@ -345,40 +354,158 @@ def install (): old_filename = ql[0] + ql[1]; file_size = ql[2]; file_md5sum = ql[3]; - new_filename = utils.poolify (changes["source"], dsc_component) + os.path.basename(old_filename); + new_filename = utils.poolify(changes["source"], dsc_component) + os.path.basename(old_filename); new_files_id = db_access.get_files_id(new_filename, file_size, file_md5sum, dsc_location_id); if new_files_id == None: - utils.copy(old_filename, Cnf["Dir::PoolDir"] + new_filename); + utils.copy(old_filename, Cnf["Dir::Pool"] + new_filename); new_files_id = db_access.set_files_id(new_filename, file_size, file_md5sum, dsc_location_id); projectB.query("UPDATE dsc_files SET file = %s WHERE source = %s AND file = %s" % (new_files_id, source_id, orig_tar_id)); # Install the files into the pool for file in files.keys(): - destination = Cnf["Dir::PoolDir"] + files[file]["pool name"] + file - utils.move (file, destination) + destination = Cnf["Dir::Pool"] + files[file]["pool name"] + file; + utils.move(file, destination); Logger.log(["installed", file, files[file]["type"], files[file]["size"], files[file]["architecture"]]); - install_bytes = install_bytes + float(files[file]["size"]) + install_bytes = install_bytes + float(files[file]["size"]); # Copy the .changes file across for suite which need it. for suite in changes["distribution"].keys(): if Cnf.has_key("Suite::%s::CopyChanges" % (suite)): - utils.copy (pkg.changes_file, Cnf["Dir::RootDir"] + Cnf["Suite::%s::CopyChanges" % (suite)]); + utils.copy(pkg.changes_file, Cnf["Dir::Root"] + Cnf["Suite::%s::CopyChanges" % (suite)]); + # and the .katie file... + if Cnf.has_key("Suite::%s::CopyKatie" % (suite)): + utils.copy(Katie.pkg.changes_file[:-8]+".katie", Cnf["Suite::%s::CopyKatie" % (suite)]); projectB.query("COMMIT WORK"); # Move the .changes into the 'done' directory try: - utils.move (pkg.changes_file, os.path.join(Cnf["Dir::QueueDoneDir"], os.path.basename(pkg.changes_file))); + utils.move (pkg.changes_file, os.path.join(Cnf["Dir::Queue::Done"], os.path.basename(pkg.changes_file))); except: utils.warn("couldn't move changes file '%s' to DONE directory. [Got %s]" % (os.path.basename(pkg.changes_file), sys.exc_type)); os.unlink(Katie.pkg.changes_file[:-8]+".katie"); - if changes["architecture"].has_key("source"): + if changes["architecture"].has_key("source") and Urgency_Logger: Urgency_Logger.log(dsc["source"], dsc["version"], changes["urgency"]); + # Undo the work done in katie.py(accept) to help auto-building + # from accepted. + projectB.query("BEGIN WORK"); + for suite in changes["distribution"].keys(): + if suite not in Cnf.ValueList("Dinstall::AcceptedAutoBuildSuites"): + continue; + now_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time())); + suite_id = db_access.get_suite_id(suite); + dest_dir = Cnf["Dir::AcceptedAutoBuild"]; + if Cnf.FindB("Dinstall::SecurityAcceptedAutoBuild"): + dest_dir = os.path.join(dest_dir, suite); + for file in files.keys(): + dest = os.path.join(dest_dir, file); + # Remove it from the list of packages for later processing by apt-ftparchive + projectB.query("UPDATE accepted_autobuild SET in_accepted = 'f', last_used = '%s' WHERE filename = '%s' AND suite = %s" % (now_date, dest, suite_id)); + if not Cnf.FindB("Dinstall::SecurityAcceptedAutoBuild"): + # Update the symlink to point to the new location in the pool + pool_location = utils.poolify (changes["source"], files[file]["component"]); + src = os.path.join(Cnf["Dir::Pool"], pool_location, os.path.basename(file)); + if os.path.islink(dest): + os.unlink(dest); + os.symlink(src, dest); + # Update last_used on any non-upload .orig.tar.gz symlink + if orig_tar_id: + # Determine the .orig.tar.gz file name + for dsc_file in dsc_files.keys(): + if dsc_file[-12:] == ".orig.tar.gz": + orig_tar_gz = os.path.join(dest_dir, dsc_file); + # Remove it from the list of packages for later processing by apt-ftparchive + projectB.query("UPDATE accepted_autobuild SET in_accepted = 'f', last_used = '%s' WHERE filename = '%s' AND suite = %s" % (now_date, orig_tar_gz, suite_id)); + projectB.query("COMMIT WORK"); + + # Finally... + install_count = install_count + 1; + +################################################################################ + +def stable_install (summary, short_summary): + global install_count; + + print "Installing to stable."; + + # Begin a transaction; if we bomb out anywhere between here and the COMMIT WORK below, the DB will not be changed. + projectB.query("BEGIN WORK"); + + # Add the source to stable (and remove it from proposed-updates) + for file in files.keys(): + if files[file]["type"] == "dsc": + package = dsc["source"]; + version = dsc["version"]; # NB: not files[file]["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: + utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s) in source table." % (package, version)); + source_id = ql[0][0]; + suite_id = db_access.get_suite_id('proposed-updates'); + projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id)); + suite_id = db_access.get_suite_id('stable'); + projectB.query("INSERT INTO src_associations (suite, source) VALUES ('%s', '%s')" % (suite_id, source_id)); + + # Add the binaries to stable (and remove it/them from proposed-updates) + for file in files.keys(): + if files[file]["type"] == "deb": + package = files[file]["package"]; + version = files[file]["version"]; + architecture = files[file]["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(); + if not ql: + utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s for %s architecture) in binaries table." % (package, version, architecture)); + binary_id = ql[0][0]; + suite_id = db_access.get_suite_id('proposed-updates'); + projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id)); + suite_id = db_access.get_suite_id('stable'); + projectB.query("INSERT INTO bin_associations (suite, bin) VALUES ('%s', '%s')" % (suite_id, binary_id)); + + projectB.query("COMMIT WORK"); + + utils.move (pkg.changes_file, Cnf["Dir::Morgue"] + '/katie/' + os.path.basename(pkg.changes_file)); + + ## Update the Stable ChangeLog file + new_changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + ".ChangeLog"; + changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + "ChangeLog"; + if os.path.exists(new_changelog_filename): + os.unlink (new_changelog_filename); + + new_changelog = utils.open_file(new_changelog_filename, 'w'); + for file in files.keys(): + if files[file]["type"] == "deb": + new_changelog.write("stable/%s/binary-%s/%s\n" % (files[file]["component"], files[file]["architecture"], file)); + elif utils.re_issource.match(file) != None: + new_changelog.write("stable/%s/source/%s\n" % (files[file]["component"], file)); + else: + new_changelog.write("%s\n" % (file)); + chop_changes = katie.re_fdnic.sub("\n", changes["changes"]); + new_changelog.write(chop_changes + '\n\n'); + if os.access(changelog_filename, os.R_OK) != 0: + changelog = utils.open_file(changelog_filename); + new_changelog.write(changelog.read()); + new_changelog.close(); + if os.access(changelog_filename, os.R_OK) != 0: + os.unlink(changelog_filename); + utils.move(new_changelog_filename, changelog_filename); + install_count = install_count + 1; + if not Options["No-Mail"] and changes["architecture"].has_key("source"): + Subst["__SUITE__"] = " into stable"; + Subst["__SUMMARY__"] = summary; + mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/katie.installed"); + utils.send_mail(mail_message, ""); + Katie.announce(short_summary, 1) + + # Finally remove the .katie file + katie_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyKatie"], os.path.basename(Katie.pkg.changes_file[:-8]+".katie")); + os.unlink(katie_file); + ################################################################################ def process_it (changes_file): @@ -394,9 +521,18 @@ def process_it (changes_file): # save and restore it. pkg.directory = os.getcwd(); + if installing_to_stable: + old = Katie.pkg.changes_file; + Katie.pkg.changes_file = os.path.basename(old); + os.chdir(Cnf["Suite::Proposed-Updates::CopyKatie"]); + Katie.init_vars(); Katie.update_vars(); Katie.update_subst(); + + if installing_to_stable: + Katie.pkg.changes_file = old; + check(); action(); @@ -406,7 +542,7 @@ def process_it (changes_file): ############################################################################### def main(): - global projectB, Logger, Urgency_Logger; + global projectB, Logger, Urgency_Logger, installing_to_stable; changes_files = init(); @@ -423,16 +559,20 @@ def main(): # Check that we aren't going to clash with the daily cron job - if not Options["No-Action"] and os.path.exists("%s/Archive_Maintenance_In_Progress" % (Cnf["Dir::RootDir"])) and not Options["No-Lock"]: + if not Options["No-Action"] and os.path.exists("%s/Archive_Maintenance_In_Progress" % (Cnf["Dir::Root"])) and not Options["No-Lock"]: utils.fubar("Archive maintenance in progress. Try again later."); - # Obtain lock if not in no-action mode and initialize the log + # If running from within proposed-updates; assume an install to stable + if string.find(os.getcwd(), 'proposed-updates') != -1: + installing_to_stable = 1; + # Obtain lock if not in no-action mode and initialize the log if not Options["No-Action"]: lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT); fcntl.lockf(lock_fd, FCNTL.F_TLOCK); Logger = Katie.Logger = logging.Logger(Cnf, "katie"); - Urgency_Logger = Urgency_Log(Cnf); + if not installing_to_stable and Cnf.get("Dir::UrgencyLog"): + Urgency_Logger = Urgency_Log(Cnf); # Initialize the substitution template mapping global bcc = "X-Katie: %s" % (katie_version); @@ -440,7 +580,8 @@ def main(): Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"]); else: Subst["__BCC__"] = bcc; - Subst["__STABLE_REJECTOR__"] = Cnf["Dinstall::StableRejector"]; + if Cnf.has_key("Dinstall::StableRejector"): + Subst["__STABLE_REJECTOR__"] = Cnf["Dinstall::StableRejector"]; # Sort the .changes files so that we process sourceful ones first changes_files.sort(utils.changes_compare); @@ -459,8 +600,10 @@ def main(): if not Options["No-Action"]: Logger.close(); - Urgency_Logger.close(); + if Urgency_Logger: + Urgency_Logger.close(); -if __name__ == '__main__': - main() +############################################################################### +if __name__ == '__main__': + main();