Rev 4: Add extract_info_branch to gather information from a branch. in http://people.ubuntu.com/~robertc/baz2.0/plugins/plugin_info/trunk

Robert Collins robertc at robertcollins.net
Fri Feb 29 16:25:58 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/plugins/plugin_info/trunk

------------------------------------------------------------
revno: 4
revision-id:robertc at robertcollins.net-20080229162558-1e0du5ryizp1jblc
parent: robertc at robertcollins.net-20080229160713-lne6c7462w7m3how
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Sat 2008-03-01 03:25:58 +1100
message:
  Add extract_info_branch to gather information from a branch.
modified:
  extract.py                     extract.py-20080229115650-cgv523um54o9zvew-1
  tests/test_extract.py          test_extract.py-20080229115650-cgv523um54o9zvew-2
=== modified file 'extract.py'
--- a/extract.py	2008-02-29 16:07:13 +0000
+++ b/extract.py	2008-02-29 16:25:58 +0000
@@ -17,7 +17,25 @@
 
 """Extraction of plugin data from a plugin."""
 
-__all__ = ['extract_info_local', 'PluginInfo']
+__all__ = ['extract_info_branch', 'extract_info_local', 'PluginInfo']
+
+from bzrlib import osutils
+
+
+def extract_info_branch(branch):
+    """Extract plugin info from a branch containing a plugin.
+
+    :param branch: The branch containing the plugin.
+    :return: A PluginInfo for the plugin.
+    """
+    tempdir = osutils.mkdtemp()
+    treedir = tempdir + '/plugin'
+    try:
+        branch.create_checkout(treedir, lightweight=True)
+        return extract_info_local(treedir)
+    finally:
+        osutils.rmtree(tempdir, ignore_errors=True)
+
 
 
 def extract_info_local(path):

=== modified file 'tests/test_extract.py'
--- a/tests/test_extract.py	2008-02-29 16:07:13 +0000
+++ b/tests/test_extract.py	2008-02-29 16:25:58 +0000
@@ -97,10 +97,8 @@
         plugin = extract_info_local('foo-bar')
         self.assertEqual(PluginInfo(), plugin)
 
-    def test_extract_all_variables(self):
-        self.build_tree(['foo-bar/'])
-        self.build_tree_contents([('foo-bar/setup.py',
-"""
+    def sample_setup(self):
+        return """
 bzr_plugin_name = "foo_bar"
 bzr_commands = ["a-command"]
 bzr_plugin_version = (1, 2, 3, 'dev', 0)
@@ -110,8 +108,9 @@
 bzr_checkout_formats = {"Bazaar Working Tree Format 4 (bzr 0.15)\\n":"dirstate"}
 bzr_branch_formats = {"Bazaar Branch Format 6 (bzr 0.15)\\n":"branch 6"}
 bzr_repository_formats = {"Bazaar pack repository format 1 (needs bzr 0.92)\\n":"packs"}
-""")])
-        plugin = extract_info_local('foo-bar')
+"""
+
+    def expected_plugin(self):
         expected_plugin = PluginInfo()
         expected_plugin.name = "foo_bar"
         expected_plugin.commands = ["a-command"]
@@ -127,5 +126,19 @@
             "Bazaar Branch Format 6 (bzr 0.15)\n":"branch 6"}
         expected_plugin.repository_formats = {
             "Bazaar pack repository format 1 (needs bzr 0.92)\n":"packs"}
+        return expected_plugin
+
+    def test_extract_all_variables(self):
+        self.build_tree(['foo-bar/'])
+        self.build_tree_contents([('foo-bar/setup.py', self.sample_setup())])
+        plugin = extract_info_local('foo-bar')
+        expected_plugin = self.expected_plugin()
         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')
+        expected_plugin = self.expected_plugin()
+        self.assertEqual(expected_plugin, extract_info_branch(tree.branch))



More information about the bazaar-commits mailing list