Rev 3266: Convert lp transport into a directory service (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Mar 12 04:19:32 GMT 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3266
revision-id:pqm at pqm.ubuntu.com-20080312041921-iqibnzp8pcqx18mk
parent: pqm at pqm.ubuntu.com-20080312024638-d1zdt09upkzq52is
parent: aaron at aaronbentley.com-20080307135143-v84thnmby9tllh70
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-03-12 04:19:21 +0000
message:
Convert lp transport into a directory service (abentley)
renamed:
bzrlib/plugins/launchpad/lp_indirect.py => bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
bzrlib/plugins/launchpad/test_lp_indirect.py => bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
------------------------------------------------------------
revno: 3251.3.1.1.8
revision-id:aaron at aaronbentley.com-20080307135143-v84thnmby9tllh70
parent: aaron at aaronbentley.com-20080307125409-8gvwri13317283c6
parent: aaron at aaronbentley.com-20080307134907-57mziosf1h770wz6
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Fri 2008-03-07 13:51:43 +0000
message:
Merge with directory-service
modified:
bzrlib/directory_service.py directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
------------------------------------------------------------
revno: 3251.3.1.1.7
revision-id:aaron at aaronbentley.com-20080307125409-8gvwri13317283c6
parent: aaron at aaronbentley.com-20080307125031-mpizami4w0lyqopn
author: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Fri 2008-03-07 12:54:09 +0000
message:
Remove Python 2.5-isms
modified:
bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
------------------------------------------------------------
revno: 3251.3.1.1.6
revision-id:aaron at aaronbentley.com-20080307125031-mpizami4w0lyqopn
parent: aaron at aaronbentley.com-20080307120431-ql858nw9cn4qjr0b
parent: aaron at aaronbentley.com-20080307124953-bz7ho9p4bb6u0wdx
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Fri 2008-03-07 12:50:31 +0000
message:
Merge with directory-service
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/directory_service.py directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
------------------------------------------------------------
revno: 3251.3.1.1.5
revision-id:aaron at aaronbentley.com-20080307120431-ql858nw9cn4qjr0b
parent: aaron at aaronbentley.com-20080307115103-52qb39idrn4c0wwh
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Fri 2008-03-07 12:04:31 +0000
message:
Add docstring
modified:
bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
------------------------------------------------------------
revno: 3251.3.1.1.4
revision-id:aaron at aaronbentley.com-20080307115103-52qb39idrn4c0wwh
parent: aaron at aaronbentley.com-20080306211638-e7vl1tvjkw1w961l
parent: aaron at aaronbentley.com-20080307114620-k8bznm3qigu2bzlh
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Fri 2008-03-07 11:51:03 +0000
message:
Merge with directory-service
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/registry.py lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-1
bzrlib/tests/test_registry.py test_lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-2
------------------------------------------------------------
revno: 3251.3.1.1.3
revision-id:aaron at aaronbentley.com-20080306211638-e7vl1tvjkw1w961l
parent: aaron at aaronbentley.com-20080306205240-k0wt7gn9xzhwmo56
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Thu 2008-03-06 21:16:38 +0000
message:
More renames and cleanups
renamed:
bzrlib/plugins/launchpad/lp_indirect.py => bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
bzrlib/plugins/launchpad/test_lp_indirect.py => bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
------------------------------------------------------------
revno: 3251.3.1.1.2
revision-id:aaron at aaronbentley.com-20080306205240-k0wt7gn9xzhwmo56
parent: aaron at aaronbentley.com-20080306184017-ulwtkf5hxgrc569d
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Thu 2008-03-06 20:52:40 +0000
message:
Clean up Launchpad directory service code
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/lp_indirect.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
bzrlib/plugins/launchpad/test_lp_indirect.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
------------------------------------------------------------
revno: 3251.3.1.1.1
revision-id:aaron at aaronbentley.com-20080306184017-ulwtkf5hxgrc569d
parent: aaron at aaronbentley.com-20080306141245-ukzpgujvk3zuajai
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: lp-service
timestamp: Thu 2008-03-06 18:40:17 +0000
message:
Convert LP transport into directory service
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/lp_indirect.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
bzrlib/plugins/launchpad/test_lp_indirect.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
=== renamed file 'bzrlib/plugins/launchpad/lp_indirect.py' => 'bzrlib/plugins/launchpad/lp_directory.py'
--- a/bzrlib/plugins/launchpad/lp_indirect.py 2008-01-22 08:40:50 +0000
+++ b/bzrlib/plugins/launchpad/lp_directory.py 2008-03-07 12:54:09 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Canonical Ltd
+# Copyright (C) 2007, 2008 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -15,12 +15,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Transport indirection that uses Launchpad as a directory lookup.
-
-When the transport is opened, it immediately redirects to a url
-on Launchpad, which can then either serve the branch itself or redirect
-again.
-"""
+"""Directory lookup that uses Launchpad."""
from urlparse import urlsplit, urlunsplit
import xmlrpclib
@@ -34,7 +29,6 @@
from bzrlib.transport import (
get_transport,
register_urlparse_netloc_protocol,
- Transport,
)
from bzrlib.plugins.launchpad.lp_registration import (
@@ -48,21 +42,7 @@
register_urlparse_netloc_protocol('lp')
-class LaunchpadTransport(Transport):
- """lp:/// URL transport
-
- This transport redirects requests to the real branch location
- after resolving the URL via an XMLRPC request to Launchpad.
- """
-
- def __init__(self, base):
- super(LaunchpadTransport, self).__init__(base)
- # We only support URLs without a netloc
- self.lp_instance = urlsplit(base)[1]
- if self.lp_instance == '':
- self.lp_instance = None
- elif self.lp_instance not in LaunchpadService.LAUNCHPAD_INSTANCE:
- raise errors.InvalidURL(path=base)
+class LaunchpadDirectory(object):
def _requires_launchpad_login(self, scheme, netloc, path, query,
fragment):
@@ -75,19 +55,28 @@
and (netloc.endswith('launchpad.net')
or netloc.endswith('launchpad.dev')))
- def _resolve(self, abspath,
+ def look_up(self, name, url):
+ """See DirectoryService.look_up"""
+ return self._resolve(url)
+
+ def _resolve(self, url,
_request_factory=ResolveLaunchpadPathRequest,
_lp_login=None):
"""Resolve the base URL for this transport."""
- path = urlsplit(abspath)[2].lstrip('/')
+ result = urlsplit(url)
# Perform an XMLRPC request to resolve the path
- resolve = _request_factory(path)
- service = LaunchpadService(lp_instance=self.lp_instance)
+ lp_instance = result[1]
+ if lp_instance == '':
+ lp_instance = None
+ elif lp_instance not in LaunchpadService.LAUNCHPAD_INSTANCE:
+ raise errors.InvalidURL(path=url)
+ resolve = _request_factory(result[2].strip('/'))
+ service = LaunchpadService(lp_instance=lp_instance)
try:
result = resolve.submit(service)
except xmlrpclib.Fault, fault:
raise errors.InvalidURL(
- path=abspath, extra=fault.faultString)
+ path=url, extra=fault.faultString)
if 'launchpad' in debug.debug_flags:
trace.mutter("resolve_lp_path(%r) == %r", path, result)
@@ -114,34 +103,9 @@
else:
break
else:
- raise errors.InvalidURL(path=abspath,
- extra='no supported schemes')
+ raise errors.InvalidURL(path=url, extra='no supported schemes')
return url
- def _request_redirect(self, relpath):
- source = urlutils.join(self.base, relpath)
- # Split the source location into the branch location, and the
- # extra path components.
- pos = source.find('/.bzr/')
- if pos >= 0:
- branchpath = source[:pos]
- extra = source[pos:]
- else:
- branchpath = source
- extra = ''
- target = self._resolve(branchpath) + extra
- raise errors.RedirectRequested(
- source=source,
- target=target)
-
- def get(self, relpath):
- """See Transport.get()."""
- self._request_redirect(relpath)
-
- def mkdir(self, relpath, mode=None):
- """See Transport.mkdir()."""
- self._request_redirect(relpath)
-
def get_test_permutations():
# Since this transport doesn't do anything once opened, it's not subjected
=== renamed file 'bzrlib/plugins/launchpad/test_lp_indirect.py' => 'bzrlib/plugins/launchpad/test_lp_directory.py'
--- a/bzrlib/plugins/launchpad/test_lp_indirect.py 2008-02-15 04:40:19 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_directory.py 2008-03-06 21:16:38 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Canonical Ltd
+# Copyright (C) 2007, 2008 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Tests for indirect branch urls through Launchpad.net"""
+"""Tests for directory lookup through Launchpad.net"""
import xmlrpclib
@@ -22,10 +22,12 @@
errors,
)
from bzrlib.branch import Branch
+from bzrlib.directory_service import directories
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
from bzrlib.transport import get_transport
-from bzrlib.plugins.launchpad.lp_indirect import (
- LaunchpadTransport)
+from bzrlib.plugins.launchpad import _register_directory
+from bzrlib.plugins.launchpad.lp_directory import (
+ LaunchpadDirectory)
from bzrlib.plugins.launchpad.account import get_lp_login
@@ -44,17 +46,17 @@
return self._result
-class IndirectUrlTests(TestCase):
- """Tests for indirect branch urls through Launchpad.net"""
+class DirectoryUrlTests(TestCase):
+ """Tests for branch urls through Launchpad.net directory"""
def test_short_form(self):
"""A launchpad url should map to a http url"""
factory = FakeResolveFactory(
self, 'apt', dict(urls=[
'http://bazaar.launchpad.net/~apt/apt/devel']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
- transport._resolve('lp:apt', factory))
+ directory._resolve('lp:apt', factory))
# Make sure that resolve went to the production server.
self.assertEquals('https://xmlrpc.edge.launchpad.net/bazaar/',
factory._service_url)
@@ -65,51 +67,51 @@
self, 'apt', dict(urls=[
'http://bazaar.staging.launchpad.net/~apt/apt/devel']))
url = 'lp://staging/apt'
- transport = LaunchpadTransport(url)
+ directory = LaunchpadDirectory()
self.assertEquals('http://bazaar.staging.launchpad.net/~apt/apt/devel',
- transport._resolve(url, factory))
+ directory._resolve(url, factory))
# Make sure that resolve went to the staging server.
self.assertEquals('https://xmlrpc.staging.launchpad.net/bazaar/',
factory._service_url)
- def test_indirect_through_url(self):
+ def test_url_from_directory(self):
"""A launchpad url should map to a http url"""
factory = FakeResolveFactory(
self, 'apt', dict(urls=[
'http://bazaar.launchpad.net/~apt/apt/devel']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
- transport._resolve('lp:///apt', factory))
+ directory._resolve('lp:///apt', factory))
- def test_indirect_skip_bad_schemes(self):
+ def test_directory_skip_bad_schemes(self):
factory = FakeResolveFactory(
self, 'apt', dict(urls=[
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel',
'http://bazaar.launchpad.net/~apt/apt/devel',
'http://another/location']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
- transport._resolve('lp:///apt', factory))
+ directory._resolve('lp:///apt', factory))
- def test_indirect_no_matching_schemes(self):
+ def test_directory_no_matching_schemes(self):
# If the XMLRPC call does not return any protocols we support,
# invalidURL is raised.
factory = FakeResolveFactory(
self, 'apt', dict(urls=[
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertRaises(errors.InvalidURL,
- transport._resolve, 'lp:///apt', factory)
+ directory._resolve, 'lp:///apt', factory)
- def test_indirect_fault(self):
+ def test_directory_fault(self):
# Test that XMLRPC faults get converted to InvalidURL errors.
factory = FakeResolveFactory(self, 'apt', None)
def submit(service):
raise xmlrpclib.Fault(42, 'something went wrong')
factory.submit = submit
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertRaises(errors.InvalidURL,
- transport._resolve, 'lp:///apt', factory)
+ directory._resolve, 'lp:///apt', factory)
def test_skip_bzr_ssh_launchpad_net_when_anonymous(self):
# Test that bzr+ssh://bazaar.launchpad.net gets skipped if
@@ -119,9 +121,9 @@
self, 'apt', dict(urls=[
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
'http://bazaar.launchpad.net/~apt/apt/devel']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
- transport._resolve('lp:///apt', factory))
+ directory._resolve('lp:///apt', factory))
def test_skip_sftp_launchpad_net_when_anonymous(self):
# Test that sftp://bazaar.launchpad.net gets skipped if
@@ -131,9 +133,9 @@
self, 'apt', dict(urls=[
'sftp://bazaar.launchpad.net/~apt/apt/devel',
'http://bazaar.launchpad.net/~apt/apt/devel']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
- transport._resolve('lp:///apt', factory))
+ directory._resolve('lp:///apt', factory))
def test_rewrite_bzr_ssh_launchpad_net(self):
# Test that bzr+ssh URLs get rewritten to include the user's
@@ -142,10 +144,10 @@
self, 'apt', dict(urls=[
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
'http://bazaar.launchpad.net/~apt/apt/devel']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertEquals(
'bzr+ssh://username@bazaar.launchpad.net/~apt/apt/devel',
- transport._resolve('lp:///apt', factory, _lp_login='username'))
+ directory._resolve('lp:///apt', factory, _lp_login='username'))
def test_no_rewrite_of_other_bzr_ssh(self):
# Test that we don't rewrite bzr+ssh URLs for other
@@ -154,50 +156,34 @@
self, 'apt', dict(urls=[
'bzr+ssh://example.com/~apt/apt/devel',
'http://bazaar.launchpad.net/~apt/apt/devel']))
- transport = LaunchpadTransport('lp:///')
+ directory = LaunchpadDirectory()
self.assertEquals('bzr+ssh://example.com/~apt/apt/devel',
- transport._resolve('lp:///apt', factory))
+ directory._resolve('lp:///apt', factory))
# TODO: check we get an error if the url is unreasonable
- def test_error_for_bad_indirection(self):
+ def test_error_for_bad_url(self):
+ directory = LaunchpadDirectory()
self.assertRaises(errors.InvalidURL,
- LaunchpadTransport, 'lp://ratotehunoahu')
-
- def catch_redirect(self, methodname, *args):
- transport = LaunchpadTransport('lp:///apt')
- def _resolve(abspath):
- self.assertEqual('lp:///apt', abspath)
- return 'http://example.com/~apt/apt/devel'
- transport._resolve = _resolve
- try:
- getattr(transport, methodname)(*args)
- except errors.RedirectRequested, exc:
- return exc
- else:
- raise self.failException('RedirectRequested not raised')
-
- def test_redirect_on_get(self):
- exc = self.catch_redirect('get', '.bzr/branch-format')
- self.assertEqual('lp:///apt/.bzr/branch-format', exc.source)
- self.assertEqual(
- 'http://example.com/~apt/apt/devel/.bzr/branch-format', exc.target)
-
- def test_redirect_on_mkdir(self):
- exc = self.catch_redirect('mkdir', '.')
- self.assertEqual('lp:///apt', exc.source)
- self.assertEqual(
- 'http://example.com/~apt/apt/devel', exc.target)
-
-
-class IndirectOpenBranchTests(TestCaseWithMemoryTransport):
-
- def test_indirect_open_branch(self):
+ directory._resolve, 'lp://ratotehunoahu')
+
+
+class DirectoryOpenBranchTests(TestCaseWithMemoryTransport):
+
+ def test_directory_open_branch(self):
# Test that opening an lp: branch redirects to the real location.
target_branch = self.make_branch('target')
+ class FooService(object):
+ """A directory service that maps the name to a FILE url"""
+
+ def look_up(self, name, url):
+ if 'lp:///apt' == url:
+ return target_branch.base.rstrip('/')
+ return '!unexpected look_up value!'
+
+ directories.remove('lp:')
+ directories.register('lp:', FooService, 'Map lp URLs to local urls')
+ self.addCleanup(_register_directory)
+ self.addCleanup(lambda: directories.remove('lp:'))
transport = get_transport('lp:///apt')
- def _resolve(abspath):
- self.assertEqual('lp:///apt', abspath)
- return target_branch.base.rstrip('/')
- transport._resolve = _resolve
branch = Branch.open_from_transport(transport)
self.assertEqual(target_branch.base, branch.base)
=== modified file 'bzrlib/plugins/launchpad/__init__.py'
--- a/bzrlib/plugins/launchpad/__init__.py 2008-02-13 06:43:53 +0000
+++ b/bzrlib/plugins/launchpad/__init__.py 2008-03-06 21:16:38 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, 2007 Canonical Ltd
+# Copyright (C) 2006 - 2008 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -23,8 +23,8 @@
from bzrlib.branch import Branch
from bzrlib.commands import Command, Option, register_command
+from bzrlib.directory_service import directories
from bzrlib.errors import BzrCommandError, NoPublicBranch, NotBranchError
-from bzrlib.transport import register_lazy_transport
from bzrlib.help_topics import topic_registry
@@ -171,17 +171,18 @@
register_command(cmd_launchpad_login)
-register_lazy_transport(
- 'lp:',
- 'bzrlib.plugins.launchpad.lp_indirect',
- 'LaunchpadTransport')
+def _register_directory():
+ directories.register_lazy('lp:', 'bzrlib.plugins.launchpad.lp_directory',
+ 'LaunchpadDirectory',
+ 'Launchpad-based directory service',)
+_register_directory()
def test_suite():
"""Called by bzrlib to fetch tests for this plugin"""
from unittest import TestSuite, TestLoader
from bzrlib.plugins.launchpad import (
- test_account, test_lp_indirect, test_lp_service, test_register,
+ test_account, test_lp_directory, test_lp_service, test_register,
)
loader = TestLoader()
@@ -189,7 +190,7 @@
for module in [
test_account,
test_register,
- test_lp_indirect,
+ test_lp_directory,
test_lp_service,
]:
suite.addTests(loader.loadTestsFromModule(module))
More information about the bazaar-commits
mailing list