[Zope-Checkins] CVS: Zope/utilities - mkzopeinstance.py:1.4
Chris McDonough
chrism@zope.com
Tue, 22 Jul 2003 18:11:13 -0400
Update of /cvs-repository/Zope/utilities
In directory cvs.zope.org:/tmp/cvs-serv28609
Modified Files:
mkzopeinstance.py
Log Message:
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.
=== Zope/utilities/mkzopeinstance.py 1.3 => 1.4 ===
--- Zope/utilities/mkzopeinstance.py:1.3 Sun Jul 20 23:35:34 2003
+++ Zope/utilities/mkzopeinstance.py Tue Jul 22 18:11:08 2003
@@ -17,14 +17,16 @@
usage: %(program)s [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
-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
-paassword.
-
+password and will use ZOPEHOME/skel as the skeleton directory.
"""
import getopt
@@ -34,18 +36,25 @@
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], "hu:z:d:", ["help", "user=",
- "zeo=", "dir="])
+ opts, args = getopt.getopt(sys.argv[1:],
+ "hu:z:d:s:z:l:",
+ ["help", "user=", "dir=", "skel=", "home=", "lib="]
+ )
except getopt.GetoptError, msg:
usage(sys.stderr, msg)
sys.exit(2)
+
+ script = os.path.abspath(sys.argv[0])
user = None
password = None
- zeo = None
dirname = None
+ zopehome = None
+ softwarehome = None
+ skel = None
+
for opt, arg in opts:
if opt in ("-d", "--dir"):
- dirname = os.path.abspath(arg)
+ dirname = os.path.expanduser(os.path.abspath(arg))
if not dirname:
usage(sys.stderr, "dirname must not be empty")
sys.exit(2)
@@ -57,25 +66,41 @@
usage(sys.stderr, "user must be specified as name:password")
sys.exit(2)
user, password = arg.split(":", 1)
- if opt in ("-z", "--zeo"):
- if not ":" in arg:
- usage(sys.stderr, "zeo server must be specified as host:port")
+ if opt in ("-s", "--skel"):
+ skel = os.path.expanduser(os.path.abspath(arg))
+ 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)
- zeo = tuple(arg.split(":", 1))
- try:
- int(zeo[1])
- except ValueError:
- usage(sys.stderr, "zeo server port must be a number")
+ if opt in ("-l", "--lib"):
+ softwarehome = os.path.expanduser(os.path.abspath(arg))
+ if not softwarehome:
+ usage(sys.stderr, "lib must not be empty")
sys.exit(2)
+
+ # interactively ask for dirname and initial user name/passwd
if not dirname:
dirname = get_dirname()
dirname = os.path.expanduser(dirname)
inituser = os.path.join(dirname, "inituser")
if not (user or os.path.exists(inituser)):
user, password = get_inituser()
- makeinstance(dirname, user, password, inituser)
- if zeo:
- makezeo(dirname, zeo)
+
+ # use defaults for zopehome, softwarehome, and skel if they're not
+ # 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):
if msg:
@@ -117,11 +142,8 @@
print "Password mismatch, please try again..."
return user, passwd
-def makeinstance(dirname, user, password, inituser):
- script = os.path.abspath(sys.argv[0])
- installation = os.path.dirname(os.path.dirname(script))
- skel = os.path.join(installation, "skel")
-
+def makeinstance(dirname, user, password, inituser, zopehome,
+ softwarehome, skel):
# Create the top of the instance:
if not os.path.exists(dirname):
os.makedirs(dirname)
@@ -129,8 +151,8 @@
replacements = {
"PYTHON": sys.executable,
"INSTANCE_HOME": dirname,
- "SOFTWARE_HOME": os.path.join(installation, "lib", "python"),
- "ZOPE_HOME": installation,
+ "SOFTWARE_HOME": softwarehome,
+ "ZOPE_HOME": zopehome,
}
# This is fairly ugly. The chdir() makes path manipulation in the
@@ -149,12 +171,6 @@
if user:
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):
import binascii