Mercurial > treepkg
changeset 184:83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
method to the PBuilder class.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 25 Jun 2008 15:15:30 +0000 |
parents | 72e41b27f224 |
children | e1c7cd896310 |
files | bin/treepkgbuilder.py treepkg/builder.py |
diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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")
--- 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