]> git.decadent.org.uk Git - dak.git/blobdiff - dak/process_accepted.py
merge with master
[dak.git] / dak / process_accepted.py
index a25c391fc374f9d286d8e515ecf74adfa64e9684..9883bb206de77c0e7b5a9780769482534cf774aa 100755 (executable)
@@ -1,8 +1,14 @@
 #!/usr/bin/env python
 
-# Installs Debian packages from queue/accepted into the pool
-# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.org>
+"""
+Installs Debian packages from queue/accepted into the pool
 
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.org>
+@copyright: 2009  Joerg Jaspert <joerg@debian.org>
+@license: GNU General Public License version 2 or later
+
+"""
 # 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
 # the Free Software Foundation; either version 2 of the License, or
 
 ###############################################################################
 
-import errno, fcntl, os, sys, time, re
-import apt_pkg
+import errno
+import fcntl
+import os
+import sys
+import time
+import re
+import apt_pkg, commands
 from daklib import database
 from daklib import logging
 from daklib import queue
 from daklib import utils
 from daklib.dak_exceptions import *
+from daklib.regexes import re_default_answer, re_issource, re_fdnic
 
 ###############################################################################
 
@@ -96,8 +108,10 @@ class Urgency_Log:
         else:
             os.unlink(self.log_filename)
 
+
 ###############################################################################
 
+
 def reject (str, prefix="Rejected: "):
     global reject_message
     if str:
@@ -161,9 +175,11 @@ def init():
                  ('h',"help","Dinstall::Options::Help"),
                  ('n',"no-action","Dinstall::Options::No-Action"),
                  ('p',"no-lock", "Dinstall::Options::No-Lock"),
-                 ('s',"no-mail", "Dinstall::Options::No-Mail")]
+                 ('s',"no-mail", "Dinstall::Options::No-Mail"),
+                 ('d',"directory", "Dinstall::Options::Directory", "HasArg")]
 
-    for i in ["automatic", "help", "no-action", "no-lock", "no-mail", "version"]:
+    for i in ["automatic", "help", "no-action", "no-lock", "no-mail",
+              "version", "directory"]:
         if not Cnf.has_key("Dinstall::Options::%s" % (i)):
             Cnf["Dinstall::Options::%s" % (i)] = ""
 
@@ -173,6 +189,15 @@ def init():
     if Options["Help"]:
         usage()
 
+    # If we have a directory flag, use it to find our files
+    if Cnf["Dinstall::Options::Directory"] != "":
+        # Note that we clobber the list of files we were given in this case
+        # so warn if the user has done both
+        if len(changes_files) > 0:
+            utils.warn("Directory provided so ignoring files given on command line")
+
+        changes_files = utils.get_changes_files(Cnf["Dinstall::Options::Directory"])
+
     Upload = queue.Upload(Cnf)
     projectB = Upload.projectB
 
@@ -199,7 +224,7 @@ def usage (exit_code=0):
 
 ###############################################################################
 
-def action ():
+def action (queue=""):
     (summary, short_summary) = Upload.build_summaries()
 
     (prompt, answer) = ("", "XXX")
@@ -220,7 +245,7 @@ def action ():
 
     while prompt.find(answer) == -1:
         answer = utils.our_raw_input(prompt)
-        m = queue.re_default_answer.match(prompt)
+        m = re_default_answer.match(prompt)
         if answer == "":
             answer = m.group(1)
         answer = answer[:1].upper()
@@ -231,7 +256,7 @@ def action ():
         if not installing_to_stable:
             install()
         else:
-            stable_install(summary, short_summary)
+            stable_install(summary, short_summary, queue)
     elif answer == 'Q':
         sys.exit(0)
 
@@ -371,34 +396,21 @@ def install ():
                 suite_id = database.get_suite_id(suite)
                 projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%d, currval('binaries_id_seq'))" % (suite_id))
 
