Commit 80154344 authored by Jim Fulton's avatar Jim Fulton

Fixed: the -S option didn't allow a space between the option and it's

argument and didn't work with FileStorages.

The -S option allows you to specify a module variable name that is
different from the storage name.  You can now include a '.py' suffix
in the module name, if you must.
parent 6439da54
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
"""Start the server storage. """Start the server storage.
""" """
__version__ = "$Revision: 1.7 $"[11:-2] __version__ = "$Revision: 1.8 $"[11:-2]
import sys, os, getopt, string import sys, os, getopt, string
...@@ -104,22 +104,28 @@ def get_storage(m, n): ...@@ -104,22 +104,28 @@ def get_storage(m, n):
d, m = os.path.split(m) d, m = os.path.split(m)
if d: p=[d]+p if d: p=[d]+p
import imp import imp
if m[-3:]=='.py': m=m[:-3]
im=imp.find_module(m,p) im=imp.find_module(m,p)
im=imp.load_module(m, im[0], im[1], im[2]) im=imp.load_module(m, im[0], im[1], im[2])
return getattr(im, n) return getattr(im, n)
def main(argv): def main(argv):
me=argv[0] me=argv[0]
sys.path[:]==filter(None, sys.path) sys.path[:]==filter(None, sys.path)
sys.path.insert(0, directory(me, 2)) sys.path.insert(0, directory(me, 2))
args=[] args=[]
last=''
for a in argv[1:]: for a in argv[1:]:
if a[:1] != '-' and string.find(a, '=') > 0: if (a[:1] != '-' and string.find(a, '=') > 0
and last != '-S' # lame, sorry
):
a=string.split(a,'=') a=string.split(a,'=')
os.environ[a[0]]=string.join(a[1:],'=') os.environ[a[0]]=string.join(a[1:],'=')
continue continue
args.append(a) args.append(a)
last=a
INSTANCE_HOME=os.environ.get('INSTANCE_HOME', directory(me, 4)) INSTANCE_HOME=os.environ.get('INSTANCE_HOME', directory(me, 4))
...@@ -128,6 +134,8 @@ def main(argv): ...@@ -128,6 +134,8 @@ def main(argv):
) )
opts, args = getopt.getopt(args, 'p:Dh:U:sS:') opts, args = getopt.getopt(args, 'p:Dh:U:sS:')
fs=os.path.join(INSTANCE_HOME, 'var', 'Data.fs') fs=os.path.join(INSTANCE_HOME, 'var', 'Data.fs')
...@@ -145,10 +153,20 @@ def main(argv): ...@@ -145,10 +153,20 @@ def main(argv):
-s -- Don't use zdeamon -s -- Don't use zdeamon
-Sname=module -- A storage specification The name is the -S storage_name=module_path:attr_name -- A storage specification
storage name used in the ZEO protocol and the module is a
module that defines an attribute with the given name that where:
provides the storage.
storage_name -- is the storage name used in the ZEO protocol.
This is the name that you give as the optional
'storage' keyword argument to the ClientStorage constructor.
module_path -- This is the path to a Python module
that defines the storage object(s) to be served.
The module path should ommit the prefix (e.g. '.py').
attr_name -- This is the name to which the storage object
is assigned in the module.
if no file name is specified, then %s is used. if no file name is specified, then %s is used.
""" % (me, fs) """ % (me, fs)
...@@ -157,7 +175,6 @@ def main(argv): ...@@ -157,7 +175,6 @@ def main(argv):
debug=0 debug=0
host='' host=''
unix=None unix=None
storages=None
prefix='' prefix=''
Z=1 Z=1
for o, v in opts: for o, v in opts:
...@@ -166,10 +183,6 @@ def main(argv): ...@@ -166,10 +183,6 @@ def main(argv):
elif o=='-U': unix=v elif o=='-U': unix=v
elif o=='-D': debug=1 elif o=='-D': debug=1
elif o=='-s': Z=0 elif o=='-s': Z=0
elif o=='-S':
if storages is None: storages={}
n, m = string.split(v,'=')
storages[n]=get_storage(m,n)
try: try:
from ZServer.medusa import asyncore from ZServer.medusa import asyncore
...@@ -198,11 +211,28 @@ def main(argv): ...@@ -198,11 +211,28 @@ def main(argv):
import zdaemon import zdaemon
zdaemon.run(sys.argv, '') zdaemon.run(sys.argv, '')
import ZEO.StorageServer, ZODB.FileStorage, asyncore, zLOG import ZEO.StorageServer, asyncore, zLOG
if not storages: storages={'1': ZODB.FileStorage.FileStorage(fs)}
zLOG.LOG('ZEO Server', zLOG.INFO, 'Serving %s' % storages) storages={}
for o, v in opts:
if o=='-S':
n, m = string.split(v,'=')
if string.find(m,':'):
# we got an attribute name
m, a = string.split(m,':')
else:
# attribute name must be same as storage name
a=n
storages[n]=get_storage(m,a)
if not storages:
import ZODB.FileStorage
storages['1']=ZODB.FileStorage.FileStorage(fs)
items=storages.items()
items.sort()
for kv in items:
zLOG.LOG('ZEO Server', zLOG.INFO, 'Serving %s:\t%s' % kv)
if not unix: unix=host, port if not unix: unix=host, port
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment