Rev 12: Update the command line to dump out a python script when given --python. in http://people.canonical.com/~robertc/baz2.0/plugins/plugin_info/trunk

Robert Collins robertc at robertcollins.net
Mon Mar 1 01:33:14 GMT 2010


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

------------------------------------------------------------
revno: 12
revision-id: robertc at robertcollins.net-20100301013252-gx1fiqt8j59v36ju
parent: robertc at robertcollins.net-20100301011555-y7ky6a0bgi8ry1qi
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Mon 2010-03-01 12:32:52 +1100
message:
  Update the command line to dump out a python script when given --python.
=== modified file 'NEWS'
--- a/NEWS	2010-03-01 01:15:55 +0000
+++ b/NEWS	2010-03-01 01:32:52 +0000
@@ -14,7 +14,9 @@
   FEATURES:
 
     * New command ``bzr plugin_info`` which will dump plugin details for any
-      number of URL's. (Robert Collins)
+      number of URL's. When given ``--python`` this command dumps out a python
+      script that can recreate the metadata for all the plugins it scanned.
+      (Robert Collins)
 
   IMPROVEMENTS:
 

=== modified file 'commands.py'
--- a/commands.py	2008-02-29 19:00:41 +0000
+++ b/commands.py	2010-03-01 01:32:52 +0000
@@ -20,6 +20,7 @@
 from bzrlib.branch import Branch
 from bzrlib import errors
 import bzrlib.commands
+from bzrlib.option import Option
 from bzrlib.plugins.plugin_info.extract import *
 
 
@@ -31,16 +32,30 @@
     """
 
     takes_args = ['location+']
-
-    def run(self, location_list=[]):
+    takes_options = [
+        Option('python', help='output a python script with the plugin metadata.'),
+        ]
+
+
+    def dump_info(self, plugin_info):
+        if self.python:
+            self.outf.write(plugin_info.to_python())
+            self.outf.write('plugins.append(plugin)\n')
+        else:
+            self.outf.write(str(plugin_info))
+
+    def run(self, location_list=[], python=False):
+        self.python = python
+        if self.python:
+            self.outf.write('plugins = []\n')
         for url in location_list:
             try:
-                self.outf.write(str(extract_info_local(url)))
+                self.dump_info(extract_info_local(url))
             except IOError:
                 try:
                     branch = Branch.open(url)
                 except errors.NotBranchError:
                     raise
                 else:
-                    self.outf.write(str(extract_info_branch(branch)))
+                    self.dump_info(extract_info_branch(branch))
             self.outf.write('\n')

=== modified file 'extract.py'
--- a/extract.py	2010-03-01 01:15:55 +0000
+++ b/extract.py	2010-03-01 01:32:52 +0000
@@ -128,16 +128,16 @@
     def to_python(self):
         """Represent this PluginInfo as a python source fragment."""
         result = []
-        result.append('%s = PluginInfo()\n' % self.name)
-        result.append('%s.name = %s\n' % (self.name, self.name))
-        result.append('%s.location = %s\n' % (self.name, self.location))
-        result.append('%s.version_info = %s\n' % (self.name, self.version_info))
-        result.append('%s.minimum_bzr_version = %s\n' % (self.name, self.minimum_bzr_version))
-        result.append('%s.maximum_bzr_version = %s\n' % (self.name, self.maximum_bzr_version))
-        result.append('%s.commands = %s\n' % (self.name, self.commands))
-        result.append('%s.control_formats = %s\n' % (self.name, self.control_formats))
-        result.append('%s.checkout_formats = %s\n' % (self.name, self.checkout_formats))
-        result.append('%s.branch_formats = %s\n' % (self.name, self.branch_formats))
-        result.append('%s.repository_formats = %s\n' % (self.name, self.repository_formats))
-        result.append('%s.transports = %s\n' % (self.name, self.transports))
+        result.append('plugin = PluginInfo()\n')
+        result.append('plugin.name = %r\n' % (self.name,))
+        result.append('plugin.location = %s\n' % (self.location,))
+        result.append('plugin.version_info = %s\n' % (self.version_info,))
+        result.append('plugin.minimum_bzr_version = %s\n' % (self.minimum_bzr_version,))
+        result.append('plugin.maximum_bzr_version = %s\n' % (self.maximum_bzr_version,))
+        result.append('plugin.commands = %s\n' % (self.commands,))
+        result.append('plugin.control_formats = %s\n' % (self.control_formats,))
+        result.append('plugin.checkout_formats = %s\n' % (self.checkout_formats,))
+        result.append('plugin.branch_formats = %s\n' % (self.branch_formats,))
+        result.append('plugin.repository_formats = %s\n' % (self.repository_formats,))
+        result.append('plugin.transports = %s\n' % (self.transports,))
         return ''.join(result)

=== modified file 'tests/test_blackbox.py'
--- a/tests/test_blackbox.py	2009-08-05 04:45:21 +0000
+++ b/tests/test_blackbox.py	2010-03-01 01:32:52 +0000
@@ -1,5 +1,5 @@
 # plugin_info, a plugin for working with information about plugins.
-# Copyright (C) 2008 Canonical Limited.
+# Copyright (C) 2008, 2010 Canonical Limited.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2 as published
@@ -18,6 +18,7 @@
 """Tests for the commands supplied by plugin-info."""
 
 from bzrlib.tests import TestCaseWithTransport
+from testtools.matchers import DocTestMatches
 
 
 class TestPluginInfo(TestCaseWithTransport):
@@ -36,16 +37,55 @@
 bzr_transports = ["hg+ssh://"]
 """
 
