Mercurial > treepkg
changeset 122:6e34fc4ebe39
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.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 22 May 2008 09:58:57 +0000 |
parents | 890bb70920d6 |
children | 37aadd33ffab |
files | test/test_builder.py treepkg/builder.py |
diffstat | 2 files changed, 60 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_builder.py Wed May 21 16:47:34 2008 +0000 +++ b/test/test_builder.py Thu May 22 09:58:57 2008 +0000 @@ -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")
--- a/treepkg/builder.py Wed May 21 16:47:34 2008 +0000 +++ b/treepkg/builder.py Thu May 22 09:58:57 2008 +0000 @@ -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