~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-08-20 09:28:27 UTC
  • mfrom: (5050.78.2 2.2)
  • mto: (5609.48.8 2.3)
  • mto: This revision was merged to the branch mainline in revision 6090.
  • Revision ID: v.ladeuil+lp@free.fr-20110820092827-9dyakfslp0r3hb1k
Merge 2.2 into 2.3 (including fix for #614713, #609187 and #812928)

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
46
    errors,
51
47
    ui,
52
48
    trace,
58
54
        Command,
59
55
        register_command,
60
56
)
 
57
from bzrlib import (
 
58
    branch as _mod_branch,
 
59
    lazy_regex,
 
60
    # Since we are a built-in plugin we share the bzrlib version
 
61
    version_info,
 
62
    )
61
63
from bzrlib.directory_service import directories
62
64
from bzrlib.errors import (
63
65
    BzrCommandError,
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',