-    def test_extract_info_branch(self):
+    def setup_plugins(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')
         self.build_tree(['plugin2/'])
         self.build_tree_contents([('plugin2/setup.py', self.sample_setup())])
+
+    def test_extract_info_branch(self):
+        self.setup_plugins()
         out, err = self.run_bzr(['plugin-info', 'plugin', 'plugin2'])
         self.assertEqual(
 """foo_bar(1.2.3dev0) from plugin supplies commands("a-command"), control formats("bzr-meta"), checkout formats("dirstate"), branch formats("branch 6"), repository formats("packs"), transports("hg+ssh://").
 foo_bar(1.2.3dev0) from plugin2 supplies commands("a-command"), control formats("bzr-meta"), checkout formats("dirstate"), branch formats("branch 6"), repository formats("packs"), transports("hg+ssh://").
 """, out)
         self.assertEqual('', err)
+
+    def test_extract_info_python(self):
+        self.setup_plugins()
+        out, err = self.run_bzr(['plugin-info', 'plugin', 'plugin2', '--python'])
+        self.assertThat(out, DocTestMatches("""plugins = []
+plugin = PluginInfo()
+plugin.name = 'foo_bar'
+plugin.location = plugin
+plugin.version_info = (1, 2, 3, 'dev', 0)
+plugin.minimum_bzr_version = (1, 2, 0)
+plugin.maximum_bzr_version = (1, 3, 0)
+plugin.commands = ['a-command']
+plugin.control_formats = {'bzr-meta': {'.bzr/branch-format': 'Bazaar-NG meta directory, format 1\\n'}}
+plugin.checkout_formats = {'Bazaar Working Tree Format 4 (bzr 0.15)\\n': 'dirstate'}
+plugin.branch_formats = {'Bazaar Branch Format 6 (bzr 0.15)\\n': 'branch 6'}
+plugin.repository_formats = {'Bazaar pack repository format 1 (needs bzr 0.92)\\n': 'packs'}
+plugin.transports = ['hg+ssh://']
+plugins.append(plugin)
+<BLANKLINE>
+plugin = PluginInfo()
+plugin.name = 'foo_bar'
+plugin.location = plugin2
+plugin.version_info = (1, 2, 3, 'dev', 0)
+plugin.minimum_bzr_version = (1, 2, 0)
+plugin.maximum_bzr_version = (1, 3, 0)
+plugin.commands = ['a-command']
+plugin.control_formats = {'bzr-meta': {'.bzr/branch-format': 'Bazaar-NG meta directory, format 1\\n'}}
+plugin.checkout_formats = {'Bazaar Working Tree Format 4 (bzr 0.15)\\n': 'dirstate'}
+plugin.branch_formats = {'Bazaar Branch Format 6 (bzr 0.15)\\n': 'branch 6'}
+plugin.repository_formats = {'Bazaar pack repository format 1 (needs bzr 0.92)\\n': 'packs'}
+plugin.transports = ['hg+ssh://']
+plugins.append(plugin)
+<BLANKLINE>
+"""))
+        self.assertEqual('', err)
+

=== modified file 'tests/test_extract.py'
--- a/tests/test_extract.py	2010-03-01 01:15:55 +0000
+++ b/tests/test_extract.py	2010-03-01 01:32:52 +0000
@@ -65,18 +65,18 @@
     def test_python(self):
         # A plugin info can be turned into a python source fragment.
         plugin = self.sample_plugin()
-        self.assertEqual("""plugin_info = PluginInfo()
-plugin_info.name = plugin_info
-plugin_info.location = http://bazaar-vcs.org/plugin-info/
-plugin_info.version_info = (1, 2, 0, 'dev', 0)
-plugin_info.minimum_bzr_version = (1, 0, 0)
-plugin_info.maximum_bzr_version = None
-plugin_info.commands = ['foo']
-plugin_info.control_formats = {'svn': {'ignored': None}}
-plugin_info.checkout_formats = {'signature': 'dirstate'}
-plugin_info.branch_formats = {'signature': 'format 6'}
-plugin_info.repository_formats = {'signature': 'packs'}
-plugin_info.transports = ['hg+ssh://']
+        self.assertEqual("""plugin = PluginInfo()
+plugin.name = 'plugin_info'
+plugin.location = http://bazaar-vcs.org/plugin-info/
+plugin.version_info = (1, 2, 0, 'dev', 0)
+plugin.minimum_bzr_version = (1, 0, 0)
+plugin.maximum_bzr_version = None
+plugin.commands = ['foo']
+plugin.control_formats = {'svn': {'ignored': None}}
+plugin.checkout_formats = {'signature': 'dirstate'}
+plugin.branch_formats = {'signature': 'format 6'}
+plugin.repository_formats = {'signature': 'packs'}
+plugin.transports = ['hg+ssh://']
 """, plugin.to_python())
 
     def test___eq__(self):




More information about the bazaar-commits mailing list