[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/ Added a convenience function to start a storage server without having
Jim Fulton
jim at zope.com
Fri Nov 28 13:53:56 EST 2008
Log message for revision 93431:
Added a convenience function to start a storage server without having
to create configuration files first. This is primarily useful for
exploration and development.
Changed:
U ZODB/trunk/src/ZEO/__init__.py
U ZODB/trunk/src/ZEO/tests/forker.py
U ZODB/trunk/src/ZEO/tests/zeoserver.py
-=-
Modified: ZODB/trunk/src/ZEO/__init__.py
===================================================================
--- ZODB/trunk/src/ZEO/__init__.py 2008-11-28 16:57:04 UTC (rev 93430)
+++ ZODB/trunk/src/ZEO/__init__.py 2008-11-28 18:53:55 UTC (rev 93431)
@@ -25,4 +25,56 @@
import ZEO.ClientStorage, ZODB
return ZODB.DB(ZEO.ClientStorage.ClientStorage(*args, **kw))
+def server(path=None, blob_dir=None, storage_conf=None, zeo_conf=None,
+ port=None):
+ """Convenience function to start a server for interactive exploration
+
+ This fuction starts a ZEO server, given a storage configuration or
+ a file-storage path and blob directory. You can also supply a ZEO
+ configuration string or a port. If neither a ZEO port or
+ configuration is supplied, a port is chosen randomly.
+
+ The server address and a stop function are returned. The address
+ can be passed to ZEO.ClientStorage.ClientStorage or ZEO.DB to
+ create a client to the server. The stop function can be called
+ without arguments to stop the server.
+
+ Arguments:
+
+ path
+ A file-storage path. This argument is ignored if a storage
+ configuration is supplied.
+ blob_dir
+ A blob directory path. This argument is ignored if a storage
+ configuration is supplied.
+
+ storage_conf
+ A storage configuration string. If none is supplied, then at
+ least a file-storage path must be supplied and the storage
+ configuration will be generated from the file-storage path and
+ the blob directory.
+
+ zeo_conf
+ A ZEO server configuration string.
+
+ port
+ If no ZEO configuration is supplied, the one will be computed
+ from the port. If no port is supplied, one will be chosedn
+ randomly.
+
+ """
+ import os, ZEO.tests.forker
+ if storage_conf is None and path is None:
+ raise TypeError("You must specify either a storage_conf or file path.")
+ if port is None and zeo_conf is None:
+ port = ZEO.tests.forker.get_port()
+
+ addr, admin, pid, config = ZEO.tests.forker.start_zeo_server(
+ storage_conf, zeo_conf, port, keep=True, path=path,
+ blob_dir=blob_dir, suicide=False)
+ os.remove(config)
+ def stop_server():
+ ZEO.tests.forker.shutdown_zeo_server(admin)
+ os.waitpid(pid, 0)
+ return addr, stop_server
Modified: ZODB/trunk/src/ZEO/tests/forker.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/forker.py 2008-11-28 16:57:04 UTC (rev 93430)
+++ ZODB/trunk/src/ZEO/tests/forker.py 2008-11-28 18:53:55 UTC (rev 93431)
@@ -86,7 +86,8 @@
def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
- path='Data.fs', protocol=None):
+ path='Data.fs', protocol=None, blob_dir=None,
+ suicide=True):
"""Start a ZEO server in a separate process.
Takes two positional arguments a string containing the storage conf
@@ -98,6 +99,9 @@
if not storage_conf:
storage_conf = '<filestorage>\npath %s\n</filestorage>' % path
+ if blob_dir:
+ storage_conf = '<blobstorage>\nblob-dir %s\n%s\n</blobstorage>' % (
+ blob_dir, storage_conf)
if port is None:
raise AssertionError("The port wasn't specified")
@@ -126,6 +130,8 @@
args = [qa(sys.executable), qa(script), '-C', qa(tmpfile)]
if keep:
args.append("-k")
+ if not suicide:
+ args.append("-S")
if protocol:
args.extend(["-v", protocol])
Modified: ZODB/trunk/src/ZEO/tests/zeoserver.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/zeoserver.py 2008-11-28 16:57:04 UTC (rev 93430)
+++ ZODB/trunk/src/ZEO/tests/zeoserver.py 2008-11-28 18:53:55 UTC (rev 93431)
@@ -153,13 +153,16 @@
# wrong, it's a bug in the test suite.
keep = 0
configfile = None
+ suicide = True
# Parse the arguments and let getopt.error percolate
- opts, args = getopt.getopt(sys.argv[1:], 'kC:v:')
+ opts, args = getopt.getopt(sys.argv[1:], 'kSC:v:')
for opt, arg in opts:
if opt == '-k':
keep = 1
elif opt == '-C':
configfile = arg
+ elif opt == '-S':
+ suicide = False
elif opt == '-v':
import ZEO.zrpc.connection
ZEO.zrpc.connection.Connection.current_protocol = arg
@@ -205,10 +208,11 @@
sys.exit(2)
t.register_socket(server.dispatcher)
- # Create daemon suicide thread
- d = Suicide(test_addr)
- d.setDaemon(1)
- d.start()
+ if suicide:
+ # Create daemon suicide thread
+ d = Suicide(test_addr)
+ d.setDaemon(1)
+ d.start()
# Loop for socket events
log(label, 'entering asyncore loop')
asyncore.loop()
More information about the Zodb-checkins
mailing list