[Checkins] SVN: zc.zk/trunk/src/zc/zk/ A new script, zookeeper_set_property provides a simple way to update

jim cvs-admin at zope.org
Fri Dec 14 20:44:39 UTC 2012


Log message for revision 128659:
  A new script, zookeeper_set_property provides a simple way to update
  individual properties on a node.
  

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

-=-
Modified: zc.zk/trunk/src/zc/zk/README.txt
===================================================================
--- zc.zk/trunk/src/zc/zk/README.txt	2012-12-14 18:10:18 UTC (rev 128658)
+++ zc.zk/trunk/src/zc/zk/README.txt	2012-12-14 20:44:37 UTC (rev 128659)
@@ -855,6 +855,51 @@
 specifing access control lists. Use the ``--help`` option to see how
 to use it.
 
+Propery-update script
+=====================
+
+The `zc.zk` package provides a utility script for updating individual
+properties::
+
+  zookeeper_set_property zookeeper.example.com:2181 /fooservice \
+      threads=4 debug=True comment='ok'
+
+.. -> example
+
+    >>> example = example.replace('\\', '')
+    >>> args = example.strip().split()
+    >>> set_property = pkg_resources.load_entry_point(
+    ...     'zc.zk', 'console_scripts', args.pop(0))
+    >>> set_property(args)
+    data updated
+    comment: u'ok'
+    debug: True
+    secret: u'1234'
+    threads: 4
+    >>> zk.print_tree('/fooservice')
+    /fooservice
+      comment = u'ok'
+      debug = True
+      secret = u'1234'
+      threads = 4
+      /providers
+        /192.168.0.42:8080
+          pid = 6894
+        /192.168.0.42:8081
+          pid = 6894
+        /192.168.0.42:8082
+          pid = 6894
+      /provision
+        /node1
+        /node2
+
+
+The first argument to the script is the path of the node to be
+updated. Any number of additional arguments of the form:
+``NAME=PYTHONEXPRESSION`` are provided to supply updates.  If setting
+strings, you may have to quote the argument, as in "comment='a
+comment'".
+
 Iterating over a tree
 =====================
 
@@ -1213,12 +1258,15 @@
 Change History
 ==============
 
-1.1.1 (2012-??-??)
+1.2.0 (2012-12-14)
 ------------------
 
-Fixed: nonsensical error messages when trying to import properties at
-       the top-level of an import file.
+- A new script, zookeeper_set_property provides a simple way to update
+  individual properties on a node.
 
+- Fixed: nonsensical error messages when trying to import properties at
+         the top-level of an import file.
+
 1.1.0 (2012-11-07)
 ------------------
 

Modified: zc.zk/trunk/src/zc/zk/scripts.py
===================================================================
--- zc.zk/trunk/src/zc/zk/scripts.py	2012-12-14 18:10:18 UTC (rev 128658)
+++ zc.zk/trunk/src/zc/zk/scripts.py	2012-12-14 20:44:37 UTC (rev 128659)
@@ -125,3 +125,19 @@
         import_file = open(import_file)
 
     zc.zk.parse_tree(import_file.read())
+
+def set_property(args=None):
+    if args is None:
+        args = sys.argv[1:]
+
+    connection = args.pop(0)
+    path = args.pop(0)
+    zk = zc.zk.ZooKeeper(connection)
+
+    def _property(arg):
+        name, expr = arg.split('=', 1)
+        return name, eval(expr, {})
+
+    zk.properties(path).update(dict(map(_property, args)))
+
+    zk.close()



More information about the checkins mailing list