Rev 3258: Add support for directory services (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Mar 10 15:38:12 GMT 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3258
revision-id:pqm at pqm.ubuntu.com-20080310153803-uy09bhh0ls8tavcx
parent: pqm at pqm.ubuntu.com-20080308231040-by6td3eegfa0s21i
parent: aaron at aaronbentley.com-20080310140003-cn3mkrvauiaaqulm
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2008-03-10 15:38:03 +0000
message:
Add support for directory services (abentley)
added:
bzrlib/directory_service.py directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
bzrlib/tests/test_directory_service.py test_directory_servi-20080305221044-vr2mkvlsk8jypa2y-2
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/registry.py lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_registry.py test_lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-2
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
------------------------------------------------------------
revno: 3251.3.6
revision-id:aaron at aaronbentley.com-20080310140003-cn3mkrvauiaaqulm
parent: aaron at aaronbentley.com-20080307134907-57mziosf1h770wz6
parent: pqm at pqm.ubuntu.com-20080308231040-by6td3eegfa0s21i
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: bzr.ab.integration
timestamp: Mon 2008-03-10 10:00:03 -0400
message:
Merge bzr.dev
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/debug.py debug.py-20061102062349-vdhrw9qdpck8cl35-1
bzrlib/deprecated_graph.py graph.py-20050905070950-b47dce53236c5e48
bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
bzrlib/mail_client.py mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
bzrlib/merge_directive.py merge_directive.py-20070228184838-ja62280spt1g7f4x-1
bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
bzrlib/tests/test_tsort.py testtsort.py-20051025073946-27da871c394d5be4
bzrlib/tsort.py tsort.py-20051025073946-7808f6aaf7d07208
bzrlib/util/configobj/configobj.py configobj.py-20051018184548-06992a2246425e3e
bzrlib/util/configobj/docs/configobj.txt configobj.txt-20051018184548-4949b5f17e6a19c7
bzrlib/util/configobj/docs/validate.txt validate.txt-20051018184548-9e0e5ad913e258f5
doc/en/user-guide/resolving_conflicts.txt resolving_conflicts.-20071122141511-0knao2lklsdsvb1q-5
------------------------------------------------------------
revno: 3251.3.5
revision-id:aaron at aaronbentley.com-20080307134907-57mziosf1h770wz6
parent: aaron at aaronbentley.com-20080307124953-bz7ho9p4bb6u0wdx
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: directory-service
timestamp: Fri 2008-03-07 13:49:07 +0000
message:
Update docstring
modified:
bzrlib/directory_service.py directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
------------------------------------------------------------
revno: 3251.3.4
revision-id:aaron at aaronbentley.com-20080307124953-bz7ho9p4bb6u0wdx
parent: aaron at aaronbentley.com-20080307123048-66maa16ksw0n1o66
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: directory-service
timestamp: Fri 2008-03-07 12:49:53 +0000
message:
Update NEWS
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
------------------------------------------------------------
revno: 3251.3.3
revision-id:aaron at aaronbentley.com-20080307123048-66maa16ksw0n1o66
parent: aaron at aaronbentley.com-20080307114620-k8bznm3qigu2bzlh
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: directory-service
timestamp: Fri 2008-03-07 12:30:48 +0000
message:
Add docstring.
modified:
bzrlib/directory_service.py directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
------------------------------------------------------------
revno: 3251.3.2
revision-id:aaron at aaronbentley.com-20080307114620-k8bznm3qigu2bzlh
parent: aaron at aaronbentley.com-20080306141245-ukzpgujvk3zuajai
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: directory-service
timestamp: Fri 2008-03-07 11:46:20 +0000
message:
Add testing of Registry.get_prefix
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
revision-id:aaron at aaronbentley.com-20080306141245-ukzpgujvk3zuajai
parent: pqm at pqm.ubuntu.com-20080305131343-toq33x607hecihie
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: directory-service
timestamp: Thu 2008-03-06 14:12:45 +0000
message:
Add support for directory services
added:
bzrlib/directory_service.py directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
bzrlib/tests/test_directory_service.py test_directory_servi-20080305221044-vr2mkvlsk8jypa2y-2
modified:
bzrlib/registry.py lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
=== added file 'bzrlib/directory_service.py'
--- a/bzrlib/directory_service.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/directory_service.py 2008-03-07 13:49:07 +0000
@@ -0,0 +1,54 @@
+# Copyright (C) 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Directory service registration and usage.
+
+Directory services are utilities that provide a mapping from URL-like strings
+to true URLs. Examples include lp:urls and per-user location aliases.
+"""
+
+from bzrlib import registry
+
+class DirectoryServiceRegistry(registry.Registry):
+ """This object maintains and uses a list of directory services.
+
+ Directory services may be registered via the standard Registry methods.
+ They will be invoked if their key is a prefix of the supplied URL.
+
+ Each item registered should be a factory of objects that provide a look_up
+ method, as invoked by dereference. Specifically, look_up should accept a
+ name and URL, and return a URL.
+ """
+
+ def dereference(self, url):
+ """Dereference a supplied URL if possible.
+
+ URLs that match a registered directory service prefix are looked up in
+ it. Non-matching urls are returned verbatim.
+
+ This is applied only once; the resulting URL must not be one that
+ requires further dereferencing.
+
+ :param url: The URL to dereference
+ :return: The dereferenced URL if applicable, the input URL otherwise.
+ """
+ match = self.get_prefix(url)
+ if match is None:
+ return url
+ service, name = match
+ return service().look_up(name, url)
+
+directories = DirectoryServiceRegistry()
=== added file 'bzrlib/tests/test_directory_service.py'
--- a/bzrlib/tests/test_directory_service.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_directory_service.py 2008-03-06 14:12:45 +0000
@@ -0,0 +1,51 @@
+# Copyright (C) 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Test directory service implementation"""
+
+from bzrlib.directory_service import DirectoryServiceRegistry, directories
+from bzrlib.tests import TestCase
+from bzrlib.transport import get_transport
+
+
+class FooService(object):
+ """A directory service that maps the name to a FILE url"""
+
+ def look_up(self, name, url):
+ return 'file:///foo' + name
+
+
+class TestDirectoryLookup(TestCase):
+
+ def setUp(self):
+ TestCase.setUp(self)
+ self.registry = DirectoryServiceRegistry()
+ self.registry.register('foo:', FooService, 'Map foo URLs to http urls')
+
+ def test_get_directory_service(self):
+ directory, suffix = self.registry.get_prefix('foo:bar')
+ self.assertIs(FooService, directory)
+ self.assertEqual('bar', suffix)
+
+ def test_dereference(self):
+ self.assertEqual('file:///foobar',
+ self.registry.dereference('foo:bar'))
+ self.assertEqual('baz:qux', self.registry.dereference('baz:qux'))
+
+ def test_get_transport(self):
+ directories.register('foo:', FooService, 'Map foo URLs to http urls')
+ self.addCleanup(lambda: directories.remove('foo:'))
+ self.assertEqual('file:///foobar/', get_transport('foo:bar').base)
=== modified file 'NEWS'
--- a/NEWS 2008-03-08 21:33:25 +0000
+++ b/NEWS 2008-03-10 14:00:03 +0000
@@ -8,7 +8,7 @@
--------------
NOTES WHEN UPGRADING:
-
+
CHANGES:
* A new repository format 'development' has been added. This format will
@@ -28,7 +28,7 @@
bzr.exe, installed to ``C:\Program Files\Bazaar\plugins`` directory,
and standalone installer allows user to skip installation of this plugin.
(Alexander Belchenko)
-
+
* Restore auto-detection of plink.exe on Windows. (Dmitry Vasiliev)
FEATURES:
@@ -42,6 +42,10 @@
* Branch6.generate_revision_history is faster. (Aaron Bentley)
+ * Directory services can now be registered, allowing special URLs to be
+ dereferenced into real URLs. This is a generalization and cleanup of
+ the lp: transport lookup. (Aaron Bentley)
+
* Merge directives that are automatically attached to emails have nicer
filenames, based on branch-nick + revno. (Aaron Bentley)
=== modified file 'bzrlib/registry.py'
--- a/bzrlib/registry.py 2007-10-02 05:33:39 +0000
+++ b/bzrlib/registry.py 2008-03-07 11:46:20 +0000
@@ -167,6 +167,17 @@
"""
return self._dict[self._get_key_or_default(key)].get_obj()
+ def get_prefix(self, fullname):
+ """Return an object whose key is a prefix of the supplied value.
+
+ :fullname: The name to find a prefix for
+ :return: a tuple of (object, remainder), where the remainder is the
+ portion of the name that did not match the key.
+ """
+ for key, value in self.iteritems():
+ if fullname.startswith(key):
+ return value, fullname[len(key):]
+
def _get_key_or_default(self, key=None):
"""Return either 'key' or the default key if key is None"""
if key is not None:
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-02-25 07:28:29 +0000
+++ b/bzrlib/tests/__init__.py 2008-03-06 14:12:45 +0000
@@ -2651,6 +2651,7 @@
'bzrlib.tests.test_deprecated_graph',
'bzrlib.tests.test_diff',
'bzrlib.tests.test_dirstate',
+ 'bzrlib.tests.test_directory_service',
'bzrlib.tests.test_email_message',
'bzrlib.tests.test_errors',
'bzrlib.tests.test_escaped_store',
=== modified file 'bzrlib/tests/test_registry.py'
--- a/bzrlib/tests/test_registry.py 2006-10-16 01:50:48 +0000
+++ b/bzrlib/tests/test_registry.py 2008-03-07 11:46:20 +0000
@@ -187,6 +187,20 @@
], sorted((key, a_registry.get_info(key))
for key in a_registry.keys()))
+ def test_get_prefix(self):
+ my_registry = registry.Registry()
+ http_object = object()
+ sftp_object = object()
+ my_registry.register('http:', http_object)
+ my_registry.register('sftp:', sftp_object)
+ found_object, suffix = my_registry.get_prefix('http://foo/bar')
+ self.assertEqual('//foo/bar', suffix)
+ self.assertIs(http_object, found_object)
+ self.assertIsNot(sftp_object, found_object)
+ found_object, suffix = my_registry.get_prefix('sftp://baz/qux')
+ self.assertEqual('//baz/qux', suffix)
+ self.assertIs(sftp_object, found_object)
+
class TestRegistryWithDirs(TestCaseInTempDir):
"""Registry tests that require temporary dirs"""
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2008-01-04 01:21:44 +0000
+++ b/bzrlib/transport/__init__.py 2008-03-06 14:12:45 +0000
@@ -1572,6 +1572,8 @@
if base is None:
base = '.'
last_err = None
+ from bzrlib.directory_service import directories
+ base = directories.dereference(base)
def convert_path_to_url(base, error_str):
m = _urlRE.match(base)
More information about the bazaar-commits
mailing list