# HG changeset patch # User Bernhard Herzog # Date 1211482394 0 # Node ID 68d829cac3ff33a30553c01d98c8d6223e296a25 # Parent 34e08d52956e1f0009ec6137b2a334a54f710539 New parameter for PBuilder.build: extra_env, a mapping with extra environment varaibles. Also add a test case. diff -r 34e08d52956e -r 68d829cac3ff test/test_builder.py --- a/test/test_builder.py Thu May 22 18:12:30 2008 +0000 +++ b/test/test_builder.py Thu May 22 18:53:14 2008 +0000 @@ -17,10 +17,14 @@ from filesupport import FileTestMixin # helper program to dump the command line arguments into a file so that -# test cases can check them. +# test cases can check them. Also if the environment variable +# TREEPKG_TEST is set, create the file named by it. dump_command_line_py = """ -import sys +import sys, os open(sys.argv[1], 'w').write(repr(sys.argv[2:])) +value = os.environ.get('TREEPKG_TEST') +if value: + open(value, 'w').close() """ class PBuilderTests(unittest.TestCase, FileTestMixin): @@ -105,6 +109,29 @@ 'my_dsc_file']) self.failUnless(os.path.isdir(binary_dir_name)) + def test_build_with_extra_env(self): + """Tests the PBuilder.build method with the extra_env parameter""" + binary_dir_name = self.temp_file_name("binary") + if os.path.exists(binary_dir_name): + os.rmdir(binary_dir_name) + env_test_file = self.temp_file_name(self.id() + "_envtest", remove=True) + # sanity check: the binary directory must not exist yet. + self.failIf(os.path.exists(binary_dir_name)) + # sanity check: the environment variable TREEPKG_TEST must not + # be set yet + self.failIf("TREEPKG_TEST" in os.environ) + + builder = PBuilder("my_pbuilderrc", self.root_command) + builder.build("my_dsc_file", binary_dir_name, "the_logfile", + extra_env=dict(TREEPKG_TEST=env_test_file)) + self.check_command_line(['/usr/sbin/pbuilder', 'build', + '--configfile', 'my_pbuilderrc', + '--logfile', 'the_logfile', + '--buildresult', binary_dir_name, + 'my_dsc_file']) + self.failUnless(os.path.isdir(binary_dir_name)) + self.failUnless(os.path.exists(env_test_file)) + def test_run_script(self): builder = PBuilder("my_pbuilderrc", self.root_command) builder.run_script("my_script", logfile="the_logfile") diff -r 34e08d52956e -r 68d829cac3ff treepkg/builder.py --- a/treepkg/builder.py Thu May 22 18:12:30 2008 +0000 +++ b/treepkg/builder.py Thu May 22 18:53:14 2008 +0000 @@ -32,7 +32,7 @@ self.root_cmd = root_cmd def build(self, dsc_file, binary_dir, logfile, bindmounts=(), - extra_packages=()): + extra_packages=(), extra_env=None): """Build a binary packager from a source package Parameters: dsc_file -- name of the debian .dsc file of the source package @@ -60,7 +60,8 @@ rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc, logfile=logfile, bindir=binary_dir, dsc=dsc_file, args=args), - suppress_output=True) + suppress_output=True, + extra_env=extra_env) # remove the source package files put into the binary directory # by pbuilder for filename in os.listdir(binary_dir):