41
41
# see http://wiki.bazaar.canonical.com/Specs/BranchRegistrationTool
43
# Since we are a built-in plugin we share the bzrlib version
44
from bzrlib import version_info
46
43
from bzrlib.lazy_import import lazy_import
47
44
lazy_import(globals(), """
48
45
from bzrlib import (
49
branch as _mod_branch,
56
from bzrlib import bzrdir
52
branch as _mod_branch,
55
# Since we are a built-in plugin we share the bzrlib version
57
58
from bzrlib.commands import (
61
62
from bzrlib.directory_service import directories
62
63
from bzrlib.errors import (
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()
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)
463
465
_register_directory()
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
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>/[^/]+)?'
476
def _get_package_branch_info(url):
477
"""Determine the packaging information for this URL.
479
:return: If this isn't a packaging branch, return None. If it is, return
480
(archive, series, project)
484
m = _package_branch.search(url)
487
archive, series, project, user = m.group('archive', 'series',
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('/')
494
user = user.strip('~/')
495
if user != 'ubuntu-branches':
497
return archive, series, project
500
def _check_is_up_to_date(the_branch):
501
info = _get_package_branch_info(the_branch.base)
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,))
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)
518
def _register_hooks():
519
_mod_branch.Branch.hooks.install_named_hook('open',
520
_check_is_up_to_date, 'package-branch-up-to-date')
466
525
def load_tests(basic_tests, module, loader):
467
526
testmod_names = [
471
531
'test_lp_directory',