~mars/tarmac/throwaway-merge-source

« back to all changes in this revision

Viewing changes to tarmac/bin.py

  • Committer: Paul Hummer
  • Date: 2009-07-11 04:18:18 UTC
  • mfrom: (131 tarmac)
  • mto: This revision was merged to the branch mainline in revision 132.
  • Revision ID: paul@eventuallyanyway.com-20090711041818-jirjz6ert780jcx9
Merge from trunk, resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009 Paul Hummer - See LICENSE
 
1
# Copyright 2009 Paul Hummer
 
2
# This file is part of Tarmac.
 
3
#
 
4
# Tarmac is free software: you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License version 3 as
 
6
# published by
 
7
# the Free Software Foundation.
 
8
#
 
9
# Tarmac is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with Tarmac.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
2
17
'''Code used by Tarmac scripts.'''
3
18
import atexit
4
19
import logging
13
28
from tarmac.branch import Branch
14
29
from tarmac.config import TarmacConfig
15
30
from tarmac.hooks import tarmac_hooks
 
31
from tarmac.exceptions import BranchHasConflicts
16
32
from tarmac.plugin import load_plugins
17
33
from tarmac.utils import get_launchpad_object
18
34
 
102
118
        logging.basicConfig(filename=self.configuration.log_file,
103
119
            level=logging.INFO)
104
120
        self.logger = logging.getLogger('tarmac-lander')
 
121
        if self.options.debug:
 
122
            stderr_handler = logging.StreamHandler(sys.stderr)
 
123
            stderr_handler.setLevel(logging.DEBUG)
 
124
            self.logger.addHandler(stderr_handler)
105
125
 
106
126
        # Write a pid file
107
127
        if not test_mode:
122
142
        parser.add_option('--test-command', type='string', default=None,
123
143
            metavar='TEST',
124
144
            help='The test command to run after merging a branch.')
 
145
        parser.add_option('--debug', default=False, action='store_true',
 
146
            help='Print information to the screen as well as logging.')
125
147
        return parser
126
148
 
127
149
    def _get_reviewers(self, candidate):
146
168
 
147
169
        project = launchpad.projects[self.project]
148
170
        try:
149
 
            trunk = Branch(project.development_focus.branch, create_tree=True)
 
171
            trunk = project.development_focus.branch
150
172
        except AttributeError:
151
173
            message = (
152
174
                'Oops!  It looks like you\'ve forgotten to specify a '
156
178
            print message
157
179
            sys.exit()
158
180
 
 
181
        self.logger.debug('Looking for landing candidates')
159
182
        candidates = [entry for entry in trunk.landing_candidates
160
183
                        if entry.queue_status == u'Approved' and
161
184
                        entry.commit_message]
 
185
 
162
186
        if not candidates:
163
187
            self.logger.info('No branches approved to land.')
164
188
            return
 
189
        else:
 
190
            self.logger.debug('Found %s candidates to land', len(candidates))
165
191
 
 
192
        self.logger.info('Downloading development target:\n    %s',
 
193
                         project.development_focus.branch)
 
194
        trunk = Branch(trunk, create_tree=True)
166
195
        for candidate in candidates:
167
196
 
168
197
            source_branch = Branch(candidate.source_branch)
169
198
 
170
199
            try:
171
200
                trunk.merge(source_branch)
 
201
 
 
202
            except BranchHasConflicts:
 
203
                # XXX: rockstar - This should also set the status, but it
 
204
                # appears that this is broken in Launchpad currently.
 
205
                candidate.createComment(
 
206
                    subject=u'Conflicts merging branch',
 
207
                    content=trunk.get_conflicts())
 
208
                trunk.cleanup()
 
209
                continue
 
210
 
172
211
            except PointlessMerge:
173
212
                trunk.cleanup()
174
213
                continue
183
222
                    trunk.commit(candidate.commit_message,
184
223
                                 authors=source_branch.authors)
185
224
 
 
225
                tarmac_hooks['post_tarmac_commit'].fire(
 
226
                    self.options, self.configuration, candidate, trunk)
 
227
 
186
228
            except Exception, e:
187
229
                print e
188
 
                trunk.cleanup()
189
230
 
190
 
            tarmac_hooks['post_tarmac_commit'].fire(
191
 
                self.options, self.configuration, candidate, trunk)
 
231
            trunk.cleanup()
192
232