# HG changeset patch # User cmlenz # Date 1193153766 0 # Node ID 79be3c00ae6926e0078ccc3e72e736f09a48c8fb # Parent 04205ba5dc9897818f92c93a39b4b6df0abec783 Applied patch to #188 for stable/configurable names of build directories. Thanks to Allen Bierbaum for the patch. diff --git a/bitten/master.py b/bitten/master.py --- 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) diff --git a/bitten/recipe.py b/bitten/recipe.py --- 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. diff --git a/bitten/slave.py b/bitten/slave.py --- 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, diff --git a/bitten/tests/master.py b/bitten/tests/master.py --- 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('', + self.assertEqual('', outbody.getvalue()) # Make sure the started timestamp has been set