[Zope-Checkins] CVS: Zope/ZopeControl - .cvsignore:1.1.2.1 __init__.py:1.1.2.2 zope.in:1.1.2.2

Matt Behrens matt@zigg.com
Wed, 22 May 2002 21:19:37 -0400


Update of /cvs-repository/Zope/ZopeControl
In directory cvs.zope.org:/tmp/cvs-serv23389/ZopeControl

Modified Files:
      Tag: zigg_unix-install-control-config-branch
	__init__.py zope.in 
Added Files:
      Tag: zigg_unix-install-control-config-branch
	.cvsignore 
Log Message:
Further progress on this branch.

'zope create', to create an instance, works now, although the
instance is currently rather bare :-)



=== Added File Zope/ZopeControl/.cvsignore ===
zope


=== Zope/ZopeControl/__init__.py 1.1.2.1 => 1.1.2.2 ===
 #
 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE
-# 
+#
 ##############################################################################
 
 """
@@ -15,6 +16,29 @@
 system control utility.
 """
 
-def help(instance, args):
+import ConfigParser, os
+
+def help(instance_name, instance_conf, args):
+    """Provide help"""
     print "If we were providing help, you'd see it here."
+
+def create(instance_name, instance_home, software_name, config_dir):
+    """Create a new instance"""
+    try: os.makedirs(instance_home)
+    except: pass
+
+    for dir in ('Extensions', 'Packages', 'Products', 'import', 'var'):
+        os.mkdir(os.path.join(instance_home, dir))
+
+    instance_conf = ConfigParser.ConfigParser()
+    instance_conf.add_section('Paths')
+    instance_conf.set('Paths', 'InstanceHome', instance_home)
+    instance_conf.add_section('Software')
+    instance_conf.set('Software', 'SoftwareName', software_name)
+
+    try: os.makedirs(os.path.join(config_dir, instance_name))
+    except: pass
+    f = open(os.path.join(config_dir, instance_name, 'instance.conf'), 'w')
+    instance_conf.write(f)
+    f.close()
 


=== Zope/ZopeControl/zope.in 1.1.2.1 => 1.1.2.2 ===
+#! @PYTHON@
+##############################################################################
 #
 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE
-# 
+#
 ##############################################################################
 
 # Bump this number if you want the Zope installer to replace a lower-numbered
 # version of this script with this script.
-version = 0
+SCRIPT_REVISION = 0
+
+# These commands are reserved for this script.
+SYSTEM_COMMANDS = ('config', 'create')
 
 # Configuration information, written by the source distribution's configure
 # script.
