changeset 466:79be3c00ae69

Applied patch to #188 for stable/configurable names of build directories. Thanks to Allen Bierbaum for the patch.
author cmlenz
date Tue, 23 Oct 2007 15:36:06 +0000
parents 04205ba5dc98
children 5c9f34b18236
files bitten/master.py bitten/recipe.py bitten/slave.py bitten/tests/master.py
diffstat 4 files changed, 26 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/master.py
+++ b/bitten/master.py
@@ -163,6 +163,8 @@
         xml = xmlio.parse(config.recipe)
         xml.attr['path'] = config.path
         xml.attr['revision'] = build.rev
+        xml.attr['config'] = config.name
+        xml.attr['build'] = str(build.id)
         body = str(xml)
 
         req.send_response(200)
--- a/bitten/recipe.py
+++ b/bitten/recipe.py
@@ -46,14 +46,16 @@
     def __init__(self, basedir, config=None, vars=None):
         """Initialize the context.
         
-        :param basedir: a string containing the working directory for the build
+        :param basedir: a string containing the working directory for the build.
+                        (may be a pattern for replacement ex: 'build_${build}'
         :param config: the build slave configuration
         :type config: `Configuration`
-        """
-        self.basedir = os.path.realpath(basedir)
+        """        
         self.config = config or Configuration()
         self.vars = vars or {}
         self.output = []
+        self.basedir = os.path.realpath(self.config.interpolate(basedir,
+                                                                **self.vars))
 
     def run(self, step, namespace, name, attr):
         """Run the specified recipe command.
--- a/bitten/slave.py
+++ b/bitten/slave.py
@@ -63,7 +63,8 @@
     """BEEP initiator implementation for the build slave."""
 
     def __init__(self, url, name=None, config=None, dry_run=False,
-                 work_dir=None, keep_files=False, single_build=False,
+                 work_dir=None, build_dir="build_${build}",
+                 keep_files=False, single_build=False,
                  poll_interval=300, username=None, password=None,
                  dump_reports=False):
         """Create the build slave instance.
@@ -75,6 +76,7 @@
         :param dry_run: wether the build outcome should not be reported back
                         to the master
         :param work_dir: the working directory to use for build execution
+        :param build_dir: the pattern to use for naming the build subdir
         :param keep_files: whether files and directories created for build
                            execution should be kept when done
         :param single_build: whether this slave should exit after completing a 
@@ -101,6 +103,7 @@
         elif not os.path.exists(work_dir):
             os.makedirs(work_dir)
         self.work_dir = work_dir
+        self.build_dir = build_dir
         self.keep_files = keep_files
         self.single_build = single_build
         self.poll_interval = poll_interval
@@ -206,11 +209,14 @@
     def _execute_build(self, build_url, fileobj):
         build_id = build_url and int(build_url.split('/')[-1]) or 0
         xml = xmlio.parse(fileobj)
-        basedir = os.path.join(self.work_dir, 'build_%d' % build_id)
-        if not os.path.exists(basedir):
-            os.mkdir(basedir)
         try:
-            recipe = Recipe(xml, basedir, self.config)
+            recipe = Recipe(xml, os.path.join(self.work_dir, self.build_dir), 
+                            self.config)
+            basedir = recipe.ctxt.basedir
+            log.debug('Running build in directory %s' % basedir)	
+            if not os.path.exists(basedir):
+                os.mkdir(basedir)
+
             for step in recipe:
                 log.info('Executing build step %r', step.id)
                 if not self._execute_step(build_url, recipe, step):
@@ -308,6 +314,10 @@
     group = parser.add_option_group('building')
     group.add_option('-d', '--work-dir', action='store', dest='work_dir',
                      metavar='DIR', help='working directory for builds')
+    group.add_option('--build-dir', action='store', dest='build_dir',
+                     default = 'build_${config}_${build}',
+                     help='name pattern for the build dir to use inside the '
+                          'working dir ["%default"]')
     group.add_option('-k', '--keep-files', action='store_true',
                      dest='keep_files', 
                      help='don\'t delete files after builds')
@@ -354,6 +364,7 @@
 
     slave = BuildSlave(url, name=options.name, config=options.config,
                        dry_run=options.dry_run, work_dir=options.work_dir,
+                       build_dir=options.build_dir,
                        keep_files=options.keep_files,
                        single_build=options.single_build,
                        poll_interval=options.interval,
--- a/bitten/tests/master.py
+++ b/bitten/tests/master.py
@@ -213,12 +213,13 @@
             self.fail('Expected RequestDone')
         except RequestDone:
             self.assertEqual(200, outheaders['Status'])
-            self.assertEqual('39', outheaders['Content-Length'])
+            self.assertEqual('63', outheaders['Content-Length'])
             self.assertEqual('application/x-bitten+xml',
                              outheaders['Content-Type'])
             self.assertEqual('attachment; filename=recipe_test_r123.xml',
                              outheaders['Content-Disposition'])
-            self.assertEqual('<build path="somepath" revision="123"/>',
+            self.assertEqual('<build build="1" config="test"'
+                             ' path="somepath" revision="123"/>',
                              outbody.getvalue())
 
             # Make sure the started timestamp has been set
Copyright (C) 2012-2017 Edgewall Software