239
238
def _do_merges(self, branch_url, imply_commit_message):
240
existing_pid = get_pid()
241
if existing_pid is None:
244
# Check how long the lock has been there.
245
lock_creation_time = os.stat(self.config.PID_FILE)[-1]
247
locked_period = now - lock_creation_time
248
# If the locked_period is greater than the allowed, it probably
249
# means the test suite is stuck.
250
message = 'Tarmac lock file in place for %d seconds, PID: %d'
251
if locked_period > int(self.config.allowed_lock_period):
252
self.logger.info(message % (locked_period, get_pid()))
253
raise TarmacCommandError(message % (locked_period, get_pid()))
241
except PidfileExistsError, e:
242
message = "Is there another instance of Tarmac Running? %s" % e
243
if e.lifetime > int(self.config.allowed_lock_period):
244
# If the locked_period is greater than the allowed, it
245
# probably means the test suite is stuck.
246
self.logger.info(message)
247
raise TarmacCommandError(message)
255
self.logger.info(message % (locked_period, get_pid()))
249
self.logger.info(message)
258
target = Branch.create(
259
self.launchpad.branches.getByUrl(url=branch_url), self.config,
260
imply_commit_message=imply_commit_message)
262
if not target.get_merge_proposals():
265
self.logger.debug('Firing tarmac_pre_merge hook')
266
tarmac_hooks['tarmac_pre_merge'].fire(self, target)
269
# revno to restore to if bundle merge fails.
270
restore_revno = target.tree.branch.revno() + 1
271
results = target.merge_branches()
272
# Use a set to collect the proposals. We don't want
273
# duplicates since results generator will return the (source,
274
# proposal) tuple twice, once for each pre and post commit hook.
275
collected_proposals = set()
278
(hook, source, proposal) = results.next()
279
collected_proposals.add((source, proposal))
280
self._fire_merge_hook(
281
results, hook, target, source, proposal)
282
except StopIteration:
284
tarmac_hooks['tarmac_bundle_merge'].fire(
285
self, target, restore_revno, collected_proposals)
287
# This except is here because we need the else and can't have it
288
# without an except as well.
292
self.logger.debug('Firing tarmac_post_merge hook')
293
tarmac_hooks['tarmac_post_merge'].fire(self, target)
294
# Push target.tree.branch to location branch_url.
252
target = Branch.create(
253
self.launchpad.branches.getByUrl(url=branch_url), self.config,
254
imply_commit_message=imply_commit_message)
256
if not target.get_merge_proposals():
259
self.logger.debug('Firing tarmac_pre_merge hook')
260
tarmac_hooks['tarmac_pre_merge'].fire(self, target)
263
# revno to restore to if bundle merge fails.
264
restore_revno = target.tree.branch.revno() + 1
265
results = target.merge_branches()
266
collected_proposals = []
269
(hook, source, proposal) = results.next()
270
if hook == 'tarmac_post_commit':
271
# We only want the proposals that have not been
273
collected_proposals.append((source, proposal))
274
self._fire_merge_hook(
275
results, hook, target, source, proposal)
276
except StopIteration:
278
if collected_proposals:
279
# We actually have something to do!
280
# This hook is expected to raise an exception if
281
# tests fail. The hook is probably the one found in
282
# plugins/bundlecommand.py.
283
tarmac_hooks['tarmac_bundle_merge'].fire(
284
self, target, restore_revno, collected_proposals)
285
self.logger.debug('Firing tarmac_post_merge hook')
286
tarmac_hooks['tarmac_post_merge'].fire(self, target)
287
# Push target.tree.branch to location branch_url.