/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/lp_propose.py

  • Committer: Robert Collins
  • Date: 2010-05-21 04:16:47 UTC
  • mto: This revision was merged to the branch mainline in revision 5248.
  • Revision ID: robertc@robertcollins.net-20100521041647-1of2t3xt0opjt95m
Refactor to make calling the webservice cleaner.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
            self.target_branch = lp_api.LaunchpadBranch.from_bzr(
82
82
                self.launchpad, target_branch)
83
83
        self.commit_message = message
 
84
        # XXX: this is where bug lp:583638 could be tackled.
84
85
        if reviews == []:
85
86
            target_reviewer = self.target_branch.lp.reviewer
86
87
            if target_reviewer is None:
160
161
                 'prerequisite_branch': prerequisite_branch})
161
162
        return prerequisite_branch
162
163
 
 
164
    def call_webservice(self, call, *args, **kwargs):
 
165
        """Make a call to the webservice, wrapping failures.
 
166
        
 
167
        :param call: The call to make.
 
168
        :param *args: *args for the call.
 
169
        :param **kwargs: **kwargs for the call.
 
170
        :return: The result of calling call(*args, *kwargs).
 
171
        """
 
172
        try:
 
173
            return call(*args, **kwargs)
 
174
        except restful_errors.HTTPError, e:
 
175
            error_lines = []
 
176
            for line in e.content.splitlines():
 
177
                if line.startswith('Traceback (most recent call last):'):
 
178
                    break
 
179
                error_lines.append(line)
 
180
            raise Exception(''.join(error_lines))
 
181
 
163
182
    def create_proposal(self):
164
183
        """Perform the submission."""
165
184
        prerequisite_branch = self._get_prerequisite_branch()
175
194
            review_types.append(review_type)
176
195
            reviewers.append(reviewer.self_link)
177
196
        initial_comment = self.get_comment(prerequisite_branch)
178
 
        try:
179
 
            mp = self.source_branch.lp.createMergeProposal(
180
 
                target_branch=self.target_branch.lp,
181
 
                prerequisite_branch=prereq,
182
 
                initial_comment=initial_comment,
183
 
                commit_message=self.commit_message, reviewers=reviewers,
184
 
                review_types=review_types)
185
 
        except restful_errors.HTTPError, e:
186
 
            error_lines = []
187
 
            for line in e.content.splitlines():
188
 
                if line.startswith('Traceback (most recent call last):'):
189
 
                    break
190
 
                error_lines.append(line)
191
 
            raise Exception(''.join(error_lines))
192
 
        else:
193
 
            webbrowser.open(canonical_url(mp))
 
197
        mp = self.call_webservice(
 
198
            self.source_branch.lp.createMergeProposal,
 
199
            target_branch=self.target_branch.lp,
 
200
            prerequisite_branch=prereq,
 
201
            initial_comment=initial_comment,
 
202
            commit_message=self.commit_message, reviewers=reviewers,
 
203
            review_types=review_types)
 
204
        webbrowser.open(canonical_url(mp))
194
205
 
195
206
 
196
207
def modified_files(old_tree, new_tree):