[Checkins] SVN: zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/ Tweaked helper script to get ports:

Jim Fulton jim at zope.com
Wed Feb 22 16:37:28 UTC 2012


Log message for revision 124457:
  Tweaked helper script to get ports:
  
  - Allow a trailing / as abbreviation for trailing /providers
  
  - Optional argument for property name.
  

Changed:
  U   zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/README.txt
  U   zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/__init__.py

-=-
Modified: zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/README.txt
===================================================================
--- zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/README.txt	2012-02-21 23:21:23 UTC (rev 124456)
+++ zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/README.txt	2012-02-22 16:37:25 UTC (rev 124457)
@@ -454,8 +454,7 @@
     Raw:  zk-port
     {'eggs': 'zc.zk [static]',
      'entry-points': 'zk-port=time:time',
-     'initialization': "\nimport zc.zk\nzk =
-      zc.zk.ZK('zookeeper.example.com:2181/myproj2012-01-26T14:50:24.864772')\nprint zk.get_children(sys.argv[1])[0].split(':')[-1]\nzk.close()\n",
+     'initialization': "\nargs = sys.argv[1:]\nimport zc.zk\nzk = zc.zk.ZK('zookeeper.example.com:2181/myproj2012-01-26T14:50:24.864772')\npath = args.pop(0)\nif path[-1:] == '/':\n    path += 'providers'\nchild = zk.get_children(path)[0]\nif args:\n    [prop] = args\n    child = zk.get_properties(path + '/' + child)[prop]\nprint child.split(':')[-1]\nzk.close()\n",
      'recipe': 'zc.recipe.egg',
      'scripts': 'zk-port'}
     ()
@@ -477,7 +476,7 @@
 Change History
 ==============
 
-0.2.0 (2011-02-21)
+0.2.0 (2011-02-22)
 ------------------
 
 Add an option to define buildout-specific helper scripts for working

Modified: zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/__init__.py
===================================================================
--- zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/__init__.py	2012-02-21 23:21:23 UTC (rev 124456)
+++ zc.zookeeperrecipes/trunk/src/zc/zookeeperrecipes/__init__.py	2012-02-22 16:37:25 UTC (rev 124457)
@@ -165,8 +165,16 @@
         return f.read()
 
 zkport = """
+args = sys.argv[1:]
 import zc.zk
 zk = zc.zk.ZK(%r)
-print zk.get_children(sys.argv[1])[0].split(':')[-1]
+path = args.pop(0)
+if path[-1:] == '/':
+    path += 'providers'
+child = zk.get_children(path)[0]
+if args:
+    [prop] = args
+    child = zk.get_properties(path + '/' + child)[prop]
+print child.split(':')[-1]
 zk.close()
 """



More information about the checkins mailing list