-    # If the .orig.tar.gz is in a legacy directory we need to poolify
-    # it, so that apt-get source (and anything else that goes by the
-    # "Directory:" field in the Sources.gz file) works.
+            if not database.copy_temporary_contents(package, version, architecture, newfile, reject):
+                print "REJECT\n" + reject_message,
+                projectB.query("ROLLBACK")
+                raise MissingContents, "No contents stored for package %s, and couldn't determine contents of %s" % (package, newfile )
+
+
     orig_tar_id = Upload.pkg.orig_tar_id
     orig_tar_location = Upload.pkg.orig_tar_location
-    legacy_source_untouchable = Upload.pkg.legacy_source_untouchable
-    if orig_tar_id and orig_tar_location == "legacy":
-        q = projectB.query("SELECT DISTINCT ON (f.id) l.path, f.filename, f.id as files_id, df.source, df.id as dsc_files_id, f.size, f.md5sum FROM files f, dsc_files df, location l WHERE df.source IN (SELECT source FROM dsc_files WHERE file = %s) AND f.id = df.file AND l.id = f.location AND (l.type = 'legacy' OR l.type = 'legacy-mixed')" % (orig_tar_id))
-        qd = q.dictresult()
-        for qid in qd:
-            # Is this an old upload superseded by a newer -sa upload?  (See check_dsc() for details)
-            if legacy_source_untouchable.has_key(qid["files_id"]):
-                continue
-            # First move the files to the new location
-            legacy_filename = qid["path"] + qid["filename"]
-            pool_location = utils.poolify (changes["source"], files[newfile]["component"])
-            pool_filename = pool_location + os.path.basename(qid["filename"])
-            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"]))
-
-    # If this is a sourceful diff only upload that is moving non-legacy
+
+    # If this is a sourceful diff only upload that is moving
     # cross-component we need to copy the .orig.tar.gz into the new
     # component too for the same reasons as above.
     #
     if changes["architecture"].has_key("source") and orig_tar_id and \
-       orig_tar_location != "legacy" and orig_tar_location != dsc_location_id:
+       orig_tar_location != dsc_location_id:
         q = projectB.query("SELECT l.path, f.filename, f.size, f.md5sum, f.sha1sum, f.sha256sum FROM files f, location l WHERE f.id = %s AND f.location = l.id" % (orig_tar_id))
         ql = q.getresult()[0]
         old_filename = ql[0] + ql[1]
@@ -433,7 +445,6 @@ def install ():
         utils.copy(pkg.changes_file, Cnf["Dir::Root"] + dest)
     for dest in copy_dot_dak.keys():
         utils.copy(Upload.pkg.changes_file[:-8]+".dak", dest)
-
     projectB.query("COMMIT WORK")
 
     # Move the .changes into the 'done' directory
@@ -483,10 +494,15 @@ def install ():
 
 ################################################################################
 
-def stable_install (summary, short_summary):
+def stable_install (summary, short_summary, fromsuite="proposed-updates"):
     global install_count
 
-    print "Installing to stable."
+    fromsuite = fromsuite.lower()
+    tosuite = "Stable"
+    if fromsuite == "oldstable-proposed-updates":
+        tosuite = "OldStable"
+
+    print "Installing from %s to %s." % (fromsuite, tosuite)
 
     # Begin a transaction; if we bomb out anywhere between here and
     # the COMMIT WORK below, the DB won't be changed.
@@ -502,9 +518,9 @@ def stable_install (summary, short_summary):
             if not ql:
                 utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s) in source table." % (package, version))
             source_id = ql[0][0]
-            suite_id = database.get_suite_id('proposed-updates')
+            suite_id = database.get_suite_id(fromsuite)
             projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id))
-            suite_id = database.get_suite_id('stable')
+            suite_id = database.get_suite_id(tosuite.lower())
             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)
@@ -519,9 +535,9 @@ def stable_install (summary, short_summary):
                 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 = database.get_suite_id('proposed-updates')
+            suite_id = database.get_suite_id(fromsuite)
             projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id))
-            suite_id = database.get_suite_id('stable')
+            suite_id = database.get_suite_id(tosuite.lower())
             projectB.query("INSERT INTO bin_associations (suite, bin) VALUES ('%s', '%s')" % (suite_id, binary_id))
 
     projectB.query("COMMIT WORK")
