Rev 5246: Refactor to make calling the webservice cleaner. in http://bazaar.launchpad.net/~lifeless/bzr/propose-accepted

Robert Collins robertc at robertcollins.net
Fri May 21 05:16:48 BST 2010


At http://bazaar.launchpad.net/~lifeless/bzr/propose-accepted

------------------------------------------------------------
revno: 5246
revision-id: robertc at robertcollins.net-20100521041647-1of2t3xt0opjt95m
parent: robertc at robertcollins.net-20100521032843-9bc6ad9gxjodmoil
committer: Robert Collins <robertc at robertcollins.net>
branch nick: propose-accepted
timestamp: Fri 2010-05-21 16:16:47 +1200
message:
  Refactor to make calling the webservice cleaner.
=== modified file 'bzrlib/plugins/launchpad/lp_propose.py'
--- a/bzrlib/plugins/launchpad/lp_propose.py	2010-05-20 18:23:10 +0000
+++ b/bzrlib/plugins/launchpad/lp_propose.py	2010-05-21 04:16:47 +0000
@@ -81,6 +81,7 @@
             self.target_branch = lp_api.LaunchpadBranch.from_bzr(
                 self.launchpad, target_branch)
         self.commit_message = message
+        # XXX: this is where bug lp:583638 could be tackled.
         if reviews == []:
             target_reviewer = self.target_branch.lp.reviewer
             if target_reviewer is None:
@@ -160,6 +161,24 @@
                  'prerequisite_branch': prerequisite_branch})
         return prerequisite_branch
 
+    def call_webservice(self, call, *args, **kwargs):
+        """Make a call to the webservice, wrapping failures.
+        
+        :param call: The call to make.
+        :param *args: *args for the call.
+        :param **kwargs: **kwargs for the call.
+        :return: The result of calling call(*args, *kwargs).
+        """
+        try:
+            return call(*args, **kwargs)
+        except restful_errors.HTTPError, e:
+            error_lines = []
+            for line in e.content.splitlines():
+                if line.startswith('Traceback (most recent call last):'):
+                    break
+                error_lines.append(line)
+            raise Exception(''.join(error_lines))
+
     def create_proposal(self):
         """Perform the submission."""
         prerequisite_branch = self._get_prerequisite_branch()
@@ -175,22 +194,14 @@
             review_types.append(review_type)
             reviewers.append(reviewer.self_link)
         initial_comment = self.get_comment(prerequisite_branch)
-        try:
-            mp = self.source_branch.lp.createMergeProposal(
-                target_branch=self.target_branch.lp,
-                prerequisite_branch=prereq,
-                initial_comment=initial_comment,
-                commit_message=self.commit_message, reviewers=reviewers,
-                review_types=review_types)
-        except restful_errors.HTTPError, e:
-            error_lines = []
-            for line in e.content.splitlines():
-                if line.startswith('Traceback (most recent call last):'):
-                    break
-                error_lines.append(line)
-            raise Exception(''.join(error_lines))
-        else:
-            webbrowser.open(canonical_url(mp))
+        mp = self.call_webservice(
+            self.source_branch.lp.createMergeProposal,
+            target_branch=self.target_branch.lp,
+            prerequisite_branch=prereq,
+            initial_comment=initial_comment,
+            commit_message=self.commit_message, reviewers=reviewers,
+            review_types=review_types)
+        webbrowser.open(canonical_url(mp))
 
 
 def modified_files(old_tree, new_tree):




More information about the bazaar-commits mailing list