~zorba-buildbot/tarmac/zorba-custom-tarmac

« back to all changes in this revision

Viewing changes to tarmac/bin/commands.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2011-01-05 17:25:58 UTC
  • mfrom: (382.2.1 args-as-config)
  • Revision ID: tarmac-20110105172558-6g9s8oat979ltwo5
Set all takes_options options in the TarmacConfig as global bool options
Ensure that ConfigParser.set gets passed a str() for the value

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import httplib2
3
3
import logging
4
4
import os
 
5
import re
5
6
 
6
7
from bzrlib.commands import Command
7
8
from bzrlib.errors import PointlessMerge
33
34
        set_up_logging(self.config)
34
35
        self.logger = logging.getLogger('tarmac')
35
36
 
 
37
        for option in self.takes_options:
 
38
            name = re.sub(r'-', '_', option.name)
 
39
            self.config.set('Tarmac', name, False)
 
40
 
36
41
    def _usage(self):
37
42
        """Custom _usage for referencing "tarmac" instead of "bzr."""
38
43
        s = 'tarmac ' + self.name() + ' '
146
151
        options.debug_option,
147
152
        options.imply_commit_message_option]
148
153
 
149
 
    def _do_merges(self, branch_url, imply_commit_message):
 
154
    def _do_merges(self, branch_url):
150
155
 
151
156
        lp_branch = self.launchpad.branches.getByUrl(url=branch_url)
152
157
 
153
 
        proposals = self._get_mergable_proposals_for_branch(
154
 
            lp_branch, imply_commit_message)
 
158
        proposals = self._get_mergable_proposals_for_branch(lp_branch)
155
159
 
156
160
        if not proposals:
157
161
            self.logger.info(
266
270
                revprops = {'merge_url': merge_url}
267
271
 
268
272
                commit_message = proposal.commit_message
269
 
                if commit_message is None and imply_commit_message:
 
273
                if commit_message is None and self.config.imply_commit_message:
270
274
                    commit_message = proposal.description
271
275
                target.commit(commit_message,
272
276
                             revprops=revprops,
290
294
        finally:
291
295
            target.cleanup()
292
296
 
293
 
    def _get_mergable_proposals_for_branch(self, lp_branch,
294
 
                                           imply_commit_message):
 
297
    def _get_mergable_proposals_for_branch(self, lp_branch):
295
298
        """Return a list of the mergable proposals for the given branch."""
296
299
        proposals = []
297
300
        for entry in lp_branch.landing_candidates:
303
306
                    "'Approved'".format(entry.queue_status))
304
307
                continue
305
308
 
306
 
            if not imply_commit_message and not entry.commit_message:
 
309
            if (not self.config.imply_commit_message and 
 
310
                not entry.commit_message):
307
311
                self.logger.debug(
308
312
                    "  Skipping proposal: proposal has no commit message")
309
313
                continue
326
330
 
327
331
        return reviews
328
332
 
329
 
    def run(self, branch_url=None, debug=False, http_debug=False,
330
 
            launchpad=None, imply_commit_message=False):
331
 
        if debug:
 
333
    def run(self, branch_url=None, launchpad=None, **kwargs):
 
334
        for key, value in kwargs.iteritems():
 
335
            self.config.set('Tarmac', key, value)
 
336
 
 
337
        if self.config.debug:
332
338
            set_up_debug_logging()
333
339
            self.logger.debug('Debug logging enabled')
334
 
        if http_debug:
 
340
        if self.config.http_debug:
335
341
            httplib2.debuglevel = 1
336
342
            self.logger.debug('HTTP debugging enabled.')
337
343
        self.logger.debug('Loading plugins')
350
356
                    'branch_url': branch_url})
351
357
            if not branch_url.startswith('lp:'):
352
358
                raise TarmacCommandError('Branch urls must start with lp:')
353
 
            self._do_merges(branch_url, imply_commit_message)
 
359
            self._do_merges(branch_url)
354
360
 
355
361
        else:
356
362
            for branch in self.config.branches:
358
364
                    'Merging approved branches against %(branch)s' % {
359
365
                        'branch': branch})
360
366
                try:
361
 
                    self._do_merges(branch, imply_commit_message)
 
367
                    self._do_merges(branch)
362
368
                except Exception, error:
363
369
                    self.logger.error(
364
370
                        'An error occurred trying to merge %s: %s',