-configured = {
+CONFIG = {
     # GNU-style configured paths
-    'PREFIX':		'@PREFIX@',
-    'BINDIR':		'@BINDIR@',
-    'ETCDIR':		'@ETCDIR@',
-    'LIBDIR':		'@LIBDIR@',
-    'VARDIR':		'@VARDIR@',
+    'PREFIX':           '@PREFIX@',
+    'BINDIR':           '@BINDIR@',
+    'ETCDIR':           '@ETCDIR@',
+    'LIBDIR':           '@LIBDIR@',
+    'VARDIR':           '@VARDIR@',
     # Additional Zope configured paths
-    'CONFIG_DIR':	'@CONFIG_DIR@',
-    'SOFTWARE_DIR':	'@SOFTWARE_DIR@',
+    'CONFIG_DIR':       '@CONFIG_DIR@',
+    'SOFTWARE_DIR':     '@SOFTWARE_DIR@',
     'INSTANCE_DIR':     '@INSTANCE_DIR@',
 }
 
-import ConfigParser, os, string, sys
+import ConfigParser, getopt, os, string, sys
 
 def do(command, instance, args):
-    if command == 'config':
-    	# Output configured variables and exit.
-    	for key in configured.keys():
-	    print '%s=%s' % (key, configured[key])
-	sys.exit(0)
-
     # Determine software and instance homes for the given instance.
     instance_conf = getInstanceConf(instance)
-    instance_home = instance_conf.get('Paths', 'InstanceHome')
-    software_name = instance_conf.get('Software', 'SoftwareName')
-    software_home = getSoftwareConf().get('SoftwareHomes', software_name)
+    instance_home = instance_conf.get('paths', 'instance_home')
+    software_name = instance_conf.get('software', 'software_name')
+    software_home = getSystemConf().get('software_homes', software_name)
 
     # Import Control from the instance home or fallback to software home.
     sys.path.insert(0, software_home)
     sys.path.insert(0, instance_home)
-    import Control
+    import ZopeControl
 
     # Run the given command.
-    Control[command](instance, args)
+    sys.exit(ZopeControl.__dict__[command](instance, args))
+
+def doSystemCommand(command, args):
+    if command == 'config':
+        for key in CONFIG.keys():
+            print "%s=%s" % (key, CONFIG[key])
+        sys.exit(0)
+    elif command == 'create':
+        argc = len(args)
+        if (argc == 0) or (args[0][0] == '-'):
+            instance_name = 'default'
+            arg_start = 0
+        else:
+            instance_name = args[0]
+            arg_start = 1
+        instance_home = os.path.join(CONFIG['INSTANCE_DIR'], instance_name)
+        software_name = getDefaultSoftware()
+        opts, args = getopt.getopt(args[arg_start:], '',
+                                   ['software-name=', 'instance-home='])
+        for opt, value in opts:
+            if opt == '--software-name':
+                software_name = value
+            if opt == '--instance-home':
+                instance_home = value
+
+        software_home = getSystemConf().get('software_homes', software_name)
+        sys.path.insert(0, software_home)
+        import ZopeControl
+
+        sys.exit(ZopeControl.__dict__['create'](instance_name, instance_home,
+                                                software_name,
+                                                CONFIG['CONFIG_DIR']))
 
 def getDefaultInstance():
-    return getSystemConf().get('Defaults', 'Instance')
+    try: return getSystemConf().get('defaults', 'instance')
+    except: return None
+
+def getDefaultSoftware():
+    try: return getSystemConf().get('defaults', 'software')
+    except: return None
 
 def getInstanceConf(instance):
     instance_conf = ConfigParser.ConfigParser()
-    instance_conf.read(os.path.join(configured['CONFIG_DIR'],
-				    instance,
-				    'instance.conf'))
+    instance_conf.read(os.path.join(CONFIG['CONFIG_DIR'],
+                                    instance,
+                                    'instance.conf'))
     return instance_conf
 
 def getSystemConf():
     system_conf = ConfigParser.ConfigParser()
-    system_conf.read(os.path.join(configured['CONFIG_DIR'], 'system.conf'))
+    system_conf.read(os.path.join(CONFIG['CONFIG_DIR'], 'system.conf'))
     return system_conf
 
 def printUsage():
-    print "Usage: %s <command> [<instance>] [<arg> [<arg> ...]]"
+    print "Usage: %s <command> [<instance>] [<arg> [<arg> ...]]" % sys.argv[0]
 
 if __name__ == '__main__':
     argc = len(sys.argv)
     if argc > 1:
-    	command = string.lower(sys.argv[1])
-	if argc > 2:
-	    if sys.argv[2][0] == '-':
-		instance = getDefaultInstance()
-		args = sys.argv[2:]
-	    else:
-		instance = sys.argv[2]
-		args = sys.argv[3:]
-	else:
-	    instance = getDefaultInstance()
-	    args = []
-	do(command, instance, args)
-	sys.exit(0)
+        command = string.lower(sys.argv[1])
+        if command in SYSTEM_COMMANDS:
+            if argc > 2:
+                doSystemCommand(command, sys.argv[2:])
+            else:
+                doSystemCommand(command, [])
+        if argc > 2:
+            if sys.argv[2][0] == '-':
+                instance = getDefaultInstance()
+                args = sys.argv[2:]
+            else:
+                instance = sys.argv[2]
+                args = sys.argv[3:]
+        else:
+            instance = getDefaultInstance()
+            args = []
+        if instance is None:
+            print "No default instance has been configured."
+            printUsage()
+            sys.exit(1)
+        do(command, instance, args)
     else:
-	printUsage()
-	sys.exit(1)
+        printUsage()
+        sys.exit(1)