~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: 2011-07-26 08:18:56 UTC
  • mto: (6015.9.3 2.4)
  • mto: This revision was merged to the branch mainline in revision 6047.
  • Revision ID: john@arbash-meinel.com-20110726081856-st9ntoxihwokkfe9
Merge the package-freshness check from bzr-2.5 to the 2.4 series. bug #609187

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
    ui,
51
47
    trace,
52
48
    )
53
49
""")
54
50
 
55
 
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
    )
56
58
from bzrlib.commands import (
57
59
    Command,
58
60
    register_command,
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
    m = _package_branch.search(url)
 
483
    if m is None:
 
484
        return
 
485
    archive, series, project, user = m.group('archive', 'series',
 
486
                                             'project', 'user')
 
487
    if series is not None:
 
488
        # series is optional, so the regex includes the extra '/', we don't
 
489
        # want to send that on (it causes Internal Server Errors.)
 
490
        series = series.strip('/')
 
491
    if user is not None:
 
492
        user = user.strip('~/')
 
493
        if user != 'ubuntu-branches':
 
494
            return None
 
495
    return archive, series, project
 
496
 
 
497
 
 
498
def _check_is_up_to_date(the_branch):
 
499
    info = _get_package_branch_info(the_branch.base)
 
500
    if info is None:
 
501
        return
 
502
    c = the_branch.get_config()
 
503
    verbosity = c.get_user_option('launchpad.packaging_verbosity')
 
504
    if verbosity is not None:
 
505
        verbosity = verbosity.lower()
 
506
    if verbosity == 'off':
 
507
        trace.mutter('not checking %s because verbosity is turned off'
 
508
                     % (the_branch.base,))
 
509
        return
 
510
    archive, series, project = info
 
511
    from bzrlib.plugins.launchpad import lp_api_lite
 
512
    latest_pub = lp_api_lite.LatestPublication(archive, series, project)
 
513
    lp_api_lite.report_freshness(the_branch, verbosity, latest_pub)
 
514
 
 
515
 
 
516
def _register_hooks():
 
517
    _mod_branch.Branch.hooks.install_named_hook('open',
 
518
        _check_is_up_to_date, 'package-branch-up-to-date')
 
519
 
 
520
 
 
521
_register_hooks()
465
522
 
466
523
def load_tests(basic_tests, module, loader):
467
524
    testmod_names = [
468
525
        'test_account',
469
526
        'test_register',
470
527
        'test_lp_api',
 
528
        'test_lp_api_lite',
471
529
        'test_lp_directory',
472
530
        'test_lp_login',
473
531
        'test_lp_open',