# HG changeset patch # User Bernhard Herzog # Date 1211376036 0 # Node ID 92116333ef779b683e11cc81e30f7ad173ccf12b # Parent 9d59ed0e311620aea94442b2d63d4ab8acb1fe7e Add PBuilder.run_script method and associated tests. The run_script method allows arbitrary scripts to be run in the pbuilder chroot environment diff -r 9d59ed0e3116 -r 92116333ef77 test/test_builder.py --- a/test/test_builder.py Tue May 20 18:47:16 2008 +0000 +++ b/test/test_builder.py Wed May 21 13:20:36 2008 +0000 @@ -60,3 +60,23 @@ '--buildresult', binary_dir_name, 'my_dsc_file']) self.failUnless(os.path.isdir(binary_dir_name)) + + def test_run_script(self): + builder = PBuilder("my_pbuilderrc", self.root_command) + builder.run_script("my_script", logfile="the_logfile") + self.check_command_line(['/usr/sbin/pbuilder', 'execute', + '--configfile', 'my_pbuilderrc', + '--logfile', 'the_logfile', + 'my_script']) + + def test_run_script_with_bindmounts(self): + builder = PBuilder("my_pbuilderrc", self.root_command) + builder.run_script("my_script", logfile="the_logfile", + bindmounts=("/home/builder/foo", + "/home/builder/treepkg")) + self.check_command_line(['/usr/sbin/pbuilder', 'execute', + '--configfile', 'my_pbuilderrc', + '--logfile', 'the_logfile', + '--bindmounts', '/home/builder/foo', + '--bindmounts', '/home/builder/treepkg', + 'my_script']) diff -r 9d59ed0e3116 -r 92116333ef77 treepkg/builder.py --- a/treepkg/builder.py Tue May 20 18:47:16 2008 +0000 +++ b/treepkg/builder.py Wed May 21 13:20:36 2008 +0000 @@ -8,6 +8,7 @@ """Build binary packages from source packages""" import os +import logging import util import run @@ -48,3 +49,25 @@ for filename in os.listdir(binary_dir): if os.path.splitext(filename)[1] not in (".deb", ".changes"): os.remove(os.path.join(binary_dir, filename)) + + def run_script(self, script, logfile, bindmounts=()): + """Execute a script in pbuilder's chroot environment + Parameters: + script -- The filename of the script + logfile -- name of the logfile of the build + bindmounts -- Sequence of directory names that should be + bind-mounted in the pbuilder chroot + environment (optional) + """ + logging.info("Running pbuilder execute on %s", script) + args = [] + if logfile: + args.extend(["--logfile", logfile]) + for mount in bindmounts: + args.extend(["--bindmounts", mount]) + + run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder execute" + " --configfile $pbuilderrc @args $script", + rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc, + args=args, script=script), + suppress_output=False)