/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 brzlib/plugins/launchpad/lp_propose.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

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 ... import (
 
17
from __future__ import absolute_import
 
18
 
 
19
from brzlib import (
18
20
    errors,
19
21
    hooks,
20
22
    )
21
 
from ...lazy_import import lazy_import
 
23
from brzlib.lazy_import import lazy_import
22
24
lazy_import(globals(), """
23
25
import webbrowser
24
26
 
25
 
from breezy import (
 
27
from brzlib import (
26
28
    msgeditor,
27
29
    )
28
 
from breezy.i18n import gettext
29
 
from breezy.plugins.launchpad import (
 
30
from brzlib.i18n import gettext
 
31
from brzlib.plugins.launchpad import (
30
32
    lp_api,
 
33
    lp_registration,
31
34
    )
32
35
""")
33
36
 
36
39
    """Hooks for proposing a merge on Launchpad."""
37
40
 
38
41
    def __init__(self):
39
 
        hooks.Hooks.__init__(self, "breezy.plugins.launchpad.lp_propose",
40
 
                             "Proposer.hooks")
 
42
        hooks.Hooks.__init__(self, "brzlib.plugins.launchpad.lp_propose",
 
43
            "Proposer.hooks")
41
44
        self.add_hook('get_prerequisite',
42
 
                      "Return the prerequisite branch for proposing as merge.", (2, 1))
 
45
            "Return the prerequisite branch for proposing as merge.", (2, 1))
43
46
        self.add_hook('merge_proposal_body',
44
 
                      "Return an initial body for the merge proposal message.", (2, 1))
 
47
            "Return an initial body for the merge proposal message.", (2, 1))
45
48
 
46
49
 
47
50
class Proposer(object):
66
69
        """
67
70
        self.tree = tree
68
71
        if staging:
69
 
            lp_base_url = lp_api.uris.STAGING_SERVICE_ROOT
 
72
            lp_instance = 'staging'
70
73
        else:
71
 
            lp_base_url = lp_api.uris.LPNET_SERVICE_ROOT
72
 
        self.launchpad = lp_api.connect_launchpad(lp_base_url)
 
74
            lp_instance = 'production'
 
75
        service = lp_registration.LaunchpadService(lp_instance=lp_instance)
 
76
        self.launchpad = lp_api.login(service)
73
77
        self.source_branch = lp_api.LaunchpadBranch.from_bzr(
74
78
            self.launchpad, source_branch)
75
79
        if target_branch is None:
99
103
        for rdata in self.reviews:
100
104
            uniquename = "%s (%s)" % (rdata[0].display_name, rdata[0].name)
101
105
            info.append('Reviewer: %s, type "%s"\n' % (uniquename, rdata[1]))
102
 
        with self.source_branch.bzr.lock_read(), \
103
 
                self.target_branch.bzr.lock_read():
104
 
            body = self.get_initial_body()
 
106
        self.source_branch.bzr.lock_read()
 
107
        try:
 
108
            self.target_branch.bzr.lock_read()
 
109
            try:
 
110
                body = self.get_initial_body()
 
111
            finally:
 
112
                self.target_branch.bzr.unlock()
 
113
        finally:
 
114
            self.source_branch.bzr.unlock()
105
115
        initial_comment = msgeditor.edit_commit_message(''.join(info),
106
116
                                                        start_message=body)
107
117
        return initial_comment.strip().encode('utf-8')
118
128
            files = modified_files(lca_tree, source_tree)
119
129
            return list(files)
120
130
        target_loc = ('bzr+ssh://bazaar.launchpad.net/%s' %
121
 
                      self.target_branch.lp.unique_name)
 
131
                       self.target_branch.lp.unique_name)
122
132
        body = None
123
133
        for hook in self.hooks['merge_proposal_body']:
124
134
            body = hook({
132
142
    def get_source_revid(self):
133
143
        """Get the revision ID of the source branch."""
134
144
        source_branch = self.source_branch.bzr
135
 
        with source_branch.lock_read():
 
145
        source_branch.lock_read()
 
146
        try:
136
147
            return source_branch.last_revision()
 
148
        finally:
 
149
            source_branch.unlock()
137
150
 
138
151
    def check_proposal(self):
139
152
        """Check that the submission is sensible."""
161
174
 
162
175
    def call_webservice(self, call, *args, **kwargs):
163
176
        """Make a call to the webservice, wrapping failures.
164
 
 
 
177
        
165
178
        :param call: The call to make.
166
179
        :param *args: *args for the call.
167
180
        :param **kwargs: **kwargs for the call.
170
183
        from lazr.restfulclient import errors as restful_errors
171
184
        try:
172
185
            return call(*args, **kwargs)
173
 
        except restful_errors.HTTPError as e:
 
186
        except restful_errors.HTTPError, e:
174
187
            error_lines = []
175
188
            for line in e.content.splitlines():
176
189
                if line.startswith('Traceback (most recent call last):'):
183
196
        self.call_webservice(
184
197
            mp.createComment,
185
198
            vote=u'Approve',
186
 
            subject='',  # Use the default subject.
 
199
            subject='', # Use the default subject.
187
200
            content=u"Rubberstamp! Proposer approves of own proposal.")
188
201
        self.call_webservice(mp.setStatus, status=u'Approved', revid=revid)
189
202
 
222
235
 
223
236
def modified_files(old_tree, new_tree):
224
237
    """Return a list of paths in the new tree with modified contents."""
225
 
    for change in new_tree.iter_changes(old_tree):
226
 
        if change.changed_content and change.kind[1] == 'file':
 
238
    for f, (op, path), c, v, p, n, (ok, k), e in new_tree.iter_changes(
 
239
        old_tree):
 
240
        if c and k == 'file':
227
241
            yield str(path)