[Zope-Checkins] CVS: Zope/ZopeControl - __init__.py:1.1.2.4 zope.in:1.1.2.4

Matt Behrens matt@zigg.com
Wed, 29 May 2002 15:07:30 -0400


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

Modified Files:
      Tag: zigg_unix-install-control-config-branch
	__init__.py zope.in 
Log Message:
More progress:

- Only overwrite zope control script if same revision level or newer.
  This will permit people to install older Zope versions someday without
  clobbering new functionality.

- Implement -C (configuration directory) and -o (option override)
  options for z2.py.

- Correctly implement start and stop, and fix up create a bit.

If people want to check this branch out and see what it can do, now is
probably the time.



=== Zope/ZopeControl/__init__.py 1.1.2.3 => 1.1.2.4 ===
 
 from ConfigParser import ConfigParser
-import os
+import os, signal, sys
 
-def help(options, extra_args, **kwargs):
+def _printError(s):
+    """Default stderr printer"""
+    sys.stderr.write('%s: %s\n' % (sys.argv[0], s))
+
+def help(options, extra_args, printError=_printError, **kwargs):
     """Provide help"""
-    print "If we were providing help, you'd see it here."
+
+    printError("If we were providing help, you'd see it here.")
 
 def create(options, extra_args, software_name=None, software_home=None,
-	   instance_name=None, instance_home=None, instance_conf_dir=None,
-	   **kwargs):
+           instance_name=None, instance_home=None, instance_conf_dir=None,
+           printError=_printError, **kwargs):
     """Create a new instance"""
 
     # Create and populate instance home
-    os.makedirs(instance_home)
-    for dir in ('Extensions', 'Packages', 'Products', 'import', 'var'):
-        os.mkdir(os.path.join(instance_home, dir))
+    try:
+        os.makedirs(instance_home)
+        for dir in ('Extensions', 'Packages', 'Products', 'import', 'var'):
+            os.mkdir(os.path.join(instance_home, dir), 0700)
+        os.chmod(os.path.join(instance_home, 'var'), 01700)
+    except OSError, e:
+        printError(e)
+        return 1
 
     # Create instance configuration file
     instance_conf = ConfigParser()
@@ -39,9 +49,19 @@
     instance_conf.set('Instance', 'home', instance_home)
     instance_conf.add_section('Software')
     if software_name is not None:
-	instance_conf.set('Software', 'name', software_name)
+        instance_conf.set('Software', 'name', software_name)
     else:
-	instance_conf.set('Software', 'home', software_home)
+        instance_conf.set('Software', 'home', software_home)
+
+    # Set ZServer defaults
+    defaults = {
+        'debug':        '1',
+        'http':         '8080',
+        'ftp':          '8021'
+    }
+    instance_conf.add_section('ZServer')
+    for option in defaults.keys():
+        instance_conf.set('ZServer', option, defaults[option])
 
     os.makedirs(instance_conf_dir)
     f = open(os.path.join(instance_conf_dir, 'instance.conf'), 'w')
@@ -49,12 +69,36 @@
     f.close()
 
 def start(options, extra_args, software_home=None, instance_home=None,
-	  python_binary=None, **kwargs):
+          python_binary=None, instance_conf_dir=None, printError=_printError,
+          instance_conf=None, **kwargs):
     """Start an instance"""
 
+    # Set the appropriate homes
     os.environ['INSTANCE_HOME']=instance_home
     os.environ['SOFTWARE_HOME']=software_home
     os.environ['ZOPE_HOME']=software_home
-    command_line = '%s %s/z2.py -D' % (python_binary, software_home)
+
+    # Load environment overrides from configuration file
+    if instance_conf.has_section('Environment'):
+        for env_name in instance_conf.options('Environment'):
+            os.environ[env_name] = instance_conf.get('Environment', env_name)
+
+    # Construct command line.  Start by telling z2 to clear all servers and
+    # load the instance.conf file.
+    command_line = '%s %s/z2.py -C %s' % (python_binary, software_home,
+                                          instance_conf_dir)
+
+    # Append remaining options as overrides (-o).
+    for option in options.keys():
+        command_line += ' -o %s=%s' % (option, options[option])
+
+    printError('executing %s' % command_line)
     os.system(command_line)
+
+def stop(options, extra_args, instance_home=None, **kwargs):
+    """Stop an instance"""
+
+    pids = open(os.path.join(instance_home, 'var', 'Z2.pid')).readline().strip().split(' ')
+    for pid in pids:
+        os.kill(int(pid), signal.SIGTERM)
 


=== Zope/ZopeControl/zope.in 1.1.2.3 => 1.1.2.4 ===
 ##############################################################################
 
-# Bump this number if you want the Zope installer to replace a lower-numbered
-# version of this script with this script.
-SCRIPT_REVISION = 0
-
-# These commands are reserved for this script.
-SYSTEM_COMMANDS = ['config']
+# The Zope installer will overwrite an installed control utility with a
+# SCRIPT_REVISION equal to or lower than the new script's SCRIPT_REVISION.
+SCRIPT_REVISION = 1
+
+# These commands are reserved for this script and will never be passed on to
+# a software home's control package.
+SYSTEM_COMMANDS = ('config', 'revision')
 
 # Configuration information, written by the source distribution's configure
 # script.
@@ -52,7 +53,7 @@
     sys.stderr.write('%s: %s\n' % (sys.argv[0], s))
 
 def printUsage():
-    printError('%s <command> [<instance>] [<option>=<value> [<option>=<value> ...]]' % sys.argv[0])
+    printError('Usage: %s <command> [<instance>] [<option>=<value> [<option>=<value> ...]]' % os.path.basename(sys.argv[0]))
 
 if __name__ == '__main__':
     argc = len(sys.argv)
@@ -65,6 +66,10 @@
 		print "%s=%s" % (key, CONFIG[key])
 	    sys.exit(0)
 
+	if command == 'revision':
+	    print SCRIPT_REVISION
+	    sys.exit(0)
+
 	# Read the system configuration file.
 	system_conf = ConfigParser()
 	system_conf.read(os.path.join(CONFIG['CONFIG_DIR'], 'system.conf'))
@@ -167,8 +172,10 @@
 					  software_home=software_home,
 					  instance_name=instance_name,
 					  instance_home=instance_home,
+					  instance_conf=instance_conf,
 					  instance_conf_dir=instance_conf_dir,
-					  python_binary=CONFIG['PYTHON'])
+					  python_binary=CONFIG['PYTHON'],
+					  printError=printError)
 	else:
 	    printError('unrecognized command "%s"' % command)