Mercurial > bitten > bitten-test
comparison bitten/slave.py @ 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 | 8c3dfe0efe78 |
comparison
equal
deleted
inserted
replaced
465:04205ba5dc98 | 466:79be3c00ae69 |
---|---|
61 | 61 |
62 class BuildSlave(object): | 62 class BuildSlave(object): |
63 """BEEP initiator implementation for the build slave.""" | 63 """BEEP initiator implementation for the build slave.""" |
64 | 64 |
65 def __init__(self, url, name=None, config=None, dry_run=False, | 65 def __init__(self, url, name=None, config=None, dry_run=False, |
66 work_dir=None, keep_files=False, single_build=False, | 66 work_dir=None, build_dir="build_${build}", |
67 keep_files=False, single_build=False, | |
67 poll_interval=300, username=None, password=None, | 68 poll_interval=300, username=None, password=None, |
68 dump_reports=False): | 69 dump_reports=False): |
69 """Create the build slave instance. | 70 """Create the build slave instance. |
70 | 71 |
71 :param url: the URL of the build master, or the path to a build recipe | 72 :param url: the URL of the build master, or the path to a build recipe |
73 :param name: the name with which this slave should identify itself | 74 :param name: the name with which this slave should identify itself |
74 :param config: the path to the slave configuration file | 75 :param config: the path to the slave configuration file |
75 :param dry_run: wether the build outcome should not be reported back | 76 :param dry_run: wether the build outcome should not be reported back |
76 to the master | 77 to the master |
77 :param work_dir: the working directory to use for build execution | 78 :param work_dir: the working directory to use for build execution |
79 :param build_dir: the pattern to use for naming the build subdir | |
78 :param keep_files: whether files and directories created for build | 80 :param keep_files: whether files and directories created for build |
79 execution should be kept when done | 81 execution should be kept when done |
80 :param single_build: whether this slave should exit after completing a | 82 :param single_build: whether this slave should exit after completing a |
81 single build, or continue processing builds forever | 83 single build, or continue processing builds forever |
82 :param poll_interval: the time in seconds to wait between requesting | 84 :param poll_interval: the time in seconds to wait between requesting |
99 if not work_dir: | 101 if not work_dir: |
100 work_dir = tempfile.mkdtemp(prefix='bitten') | 102 work_dir = tempfile.mkdtemp(prefix='bitten') |
101 elif not os.path.exists(work_dir): | 103 elif not os.path.exists(work_dir): |
102 os.makedirs(work_dir) | 104 os.makedirs(work_dir) |
103 self.work_dir = work_dir | 105 self.work_dir = work_dir |
106 self.build_dir = build_dir | |
104 self.keep_files = keep_files | 107 self.keep_files = keep_files |
105 self.single_build = single_build | 108 self.single_build = single_build |
106 self.poll_interval = poll_interval | 109 self.poll_interval = poll_interval |
107 self.dump_reports = dump_reports | 110 self.dump_reports = dump_reports |
108 | 111 |
204 self._cancel_build(build_url) | 207 self._cancel_build(build_url) |
205 | 208 |
206 def _execute_build(self, build_url, fileobj): | 209 def _execute_build(self, build_url, fileobj): |
207 build_id = build_url and int(build_url.split('/')[-1]) or 0 | 210 build_id = build_url and int(build_url.split('/')[-1]) or 0 |
208 xml = xmlio.parse(fileobj) | 211 xml = xmlio.parse(fileobj) |
209 basedir = os.path.join(self.work_dir, 'build_%d' % build_id) | 212 try: |
210 if not os.path.exists(basedir): | 213 recipe = Recipe(xml, os.path.join(self.work_dir, self.build_dir), |
211 os.mkdir(basedir) | 214 self.config) |
212 try: | 215 basedir = recipe.ctxt.basedir |
213 recipe = Recipe(xml, basedir, self.config) | 216 log.debug('Running build in directory %s' % basedir) |
217 if not os.path.exists(basedir): | |
218 os.mkdir(basedir) | |
219 | |
214 for step in recipe: | 220 for step in recipe: |
215 log.info('Executing build step %r', step.id) | 221 log.info('Executing build step %r', step.id) |
216 if not self._execute_step(build_url, recipe, step): | 222 if not self._execute_step(build_url, recipe, step): |
217 log.warning('Stopping build due to failure') | 223 log.warning('Stopping build due to failure') |
218 break | 224 break |
306 help='the password to use when authenticating') | 312 help='the password to use when authenticating') |
307 | 313 |
308 group = parser.add_option_group('building') | 314 group = parser.add_option_group('building') |
309 group.add_option('-d', '--work-dir', action='store', dest='work_dir', | 315 group.add_option('-d', '--work-dir', action='store', dest='work_dir', |
310 metavar='DIR', help='working directory for builds') | 316 metavar='DIR', help='working directory for builds') |
317 group.add_option('--build-dir', action='store', dest='build_dir', | |
318 default = 'build_${config}_${build}', | |
319 help='name pattern for the build dir to use inside the ' | |
320 'working dir ["%default"]') | |
311 group.add_option('-k', '--keep-files', action='store_true', | 321 group.add_option('-k', '--keep-files', action='store_true', |
312 dest='keep_files', | 322 dest='keep_files', |
313 help='don\'t delete files after builds') | 323 help='don\'t delete files after builds') |
314 group.add_option('-s', '--single', action='store_true', | 324 group.add_option('-s', '--single', action='store_true', |
315 dest='single_build', | 325 dest='single_build', |
352 handler.setFormatter(formatter) | 362 handler.setFormatter(formatter) |
353 logger.addHandler(handler) | 363 logger.addHandler(handler) |
354 | 364 |
355 slave = BuildSlave(url, name=options.name, config=options.config, | 365 slave = BuildSlave(url, name=options.name, config=options.config, |
356 dry_run=options.dry_run, work_dir=options.work_dir, | 366 dry_run=options.dry_run, work_dir=options.work_dir, |
367 build_dir=options.build_dir, | |
357 keep_files=options.keep_files, | 368 keep_files=options.keep_files, |
358 single_build=options.single_build, | 369 single_build=options.single_build, |
359 poll_interval=options.interval, | 370 poll_interval=options.interval, |
360 username=options.username, password=options.password, | 371 username=options.username, password=options.password, |
361 dump_reports=options.dump_reports) | 372 dump_reports=options.dump_reports) |