# HG changeset patch # User Bernhard Herzog # Date 1214406930 0 # Node ID 83c77307ffb1cd6a46249dd992935017728bc5eb # Parent 72e41b27f2245136d44dda0dd7175e6e33788291 Add the addkey command to bin/treepkgbuilder.py and a corresponding method to the PBuilder class. diff -r 72e41b27f224 -r 83c77307ffb1 bin/treepkgbuilder.py --- a/bin/treepkgbuilder.py Wed Jun 25 15:14:27 2008 +0000 +++ b/bin/treepkgbuilder.py Wed Jun 25 15:15:30 2008 +0000 @@ -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") diff -r 72e41b27f224 -r 83c77307ffb1 treepkg/builder.py --- a/treepkg/builder.py Wed Jun 25 15:14:27 2008 +0000 +++ b/treepkg/builder.py Wed Jun 25 15:15:30 2008 +0000 @@ -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