Commit b5b0fe01 authored by Chris McDonough's avatar Chris McDonough

Ask for directory name if it's not provided via --dir flag.

Recursively make subdirectories as specified by dirname.

(This is to support interactive instance creation).
parent 0e819c78
...@@ -14,13 +14,17 @@ ...@@ -14,13 +14,17 @@
"""%(program)s: Create a Zope instance home. """%(program)s: Create a Zope instance home.
usage: %(program)s [options] directory usage: %(program)s [options]
Options: Options:
-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 -z/--zeo host:port -- set the host:port of the ZEO server
If no arguments are specified, the installer will ask for dir, username, and
paassword.
""" """
import getopt import getopt
...@@ -30,15 +34,21 @@ import sys ...@@ -30,15 +34,21 @@ import sys
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hu:z:", ["help", "user=", opts, args = getopt.getopt(sys.argv[1:], "hu:z:d:", ["help", "user=",
"zeo="]) "zeo=", "dir="])
except getopt.GetoptError, msg: except getopt.GetoptError, msg:
usage(sys.stderr, msg) usage(sys.stderr, msg)
sys.exit(2) sys.exit(2)
user = None user = None
password = None password = None
zeo = None zeo = None
dirname = None
for opt, arg in opts: for opt, arg in opts:
if opt in ("-d", "--dir"):
dirname = os.path.abspath(arg)
if not dirname:
usage(sys.stderr, "dirname must not be empty")
sys.exit(2)
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
usage(sys.stdout) usage(sys.stdout)
sys.exit() sys.exit()
...@@ -57,10 +67,8 @@ def main(): ...@@ -57,10 +67,8 @@ def main():
except ValueError: except ValueError:
usage(sys.stderr, "zeo server port must be a number") usage(sys.stderr, "zeo server port must be a number")
sys.exit(2) sys.exit(2)
if len(args) != 1: if not dirname:
usage(sys.stderr, "mkzopeinstance requires exactly one argument") dirname = get_dirname()
sys.exit(2)
dirname = os.path.abspath(args[0])
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()
...@@ -75,6 +83,20 @@ def usage(stream, msg=None): ...@@ -75,6 +83,20 @@ def usage(stream, msg=None):
program = os.path.basename(sys.argv[0]) program = os.path.basename(sys.argv[0])
print >>stream, __doc__ % {"program": program} print >>stream, __doc__ % {"program": program}
def get_dirname():
print 'Please choose a directory in which you\'d like to install'
print 'Zope "instance home" files such as database files, configuration'
print 'files, etc.'
print
while 1:
dirname = raw_input("Directory: ").strip()
if dirname == '':
print 'You must specify a directory'
continue
else:
break
return dirname
def get_inituser(): def get_inituser():
import getpass import getpass
print 'Please choose a username and password for the initial user.' print 'Please choose a username and password for the initial user.'
...@@ -101,7 +123,7 @@ def makeinstance(dirname, user, password, inituser): ...@@ -101,7 +123,7 @@ def makeinstance(dirname, user, password, inituser):
# 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.mkdir(dirname) os.makedirs(dirname)
replacements = { replacements = {
"PYTHON": sys.executable, "PYTHON": sys.executable,
......
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