Rev 10: New method ``extract.extract_info_url`` as the primary workhorse for in http://people.canonical.com/~robertc/baz2.0/plugins/plugin_info/trunk
Robert Collins
robertc at robertcollins.net
Mon Mar 1 00:58:02 GMT 2010
At http://people.canonical.com/~robertc/baz2.0/plugins/plugin_info/trunk
------------------------------------------------------------
revno: 10
revision-id: robertc at robertcollins.net-20100301005750-wjhzzkrv9dg0i0jn
parent: robertc at robertcollins.net-20100301005056-q0togr1jtskat3ck
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Mon 2010-03-01 11:57:50 +1100
message:
New method ``extract.extract_info_url`` as the primary workhorse for
examining plugins. (Robert Collins)
=== modified file 'NEWS'
--- a/NEWS 2009-08-05 04:45:21 +0000
+++ b/NEWS 2010-03-01 00:57:50 +0000
@@ -33,3 +33,6 @@
* New method ``extract.extract_info_local`` to extract data from an
unpacked plugin on disk.
+
+ * New method ``extract.extract_info_url`` as the primary workhorse for
+ examining plugins. (Robert Collins)
=== modified file '__init__.py'
--- a/__init__.py 2008-02-29 19:00:41 +0000
+++ b/__init__.py 2010-03-01 00:57:50 +0000
@@ -20,7 +20,7 @@
The command ``plugin-info`` provides information about plugins when given one
or more local paths or URL's to plugin branches.
-:seealso: bzrlib.plugins.plugin_info.extract
+:seealso: bzrlib.plugins.plugin_info.extract for metadata extraction routines.
"""
import bzrlib.commands
=== modified file 'extract.py'
--- a/extract.py 2009-08-05 04:45:21 +0000
+++ b/extract.py 2010-03-01 00:57:50 +0000
@@ -15,11 +15,20 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-"""Extraction of plugin data from a plugin."""
-
-__all__ = ['extract_info_branch', 'extract_info_local', 'PluginInfo']
-
-from bzrlib import osutils
+"""Extraction of plugin data from a plugin.
+
+The primary entry point to this module is extract_info_url which will attempt
+to do the right thing when given a url (including directory service lookups).
+"""
+
+__all__ = [
+ 'extract_info_branch',
+ 'extract_info_local',
+ 'extract_info_url',
+ 'PluginInfo',
+ ]
+
+from bzrlib import branch, directory_service, osutils
def extract_info_branch(branch):
@@ -68,6 +77,20 @@
return result
+def extract_info_url(url):
+ """Extract info from a plugin at url.
+
+ :param url: A URL to probe. Directory service lookups will be done on it.
+ :return: A PluginInfo for the plugin at url.
+ """
+ # TODO: for local branches use extract_info_local ?:- what if they are
+ # treeless branches?
+ b = branch.Branch.open(url)
+ result = extract_info_branch(b)
+ result.location = url
+ return result
+
+
class PluginInfo(object):
"""Information about a plugin."""
=== modified file 'tests/test_extract.py'
--- a/tests/test_extract.py 2009-08-05 04:45:21 +0000
+++ b/tests/test_extract.py 2010-03-01 00:57:50 +0000
@@ -19,6 +19,7 @@
from copy import copy
+from bzrlib import directory_service
from bzrlib.plugins.plugin_info.extract import *
from bzrlib.tests import TestCaseWithTransport
@@ -135,6 +136,13 @@
bzr_transports = ["hg+ssh://"]
"""
+ def setup_plugin(self):
+ tree = self.make_branch_and_tree('plugin')
+ self.build_tree_contents([('plugin/setup.py', self.sample_setup())])
+ tree.add(['setup.py'])
+ tree.commit('yay history')
+ return tree
+
def expected_plugin(self):
expected_plugin = PluginInfo()
expected_plugin.name = "foo_bar"
@@ -163,10 +171,23 @@
self.assertEqual(expected_plugin, plugin)
def test_extract_info_branch(self):
- tree = self.make_branch_and_tree('plugin')
- self.build_tree_contents([('plugin/setup.py', self.sample_setup())])
- tree.add(['setup.py'])
- tree.commit('yay history')
+ tree = self.setup_plugin()
expected_plugin = self.expected_plugin()
expected_plugin.location = tree.branch.base
self.assertEqual(expected_plugin, extract_info_branch(tree.branch))
+
+ def test_extract_info_url_handles_directory_lookup(self):
+ self.setup_plugin()
+ class LocalDirectory:
+ def look_up(self, name, url):
+ return 'plugin'
+ directory_service.directories.register('pl:', LocalDirectory, '')
+ def unregister():
+ d = directory_service.directories
+ d.remove('pl:')
+ del d._help_dict['pl:']
+ del d._info_dict['pl:']
+ self.addCleanup(unregister)
+ expected_plugin = self.expected_plugin()
+ expected_plugin.location = 'pl:'
+ self.assertEqual(expected_plugin, extract_info_url('pl:'))
More information about the bazaar-commits
mailing list