[Checkins] SVN: zc.zk/trunk/s Provided a command-line tool, ``zookeeper_export``, to export/print

Jim Fulton jim at zope.com
Mon Dec 12 21:35:11 UTC 2011


Log message for revision 123783:
  Provided a command-line tool, ``zookeeper_export``,  to export/print
  trees.
  

Changed:
  U   zc.zk/trunk/setup.py
  U   zc.zk/trunk/src/zc/zk/README.txt
  A   zc.zk/trunk/src/zc/zk/scripts.py
  U   zc.zk/trunk/src/zc/zk/tests.py

-=-
Modified: zc.zk/trunk/setup.py
===================================================================
--- zc.zk/trunk/setup.py	2011-12-12 20:59:46 UTC (rev 123782)
+++ zc.zk/trunk/setup.py	2011-12-12 21:35:10 UTC (rev 123783)
@@ -21,6 +21,8 @@
     )
 
 entry_points = """
+[console_scripts]
+zookeeper_export = zc.zk.scripts:export
 """
 
 from setuptools import setup

Modified: zc.zk/trunk/src/zc/zk/README.txt
===================================================================
--- zc.zk/trunk/src/zc/zk/README.txt	2011-12-12 20:59:46 UTC (rev 123782)
+++ zc.zk/trunk/src/zc/zk/README.txt	2011-12-12 21:35:10 UTC (rev 123783)
@@ -581,6 +581,73 @@
 logging API.  ZooKeeper log messages are forwarded to the Python
 ``'ZooKeeper'`` logger.
 
+zookeeper_export script
+=======================
+
+The `zc.zk` package provides a utility script for exporting a
+ZooKeeper tree::
+
+    $ zookeeper_export -e zookeeper.example.com:2181 /fooservice
+    /fooservice
+      secret = u'1234'
+      threads = 3
+      /providers
+        /192.168.0.42:8080
+          pid = 7981
+        /192.168.0.42:8081
+          pid = 7981
+        /192.168.0.42:8082
+          pid = 7981
+
+.. -> sh
+
+    >>> command, expected = sh.strip().split('\n', 1)
+    >>> _, command, args = command.split(None, 2)
+    >>> import pkg_resources
+    >>> export = pkg_resources.load_entry_point(
+    ...     'zc.zk', 'console_scripts', command)
+    >>> import sys, StringIO
+    >>> sys.stdout = f = StringIO.StringIO(); export(args.split())
+    >>> got = f.getvalue()
+    >>> import zc.zk.tests
+    >>> zc.zk.tests.checker.check_output(expected.strip(), got.strip(), 0)
+    True
+
+    >>> export(['zookeeper.example.com:2181', '/fooservice'])
+    /fooservice
+      secret = u'1234'
+      threads = 3
+      /providers
+
+    >>> export(['zookeeper.example.com:2181'])
+    /cms : z4m cms
+      threads = 4
+      /databases
+        main -> /databases/cms
+      /providers
+    /databases
+      /cms
+        a = 1
+    /fooservice
+      secret = u'1234'
+      threads = 3
+      /providers
+    /lb : ipvs
+      /pools
+        /cms
+          address = u'1.2.3.4:80'
+          providers -> /cms/providers
+
+    >>> export(['zookeeper.example.com:2181', '/fooservice', '-oo'])
+    >>> print open('o').read(),
+    /fooservice
+      secret = u'1234'
+      threads = 3
+      /providers
+
+The export script provides the same features as the ``export_tree``
+method. Use the ``--help`` option to see how to use it.
+
 Graph analysis
 ==============
 
@@ -811,6 +878,7 @@
 0.4.0 (2011-12-??)
 ------------------
 
+- Provided a command-line tool, ``zookeeper_export``,  to export/print trees.
 - Fixed a race that could cause ZooKeeper logging info to be output
   before ``zc.zk`` began redirecting it.
 

Added: zc.zk/trunk/src/zc/zk/scripts.py
===================================================================
--- zc.zk/trunk/src/zc/zk/scripts.py	                        (rev 0)
+++ zc.zk/trunk/src/zc/zk/scripts.py	2011-12-12 21:35:10 UTC (rev 123783)
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import logging
+import optparse
+import sys
+import zc.zk
+
+def export(args=None):
+    if args is None:
+        args = sys.argv[1:]
+
+    parser = optparse.OptionParser("""
+    Usage: %(prog)s [options] connection [path]
+    """)
+    parser.add_option('-e', '--ephemeral', action='store_true')
+    parser.add_option('-o', '--output')
+
+    options, args = parser.parse_args(args)
+    connection = args.pop(0)
+    if args:
+        [path] = args
+    else:
+        path = '/'
+
+    logging.basicConfig(level=logging.WARNING)
+
+    zk = zc.zk.ZooKeeper(connection)
+    data = zk.export_tree(path, ephemeral=options.ephemeral)
+
+    if options.output:
+        with open(options.output, 'w') as f:
+            f.write(data)
+    else:
+        print data,


Property changes on: zc.zk/trunk/src/zc/zk/scripts.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: zc.zk/trunk/src/zc/zk/tests.py
===================================================================
--- zc.zk/trunk/src/zc/zk/tests.py	2011-12-12 20:59:46 UTC (rev 123782)
+++ zc.zk/trunk/src/zc/zk/tests.py	2011-12-12 21:35:10 UTC (rev 123783)
@@ -1054,13 +1054,14 @@
     test.globs['check_async'] = check_async
     test.globs['event'] = event
 
+checker = zope.testing.renormalizing.RENormalizing([
+    (re.compile('pid = \d+'), 'pid = 9999'),
+    (re.compile("{'pid': \d+}"), 'pid = 9999'),
+    (re.compile('/zc\.zk\.testing\.test-root\d+'), ''),
+    (re.compile(r'2 None\n4 None'), '4 None\n2 None'),
+    ])
+
 def test_suite():
-    checker = zope.testing.renormalizing.RENormalizing([
-        (re.compile('pid = \d+'), 'pid = 9999'),
-        (re.compile("{'pid': \d+}"), 'pid = 9999'),
-        (re.compile('/zc\.zk\.testing\.test-root\d+'), ''),
-        (re.compile(r'2 None\n4 None'), '4 None\n2 None'),
-        ])
     suite = unittest.TestSuite((
         manuel.testing.TestSuite(
             manuel.doctest.Manuel(checker=checker) + manuel.capture.Manuel(),



More information about the checkins mailing list