[Treepkg-commits] r109 - in trunk: bin treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jun 25 17:15:30 CEST 2008


Author: bh
Date: 2008-06-25 17:15:30 +0200 (Wed, 25 Jun 2008)
New Revision: 109

Modified:
   trunk/bin/treepkgbuilder.py
   trunk/treepkg/builder.py
Log:
Add the addkey command to bin/treepkgbuilder.py and a corresponding
method to the PBuilder class.


Modified: trunk/bin/treepkgbuilder.py
===================================================================
--- trunk/bin/treepkgbuilder.py	2008-06-25 15:14:27 UTC (rev 108)
+++ trunk/bin/treepkgbuilder.py	2008-06-25 15:15:30 UTC (rev 109)
@@ -90,6 +90,27 @@
         builder.update(suppress_output=False, log_info=False)
 
 
+class AddKeyCommand(Command):
+
+    names = ("addkey", "add-key")
+
+    def __init__(self, arguments):
+        super(AddKeyCommand, self).__init__(arguments)
+        if not self.opts.key_id:
+            print >>sys.stderr, "No key id given"
+            sys.exit(1)
+
+    def create_parser(self):
+        parser = super(AddKeyCommand, self).create_parser()
+        parser.add_option("--key-id",
+                          help=("The id of the key to add.  Required."))
+        return parser
+
+    def run(self):
+        builder = self.get_builder()
+        builder.add_apt_key(self.opts.key_id)
+
+
 class HelpCommand(Command):
 
     names = ("help", "--help", "-h")

Modified: trunk/treepkg/builder.py
===================================================================
--- trunk/treepkg/builder.py	2008-06-25 15:14:27 UTC (rev 108)
+++ trunk/treepkg/builder.py	2008-06-25 15:15:30 UTC (rev 109)
@@ -11,6 +11,7 @@
 import os
 import shutil
 import logging
+import tempfile
 
 import util
 import run
@@ -126,6 +127,24 @@
                            rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc),
                  suppress_output=suppress_output)
 
+    def add_apt_key(self, keyid):
+        """Runs apt-key add in the chroot"""
+        # Creates a temporary file in extra_pkg_dir (because that's
+        # bind-mounted by default) with a script that adds the desired
+        # key.  The exported key is included in the script file so that
+        # only one file has to be created
+        script = tempfile.NamedTemporaryFile(dir=self.extra_pkg_dir)
+        try:
+            script.write("#! /bin/sh\n")
+            script.write("apt-key add $0\n")
+            script.write("exit\n\n")
+            script.flush()
+            run.call(cmdexpand("gpg --export --armor $keyid", **locals()),
+                     stdout=script.fileno())
+            self.run_script([script.name], logfile=None, save_after_exec=True)
+        finally:
+            script.close()
+
     def build(self, dsc_file, binary_dir, logfile, bindmounts=(),
               extra_packages=(), extra_env=None):
         """Build a binary packager from a source package



More information about the Treepkg-commits mailing list