[Treepkg-commits] r47 - in trunk: test treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 22 11:58:57 CEST 2008


Author: bh
Date: 2008-05-22 11:58:57 +0200 (Thu, 22 May 2008)
New Revision: 47

Modified:
   trunk/test/test_builder.py
   trunk/treepkg/builder.py
Log:
New arguments for the PBuilder.build method:

 - bindmounts to specify extra directories to be bind-mounted in the
   chroot (corresponds to pbuilder's --bindmounts option)

 - extra_packages to specify extra packages to be installed in the
   chroot (corresponds to pbuilder's --extrapackages option)

Also adds corresponding test cases.


Modified: trunk/test/test_builder.py
===================================================================
--- trunk/test/test_builder.py	2008-05-21 16:47:34 UTC (rev 46)
+++ trunk/test/test_builder.py	2008-05-22 09:58:57 UTC (rev 47)
@@ -64,6 +64,47 @@
                                  'my_dsc_file'])
         self.failUnless(os.path.isdir(binary_dir_name))
 
+    def test_build_with_bindmounts(self):
+        """Tests the PBuilder.build method with the bindmounts parameter"""
+        binary_dir_name = self.temp_file_name("binary")
+        if os.path.exists(binary_dir_name):
+            os.rmdir(binary_dir_name)
+        # sanity check: the binary directory must not exist yet.
+        self.failIf(os.path.exists(binary_dir_name))
+
+        builder = PBuilder("my_pbuilderrc", self.root_command)
+        builder.build("my_dsc_file", binary_dir_name, "the_logfile",
+                      bindmounts=["/home/builder/tracks",
+                                  "/home/builder/pbuilder"])
+        self.check_command_line(['/usr/sbin/pbuilder', 'build',
+                                 '--configfile', 'my_pbuilderrc',
+                                 '--bindmounts', "/home/builder/tracks",
+                                 '--bindmounts', "/home/builder/pbuilder",
+                                 '--logfile', 'the_logfile',
+                                 '--buildresult', binary_dir_name,
+                                 'my_dsc_file'])
+        self.failUnless(os.path.isdir(binary_dir_name))
+
+    def test_build_with_extra_packages(self):
+        """Tests the PBuilder.build method with the extra_packages parameter"""
+        binary_dir_name = self.temp_file_name("binary")
+        if os.path.exists(binary_dir_name):
+            os.rmdir(binary_dir_name)
+        # sanity check: the binary directory must not exist yet.
+        self.failIf(os.path.exists(binary_dir_name))
+
+        builder = PBuilder("my_pbuilderrc", self.root_command)
+        builder.build("my_dsc_file", binary_dir_name, "the_logfile",
+                      extra_packages=["subversion", "texinfo"])
+        self.check_command_line(['/usr/sbin/pbuilder', 'build',
+                                 '--configfile', 'my_pbuilderrc',
+                                 '--extrapackages', "subversion",
+                                 '--extrapackages', "texinfo",
+                                 '--logfile', 'the_logfile',
+                                 '--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")

Modified: trunk/treepkg/builder.py
===================================================================
--- trunk/treepkg/builder.py	2008-05-21 16:47:34 UTC (rev 46)
+++ trunk/treepkg/builder.py	2008-05-22 09:58:57 UTC (rev 47)
@@ -31,19 +31,35 @@
         self.pbuilderrc = pbuilderrc
         self.root_cmd = root_cmd
 
-    def build(self, dsc_file, binary_dir, logfile):
+    def build(self, dsc_file, binary_dir, logfile, bindmounts=(),
+              extra_packages=()):
         """Build a binary packager from a source package
         Parameters:
            dsc_file -- name of the debian .dsc file of the source package
            binary_dir -- name of the directory to receive the binary packages
            logfile -- name of the logfile of the build
+           bindmounts -- Sequence of directory names that should be
+                         bind-mounted in the pbuilder chroot
+                         environment
+           extra_packages -- Extra packages to install
+           extra_env -- mapping with extra environment variables to set
+                        when runing the pbuilder process.  If pbuilder
+                        is started via sudo, make sure that sudo does
+                        not remove these variables when it starts
+                        pbuilder
         """
         util.ensure_directory(binary_dir)
+        args = []
+        for mount in bindmounts:
+            args.extend(["--bindmounts", mount])
+        for pkg in extra_packages:
+            args.extend(["--extrapackages", pkg])
         run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build"
-                           " --configfile $pbuilderrc"
+                           " --configfile $pbuilderrc @args"
                            " --logfile $logfile --buildresult $bindir $dsc",
                            rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
-                           logfile=logfile, bindir=binary_dir, dsc=dsc_file),
+                           logfile=logfile, bindir=binary_dir, dsc=dsc_file,
+                           args=args),
                  suppress_output=True)
         # remove the source package files put into the binary directory
         # by pbuilder



More information about the Treepkg-commits mailing list