[Treepkg-commits] r44 - in trunk: test treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed May 21 15:20:37 CEST 2008
Author: bh
Date: 2008-05-21 15:20:36 +0200 (Wed, 21 May 2008)
New Revision: 44
Modified:
trunk/test/test_builder.py
trunk/treepkg/builder.py
Log:
Add PBuilder.run_script method and associated tests. The run_script
method allows arbitrary scripts to be run in the pbuilder chroot
environment
Modified: trunk/test/test_builder.py
===================================================================
--- trunk/test/test_builder.py 2008-05-20 18:47:16 UTC (rev 43)
+++ trunk/test/test_builder.py 2008-05-21 13:20:36 UTC (rev 44)
@@ -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'])
Modified: trunk/treepkg/builder.py
===================================================================
--- trunk/treepkg/builder.py 2008-05-20 18:47:16 UTC (rev 43)
+++ trunk/treepkg/builder.py 2008-05-21 13:20:36 UTC (rev 44)
@@ -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)
More information about the Treepkg-commits
mailing list