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

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

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 ... import (
18
20
    errors,
19
21
    hooks,
28
30
from breezy.i18n import gettext
29
31
from breezy.plugins.launchpad import (
30
32
    lp_api,
 
33
    lp_registration,
31
34
    )
32
35
""")
33
36
 
37
40
 
38
41
    def __init__(self):
39
42
        hooks.Hooks.__init__(self, "breezy.plugins.launchpad.lp_propose",
40
 
                             "Proposer.hooks")
 
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:
118
122
            files = modified_files(lca_tree, source_tree)
119
123
            return list(files)
120
124
        target_loc = ('bzr+ssh://bazaar.launchpad.net/%s' %
121
 
                      self.target_branch.lp.unique_name)
 
125
                       self.target_branch.lp.unique_name)
122
126
        body = None
123
127
        for hook in self.hooks['merge_proposal_body']:
124
128
            body = hook({
138
142
    def check_proposal(self):
139
143
        """Check that the submission is sensible."""
140
144
        if self.source_branch.lp.self_link == self.target_branch.lp.self_link:
141
 
            raise errors.CommandError(
 
145
            raise errors.BzrCommandError(
142
146
                'Source and target branches must be different.')
143
147
        for mp in self.source_branch.lp.landing_targets:
144
148
            if mp.queue_status in ('Merged', 'Rejected'):
145
149
                continue
146
150
            if mp.target_branch.self_link == self.target_branch.lp.self_link:
147
 
                raise errors.CommandError(gettext(
 
151
                raise errors.BzrCommandError(gettext(
148
152
                    'There is already a branch merge proposal: %s') %
149
153
                    lp_api.canonical_url(mp))
150
154
 
161
165
 
162
166
    def call_webservice(self, call, *args, **kwargs):
163
167
        """Make a call to the webservice, wrapping failures.
164
 
 
 
168
        
165
169
        :param call: The call to make.
166
170
        :param *args: *args for the call.
167
171
        :param **kwargs: **kwargs for the call.
183
187
        self.call_webservice(
184
188
            mp.createComment,
185
189
            vote=u'Approve',
186
 
            subject='',  # Use the default subject.
 
190
            subject='', # Use the default subject.
187
191
            content=u"Rubberstamp! Proposer approves of own proposal.")
188
192
        self.call_webservice(mp.setStatus, status=u'Approved', revid=revid)
189
193
 
222
226
 
223
227
def modified_files(old_tree, new_tree):
224
228
    """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':
 
229
    for f, (op, path), c, v, p, n, (ok, k), e in new_tree.iter_changes(
 
230
        old_tree):
 
231
        if c and k == 'file':
227
232
            yield str(path)