changeset 119:92116333ef77

Add PBuilder.run_script method and associated tests. The run_script method allows arbitrary scripts to be run in the pbuilder chroot environment
author Bernhard Herzog <bh@intevation.de>
date Wed, 21 May 2008 13:20:36 +0000
parents 9d59ed0e3116
children 007d7f2aa184
files test/test_builder.py treepkg/builder.py
diffstat 2 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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'])
--- 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)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)