/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 bzrlib/plugins/launchpad/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-16 13:12:40 UTC
  • mfrom: (6071 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6076.
  • Revision ID: v.ladeuil+lp@free.fr-20110816131240-gcyn9cik86dxwgz3
Merge into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
# see http://wiki.bazaar.canonical.com/Specs/BranchRegistrationTool
42
42
 
43
 
# Since we are a built-in plugin we share the bzrlib version
44
 
from bzrlib import version_info
45
 
 
46
43
from bzrlib.lazy_import import lazy_import
47
44
lazy_import(globals(), """
48
45
from bzrlib import (
49
 
    branch as _mod_branch,
50
 
    errors,
51
46
    ui,
52
47
    trace,
53
48
    )
54
49
""")
55
50
 
56
 
from bzrlib import bzrdir
 
51
from bzrlib import (
 
52
    branch as _mod_branch,
 
53
    bzrdir,
 
54
    lazy_regex,
 
55
    # Since we are a built-in plugin we share the bzrlib version
 
56
    version_info,
 
57
    )
57
58
from bzrlib.commands import (
58
 
        Command,
59
 
        register_command,
60
 
)
 
59
    Command,
 
60
    register_command,
 
61
    )
61
62
from bzrlib.directory_service import directories
62
63
from bzrlib.errors import (
63
64
    BzrCommandError,
64
 
    DependencyNotPresent,
 
65
    InvalidRevisionSpec,
65
66
    InvalidURL,
66
67
    NoPublicBranch,
67
68
    NotBranchError,
296
297
    def run(self, location='.'):
297
298
        from bzrlib.plugins.launchpad import lp_api
298
299
        from bzrlib.plugins.launchpad.lp_registration import LaunchpadService
299
 
        branch = _mod_branch.Branch.open(location)
 
300
        branch, _ = _mod_branch.Branch.open_containing(location)
300
301
        service = LaunchpadService()
301
302
        launchpad = lp_api.login(service)
302
 
        lp_branch = lp_api.load_branch(launchpad, branch)
303
 
        lp_branch.requestMirror()
 
303
        lp_branch = lp_api.LaunchpadBranch.from_bzr(launchpad, branch,
 
304
                create_missing=False)
 
305
        lp_branch.lp.requestMirror()
304
306
 
305
307
 
306
308
register_command(cmd_launchpad_mirror)
420
422
            merging_revision = graph.find_lefthand_merger(
421
423
                revision_id, b.last_revision())
422
424
            if merging_revision is None:
423
 
                raise errors.InvalidRevisionSpec(revision[0].user_spec, b)
 
425
                raise InvalidRevisionSpec(revision[0].user_spec, b)
424
426
        pb.update('Finding revno')
425
427
        return b.revision_id_to_revno(merging_revision)
426
428
 
462
464
 
463
465
_register_directory()
464
466
 
 
467
# This is kept in __init__ so that we don't load lp_api_lite unless the branch
 
468
# actually matches. That way we can avoid importing extra dependencies like
 
469
# json.
 
470
_package_branch = lazy_regex.lazy_compile(
 
471
    r'bazaar.launchpad.net.*?/'
 
472
    r'(?P<user>~[^/]+/)?(?P<archive>ubuntu|debian)/(?P<series>[^/]+/)?'
 
473
    r'(?P<project>[^/]+)(?P<branch>/[^/]+)?'
 
474
    )
 
475
 
 
476
def _get_package_branch_info(url):
 
477
    """Determine the packaging information for this URL.
 
478
 
 
479
    :return: If this isn't a packaging branch, return None. If it is, return
 
480
        (archive, series, project)
 
481
    """
 
482
    if url is None:
 
483
        return None
 
484
    m = _package_branch.search(url)
 
485
    if m is None:
 
486
        return None
 
487
    archive, series, project, user = m.group('archive', 'series',
 
488
                                             'project', 'user')
 
489
    if series is not None:
 
490
        # series is optional, so the regex includes the extra '/', we don't
 
491
        # want to send that on (it causes Internal Server Errors.)
 
492
        series = series.strip('/')
 
493
    if user is not None:
 
494
        user = user.strip('~/')
 
495
        if user != 'ubuntu-branches':
 
496
            return None
 
497
    return archive, series, project
 
498
 
 
499
 
 
500
def _check_is_up_to_date(the_branch):
 
501
    info = _get_package_branch_info(the_branch.base)
 
502
    if info is None:
 
503
        return
 
504
    c = the_branch.get_config()
 
505
    verbosity = c.get_user_option('launchpad.packaging_verbosity')
 
506
    if verbosity is not None:
 
507
        verbosity = verbosity.lower()
 
508
    if verbosity == 'off':
 
509
        trace.mutter('not checking %s because verbosity is turned off'
 
510
                     % (the_branch.base,))
 
511
        return
 
512
    archive, series, project = info
 
513
    from bzrlib.plugins.launchpad import lp_api_lite
 
514
    latest_pub = lp_api_lite.LatestPublication(archive, series, project)
 
515
    lp_api_lite.report_freshness(the_branch, verbosity, latest_pub)
 
516
 
 
517
 
 
518
def _register_hooks():
 
519
    _mod_branch.Branch.hooks.install_named_hook('open',
 
520
        _check_is_up_to_date, 'package-branch-up-to-date')
 
521
 
 
522
 
 
523
_register_hooks()
465
524
 
466
525
def load_tests(basic_tests, module, loader):
467
526
    testmod_names = [
468
527
        'test_account',
469
528
        'test_register',
470
529
        'test_lp_api',
 
530
        'test_lp_api_lite',
471
531
        'test_lp_directory',
472
532
        'test_lp_login',
473
533
        'test_lp_open',