@@ -529,20 +545,20 @@ def stable_install (summary, short_summary):
     utils.move (pkg.changes_file, Cnf["Dir::Morgue"] + '/process-accepted/' + 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"
+    new_changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::%s::ChangeLogBase" % (tosuite)] + ".ChangeLog"
+    changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::%s::ChangeLogBase" % (tosuite)] + "ChangeLog"
     if os.path.exists(new_changelog_filename):
         os.unlink (new_changelog_filename)
 
     new_changelog = utils.open_file(new_changelog_filename, 'w')
     for newfile in files.keys():
         if files[newfile]["type"] == "deb":
-            new_changelog.write("stable/%s/binary-%s/%s\n" % (files[newfile]["component"], files[newfile]["architecture"], newfile))
-        elif utils.re_issource.match(newfile):
-            new_changelog.write("stable/%s/source/%s\n" % (files[newfile]["component"], newfile))
+            new_changelog.write("%s/%s/binary-%s/%s\n" % (tosuite.lower(), files[newfile]["component"], files[newfile]["architecture"], newfile))
+        elif re_issource.match(newfile):
+            new_changelog.write("%s/%s/source/%s\n" % (tosuite.lower(), files[newfile]["component"], newfile))
         else:
             new_changelog.write("%s\n" % (newfile))
-    chop_changes = queue.re_fdnic.sub("\n", changes["changes"])
+    chop_changes = 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)
@@ -555,19 +571,19 @@ def stable_install (summary, short_summary):
     install_count += 1
 
     if not Options["No-Mail"] and changes["architecture"].has_key("source"):
-        Subst["__SUITE__"] = " into stable"
+        Subst["__SUITE__"] = " into %s" % (tosuite)
         Subst["__SUMMARY__"] = summary
         mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-accepted.install")
         utils.send_mail(mail_message)
         Upload.announce(short_summary, 1)
 
     # Finally remove the .dak file
-    dot_dak_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyDotDak"], os.path.basename(Upload.pkg.changes_file[:-8]+".dak"))
+    dot_dak_file = os.path.join(Cnf["Suite::%s::CopyDotDak" % (fromsuite)], os.path.basename(Upload.pkg.changes_file[:-8]+".dak"))
     os.unlink(dot_dak_file)
 
 ################################################################################
 
-def process_it (changes_file):
+def process_it (changes_file, queue=""):
     global reject_message
 
     reject_message = ""
@@ -583,7 +599,7 @@ def process_it (changes_file):
     if installing_to_stable:
         old = Upload.pkg.changes_file
         Upload.pkg.changes_file = os.path.basename(old)
-        os.chdir(Cnf["Suite::Proposed-Updates::CopyDotDak"])
+        os.chdir(Cnf["Suite::%s::CopyDotDak" % (queue)])
 
     Upload.init_vars()
     Upload.update_vars()
@@ -593,7 +609,7 @@ def process_it (changes_file):
         Upload.pkg.changes_file = old
 
     check()
-    action()
+    action(queue)
 
     # Restore CWD
     os.chdir(pkg.directory)
@@ -615,7 +631,12 @@ def main():
         utils.fubar("Archive maintenance in progress.  Try again later.")
 
     # If running from within proposed-updates; assume an install to stable
-    if os.getcwd().find('proposed-updates') != -1:
+    queue = ""
+    if os.getenv('PWD').find('oldstable-proposed-updates') != -1:
+        queue = "Oldstable-Proposed-Updates"
+        installing_to_stable = 1
+    elif os.getenv('PWD').find('proposed-updates') != -1:
+        queue = "Proposed-Updates"
         installing_to_stable = 1
 
     # Obtain lock if not in no-action mode and initialize the log
@@ -645,7 +666,7 @@ def main():
     # Process the changes files
     for changes_file in changes_files:
         print "\n" + changes_file
-        process_it (changes_file)
+        process_it (changes_file, queue)
 
     if install_count:
         sets = "set"