~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2016-01-21 17:48:07 UTC
  • mto: This revision was merged to the branch mainline in revision 6613.
  • Revision ID: v.ladeuil+lp@free.fr-20160121174807-g4ybpaij9ln5wj6a
Make all transport put_bytes() raises TypeError when given unicode strings rather than bytes.

There was a mix of AssertionError or UnicodeEncodeError.

Also deleted test_put_file_unicode() which was bogus, files contain bytes not unicode strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
from bzrlib import (
18
20
    errors,
19
21
    hooks,
25
27
from bzrlib import (
26
28
    msgeditor,
27
29
    )
 
30
from bzrlib.i18n import gettext
28
31
from bzrlib.plugins.launchpad import (
29
32
    lp_api,
30
33
    lp_registration,
49
52
    hooks = ProposeMergeHooks()
50
53
 
51
54
    def __init__(self, tree, source_branch, target_branch, message, reviews,
52
 
                 staging=False, approve=False):
 
55
                 staging=False, approve=False, fixes=None):
53
56
        """Constructor.
54
57
 
55
58
        :param tree: The working tree for the source branch.
87
90
                            for reviewer, review_type in
88
91
                            reviews]
89
92
        self.approve = approve
 
93
        self.fixes = fixes
90
94
 
91
95
    def get_comment(self, prerequisite_branch):
92
96
        """Determine the initial comment for the merge proposal."""
133
137
            })
134
138
        return body
135
139
 
 
140
    def get_source_revid(self):
 
141
        """Get the revision ID of the source branch."""
 
142
        source_branch = self.source_branch.bzr
 
143
        source_branch.lock_read()
 
144
        try:
 
145
            return source_branch.last_revision()
 
146
        finally:
 
147
            source_branch.unlock()
 
148
 
136
149
    def check_proposal(self):
137
150
        """Check that the submission is sensible."""
138
151
        if self.source_branch.lp.self_link == self.target_branch.lp.self_link:
142
155
            if mp.queue_status in ('Merged', 'Rejected'):
143
156
                continue
144
157
            if mp.target_branch.self_link == self.target_branch.lp.self_link:
145
 
                raise errors.BzrCommandError(
146
 
                    'There is already a branch merge proposal: %s' %
 
158
                raise errors.BzrCommandError(gettext(
 
159
                    'There is already a branch merge proposal: %s') %
147
160
                    lp_api.canonical_url(mp))
148
161
 
149
162
    def _get_prerequisite_branch(self):
176
189
                error_lines.append(line)
177
190
            raise Exception(''.join(error_lines))
178
191
 
 
192
    def approve_proposal(self, mp):
 
193
        revid = self.get_source_revid()
 
194
        self.call_webservice(
 
195
            mp.createComment,
 
196
            vote=u'Approve',
 
197
            subject='', # Use the default subject.
 
198
            content=u"Rubberstamp! Proposer approves of own proposal.")
 
199
        self.call_webservice(mp.setStatus, status=u'Approved', revid=revid)
 
200
 
179
201
    def create_proposal(self):
180
202
        """Perform the submission."""
181
203
        prerequisite_branch = self._get_prerequisite_branch()
199
221
            commit_message=self.commit_message, reviewers=reviewers,
200
222
            review_types=review_types)
201
223
        if self.approve:
202
 
            self.call_webservice(mp.setStatus, status='Approved')
 
224
            self.approve_proposal(mp)
 
225
        if self.fixes:
 
226
            if self.fixes.startswith('lp:'):
 
227
                self.fixes = self.fixes[3:]
 
228
            self.call_webservice(
 
229
                self.source_branch.lp.linkBug,
 
230
                bug=self.launchpad.bugs[int(self.fixes)])
203
231
        webbrowser.open(lp_api.canonical_url(mp))
204
232
 
205
233