~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 - 2008 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
36
36
from bzrlib.directory_service import directories
37
37
from bzrlib.errors import (
38
38
    BzrCommandError,
 
39
    DependencyNotPresent,
39
40
    InvalidURL,
40
41
    NoPublicBranch,
41
42
    NotBranchError,
42
43
    )
43
44
from bzrlib.help_topics import topic_registry
44
 
from bzrlib.plugins.launchpad.lp_registration import (
45
 
    LaunchpadService,
46
 
    NotLaunchpadBranch,
47
 
    )
48
45
 
49
46
 
50
47
class cmd_register_branch(Command):
111
108
            link_bug=None,
112
109
            dry_run=False):
113
110
        from bzrlib.plugins.launchpad.lp_registration import (
114
 
            LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest,
115
 
            DryRunLaunchpadService)
 
111
            BranchRegistrationRequest, BranchBugLinkRequest,
 
112
            DryRunLaunchpadService, LaunchpadService)
116
113
        if public_url is None:
117
114
            try:
118
115
                b = _mod_branch.Branch.open_containing('.')[0]
147
144
            # Run on service entirely in memory
148
145
            service = DryRunLaunchpadService()
149
146
        service.gather_user_credentials()
150
 
        branch_object_url = rego.submit(service)
 
147
        rego.submit(service)
151
148
        if link_bug:
152
 
            link_bug_url = linko.submit(service)
 
149
            linko.submit(service)
153
150
        print 'Branch registered.'
154
151
 
155
152
register_command(cmd_register_branch)
170
167
        """Yield possible external locations for the branch at 'location'."""
171
168
        yield location
172
169
        try:
173
 
            branch = _mod_branch.Branch.open(location)
 
170
            branch = _mod_branch.Branch.open_containing(location)[0]
174
171
        except NotBranchError:
175
172
            return
176
173
        branch_url = branch.get_public_branch()
181
178
            yield branch_url
182
179
 
183
180
    def _get_web_url(self, service, location):
 
181
        from bzrlib.plugins.launchpad.lp_registration import (
 
182
            NotLaunchpadBranch)
184
183
        for branch_url in self._possible_locations(location):
185
184
            try:
186
185
                return service.get_web_url_from_branch_url(branch_url)
189
188
        raise NotLaunchpadBranch(branch_url)
190
189
 
191
190
    def run(self, location=None, dry_run=False):
 
191
        from bzrlib.plugins.launchpad.lp_registration import (
 
192
            LaunchpadService)
192
193
        if location is None:
193
194
            location = u'.'
194
195
        web_url = self._get_web_url(LaunchpadService(), location)
226
227
        ]
227
228
 
228
229
    def run(self, name=None, no_check=False, verbose=False):
 
230
        # This is totally separate from any launchpadlib login system.
229
231
        from bzrlib.plugins.launchpad import account
230
232
        check_account = not no_check
231
233
 
255
257
register_command(cmd_launchpad_login)
256
258
 
257
259
 
 
260
# XXX: cmd_launchpad_mirror is untested
 
261
class cmd_launchpad_mirror(Command):
 
262
    """Ask Launchpad to mirror a branch now."""
 
263
 
 
264
    aliases = ['lp-mirror']
 
265
    takes_args = ['location?']
 
266
 
 
267
    def run(self, location='.'):
 
268
        from bzrlib.plugins.launchpad import lp_api
 
269
        from bzrlib.plugins.launchpad.lp_registration import LaunchpadService
 
270
        branch = _mod_branch.Branch.open(location)
 
271
        service = LaunchpadService()
 
272
        launchpad = lp_api.login(service)
 
273
        lp_branch = lp_api.load_branch(launchpad, branch)
 
274
        lp_branch.requestMirror()
 
275
 
 
276
 
 
277
register_command(cmd_launchpad_mirror)
 
278
 
 
279
 
258
280
def _register_directory():
259
281
    directories.register_lazy('lp:', 'bzrlib.plugins.launchpad.lp_directory',
260
282
                              'LaunchpadDirectory',
262
284
_register_directory()
263
285
 
264
286
 
265
 
def test_suite():
266
 
    """Called by bzrlib to fetch tests for this plugin"""
267
 
    from unittest import TestSuite, TestLoader
268
 
    from bzrlib.plugins.launchpad import (
269
 
        test_account,
270
 
        test_lp_directory,
271
 
        test_lp_login,
272
 
        test_lp_open,
273
 
        test_lp_service,
274
 
        test_register,
275
 
        )
 
287
def load_tests(basic_tests, module, loader):
 
288
    testmod_names = [
 
289
        'test_account',
 
290
        'test_register',
 
291
        'test_lp_api',
 
292
        'test_lp_directory',
 
293
        'test_lp_login',
 
294
        'test_lp_open',
 
295
        'test_lp_service',
 
296
        ]
 
297
    basic_tests.addTest(loader.loadTestsFromModuleNames(
 
298
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
299
    return basic_tests
276
300
 
277
 
    loader = TestLoader()
278
 
    suite = TestSuite()
279
 
    for module in [
280
 
        test_account,
281
 
        test_register,
282
 
        test_lp_directory,
283
 
        test_lp_login,
284
 
        test_lp_open,
285
 
        test_lp_service,
286
 
        ]:
287
 
        suite.addTests(loader.loadTestsFromModule(module))
288
 
    return suite
289
301
 
290
302
_launchpad_help = """Integration with Launchpad.net
291
303