Commit a840bd51 authored by Chris McDonough's avatar Chris McDonough

Add --skel, --home, and --lib options to mkzopeinstance.

--skel points to an alternate skeleton directory.

--home allows you to write infiles with an alternate zope home

--lib allows you to write infiles with an alternate software home.

Remove --zeo/-z flags, as custom_zodb.py is no longer the preferred method
of configuring custom storages now that we have DBTab in the core,
and you should be able to create a custom skeleton dir with
the right zope.conf.in that has a zeo client storage set up if you need to.
parent 0d409824
...@@ -17,14 +17,16 @@ ...@@ -17,14 +17,16 @@
usage: %(program)s [options] usage: %(program)s [options]
Options: Options:
-d/--dir -- the directory to which the instance files should be installed -d/--dir -- the directory to which the instance files should be installed
-h/--help -- print this help text -h/--help -- print this help text
-u/--user NAME:PASSWORD -- set the user name and password of the initial user -u/--user NAME:PASSWORD -- set the user name and password of the initial user
-z/--zeo host:port -- set the host:port of the ZEO server -s/--skel -- the 'skeleton' directory which contains instance files
-z/--home -- the zope home directory (aka ZOPE_HOME) (defaults to ..)
-l/--lib -- the zope lib directory (aka SOFTWARE_HOME) (defaults to
../lib/python)
If no arguments are specified, the installer will ask for dir, username, and If no arguments are specified, the installer will ask for dir, username, and
paassword. password and will use ZOPEHOME/skel as the skeleton directory.
""" """
import getopt import getopt
...@@ -34,18 +36,25 @@ import sys ...@@ -34,18 +36,25 @@ import sys
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hu:z:d:", ["help", "user=", opts, args = getopt.getopt(sys.argv[1:],
"zeo=", "dir="]) "hu:z:d:s:z:l:",
["help", "user=", "dir=", "skel=", "home=", "lib="]
)
except getopt.GetoptError, msg: except getopt.GetoptError, msg:
usage(sys.stderr, msg) usage(sys.stderr, msg)
sys.exit(2) sys.exit(2)
script = os.path.abspath(sys.argv[0])
user = None user = None
password = None password = None
zeo = None
dirname = None dirname = None
zopehome = None
softwarehome = None
skel = None
for opt, arg in opts: for opt, arg in opts:
if opt in ("-d", "--dir"): if opt in ("-d", "--dir"):
dirname = os.path.abspath(arg) dirname = os.path.expanduser(os.path.abspath(arg))
if not dirname: if not dirname:
usage(sys.stderr, "dirname must not be empty") usage(sys.stderr, "dirname must not be empty")
sys.exit(2) sys.exit(2)
...@@ -57,25 +66,41 @@ def main(): ...@@ -57,25 +66,41 @@ def main():
usage(sys.stderr, "user must be specified as name:password") usage(sys.stderr, "user must be specified as name:password")
sys.exit(2) sys.exit(2)
user, password = arg.split(":", 1) user, password = arg.split(":", 1)
if opt in ("-z", "--zeo"): if opt in ("-s", "--skel"):
if not ":" in arg: skel = os.path.expanduser(os.path.abspath(arg))
usage(sys.stderr, "zeo server must be specified as host:port") if not skel:
usage(sys.stderr, "skel must not be empty")
sys.exit(2)
if opt in ("-h", "--home"):
zopehome = os.path.expanduser(os.path.abspath(arg))
if not zopehome:
usage(sys.stderr, "home must not be empty")
sys.exit(2) sys.exit(2)
zeo = tuple(arg.split(":", 1)) if opt in ("-l", "--lib"):
try: softwarehome = os.path.expanduser(os.path.abspath(arg))
int(zeo[1]) if not softwarehome:
except ValueError: usage(sys.stderr, "lib must not be empty")
usage(sys.stderr, "zeo server port must be a number")
sys.exit(2) sys.exit(2)
# interactively ask for dirname and initial user name/passwd
if not dirname: if not dirname:
dirname = get_dirname() dirname = get_dirname()
dirname = os.path.expanduser(dirname) dirname = os.path.expanduser(dirname)
inituser = os.path.join(dirname, "inituser") inituser = os.path.join(dirname, "inituser")
if not (user or os.path.exists(inituser)): if not (user or os.path.exists(inituser)):
user, password = get_inituser() user, password = get_inituser()
makeinstance(dirname, user, password, inituser)
if zeo: # use defaults for zopehome, softwarehome, and skel if they're not
makezeo(dirname, zeo) # given
if zopehome is None:
zopehome = os.path.dirname(os.path.dirname(script))
if softwarehome is None:
softwarehome = os.path.join(zopehome, "lib", "python")
if skel is None:
skel = os.path.join(zopehome, "skel")
makeinstance(dirname, user, password, inituser, zopehome, softwarehome,
skel)
def usage(stream, msg=None): def usage(stream, msg=None):
if msg: if msg:
...@@ -117,11 +142,8 @@ def get_inituser(): ...@@ -117,11 +142,8 @@ def get_inituser():
print "Password mismatch, please try again..." print "Password mismatch, please try again..."
return user, passwd return user, passwd
def makeinstance(dirname, user, password, inituser): def makeinstance(dirname, user, password, inituser, zopehome,
script = os.path.abspath(sys.argv[0]) softwarehome, skel):
installation = os.path.dirname(os.path.dirname(script))
skel = os.path.join(installation, "skel")
# Create the top of the instance: # Create the top of the instance:
if not os.path.exists(dirname): if not os.path.exists(dirname):
os.makedirs(dirname) os.makedirs(dirname)
...@@ -129,8 +151,8 @@ def makeinstance(dirname, user, password, inituser): ...@@ -129,8 +151,8 @@ def makeinstance(dirname, user, password, inituser):
replacements = { replacements = {
"PYTHON": sys.executable, "PYTHON": sys.executable,
"INSTANCE_HOME": dirname, "INSTANCE_HOME": dirname,
"SOFTWARE_HOME": os.path.join(installation, "lib", "python"), "SOFTWARE_HOME": softwarehome,
"ZOPE_HOME": installation, "ZOPE_HOME": zopehome,
} }
# This is fairly ugly. The chdir() makes path manipulation in the # This is fairly ugly. The chdir() makes path manipulation in the
...@@ -150,12 +172,6 @@ def makeinstance(dirname, user, password, inituser): ...@@ -150,12 +172,6 @@ def makeinstance(dirname, user, password, inituser):
if user: if user:
write_inituser(inituser, user, password) write_inituser(inituser, user, password)
def makezeo(dirname, zeo):
fp = open(os.path.join(dirname, 'custom_zodb.py'), 'w')
print >>fp, "import ZEO.ClientStorage"
print >>fp, "Storage=ZEO.ClientStorage.ClientStorage(('%s',%s))"%zeo
fp.close()
def write_inituser(fn, user, password): def write_inituser(fn, user, password):
import binascii import binascii
import sha import sha
......
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