[Zope-CVS] CVS: Packages/Startup/Controller - ZctlLib.py:1.2

Chris McDonough chrism@zope.com
Thu, 2 Jan 2003 11:41:16 -0500


Update of /cvs-repository/Packages/Startup/Controller
In directory cvs.zope.org:/tmp/cvs-serv11415/Controller

Modified Files:
	ZctlLib.py 
Log Message:
Changes supporting chrism-install-branch.


=== Packages/Startup/Controller/ZctlLib.py 1.1.1.1 => 1.2 ===
--- Packages/Startup/Controller/ZctlLib.py:1.1.1.1	Wed Jan  1 06:05:41 2003
+++ Packages/Startup/Controller/ZctlLib.py	Thu Jan  2 11:41:14 2003
@@ -16,33 +16,25 @@
     on the command-line.
 """
 
-from Startup import getSchemaKeys, configure
-
 __version__ = '$Revision$'[11:-2]
 
-def start(config_location, zope_home, software_home, instance_home):
-    """ Called by stub zctl.py in an instance_home """
-    global CONFIG_LOCATION
-    global ZOPE_HOME
-    global ZOPE_PY_LOCATION
-    global SOFTWARE_HOME
-    CONFIG_LOCATION = config_location
-    ZOPE_HOME     = zope_home
-    SOFTWARE_HOME = software_home
-    ZOPE_PY_LOCATION = os.path.join(SOFTWARE_HOME, 'zope.py')
-    _ZopeCtlCmd().main()
-
-import getopt, os, sys, re, signal, cmd, time
+import getopt
+import os
+import sys
+import re
+import signal
+import cmd
+import time
 try:
     import readline
 except:
     readline = None
-
-_marker = []
-
+from Startup import getSchemaKeys, configure
 from Startup.misc import TextBlockFormatter
 from Startup.misc.lock_file import lock_file
 
+_marker = []
+
 USAGE = """\
 
 zctl:  Zope appserver controller
@@ -79,6 +71,10 @@
     interpreter.
 """
 
+def start(config_location):
+    """ Called by stub zctl.py in an instance_home """
+    _ZopeCtlCmd().main(config_location)
+
 class ZopeCtl:
     """
         Workhorse engine for controlling the appserver.
@@ -104,17 +100,18 @@
         if lock_status:
             self._report('Error:  cannot start Zope.  Another Zope '
                          'instance has locked the "%s" file.  Use "stop" '
-                         'to stop it.' %  self._getLockfileName())
+                         'to stop it.' % self._getConfigValue('lock_filename'))
             self._report()
             return
 
         self._report('Starting Zope')
         opts = self._getCommandLineOpts()
-        loc = CONFIG_LOCATION
+        loc = self._getConfigLocation()
         if loc.find(' ') != -1:
             loc = '"%s"' % loc
         config_location = '--config=%s' % loc
-        args = [ZOPE_PY_LOCATION] + [config_location] + opts + [arg]
+        start_script = os.path.join(self._getSoftwareHome(), 'zope.py')
+        args = [start_script] + [config_location] + opts + [arg]
         wait = self._getConfigValue('debug_mode')
         try:
             apply(self._spawnPython, args, {'wait':wait})
@@ -163,14 +160,13 @@
             including:
             
             - PIDs of appserver processes
-            - server port statuses
 
             Syntax:  status
         """
         """
-        Report on process ids and port status
+        Report on process ids
         """
-        pidfile_name = self._getPidfileName()
+        pidfile_name = self._getConfigValue('pid_filename')
         try:
             pids = get_pids(pidfile_name)
         except IOError:
@@ -178,40 +174,8 @@
             self._report('Could not report status (maybe Zope isnt running?)')
             return
 
-        import os
-        from types import TupleType, ListType
-
         self._report( '%-20s : %s' % ( 'PIDS', pids ))
 
-        for key, name in (
-            ('http_server_ports', 'HTTP' ),
-            ('ftp_server_ports' , 'FTP' ),
-            ('webdav_source_server_ports', 'WebDAV' ),
-            ('monitor_server_ports', 'Monitor' ),
-            ('icp_server_ports', 'ICP'),
-            ):
-
-            ports = self._getConfigValue(key)
-            if ports is not None:
-
-                pstat = []
-
-                for port in ports:
-                    try:
-                        portnum = int(port)
-                    except ValueError:
-                        portnum = None
-                    if portnum:
-                        ok = self._checkService( 'localhost', portnum )
-                    else:
-                        ok = 0
-                    status = ok and 'OK' or 'dead'
-                    pstat.append( '%5s (%s)' % ( port, status ) )
-
-                self._report( '%-20s : %s' % ( '%s ports' % name
-                                               , ' '.join( pstat ) ) )
-
-
     def stop(self, arg=None):
         """
             Stop the Zope appserver, using the signal name passed in 'arg'.
@@ -248,7 +212,7 @@
 
     def _kill( self, sig):
         try:
-            pidfile_name = self._getPidfileName()
+            pidfile_name = self._getConfigValue('pid_filename')
             pids = get_pids(pidfile_name)
             pid = pids[-1]
         except IOError:
@@ -323,14 +287,12 @@
 
     def _getRunCmd(self):
         swhome = self._getSoftwareHome()
-        zopehome = self._getZopeHome()
         overrides = self._getOverrides()
         return(
             "import os, sys; os.environ['EVENT_LOG_SEVERITY']='300'; "
-            "sys.path.insert(0, '%s'); sys.path.insert(0, '%s'); "
-            "from Startup import configure; configure('%s', %s)"
-            "import Zope; app=Zope.app()"
-            % ( zopehome, swhome, CONFIG_LOCATION, overrides)
+            "sys.path.insert(0, '%s'); from Startup import configure; "
+            "configure('%s', %s); import Zope; app=Zope.app()"
+            % ( swhome, self._getConfigLocation(), overrides)
             )
 
     def run( self, arg ):
@@ -353,8 +315,6 @@
 
             Syntax: debug
         """
-        swhome = self._getSoftwareHome()
-        zopehome = self._getZopeHome()
         cmd = self._getRunCmd()
         cmd = cmdquote(cmd)
         msg = ('Starting debugger.  The name "app" will be bound to the Zope '
@@ -405,20 +365,14 @@
     def _setConfig( self, config ):
         self._config = config
 
-    def _getSoftwareHome(self):
-        return self._getConfigValue('software_home')
-
-    def _getZopeHome(self):
-        return ZOPE_HOME
+    def _setConfigLocation(self, config_location):
+        self._config_location = config_location
 
-    def _getClientHome(self):
-        return self._getConfigValue('client_home')
+    def _getConfigLocation(self):
+        return self._config_location
 
-    def _getPidfileName(self):
-        return self._getConfigValue('pid_filename')
-
-    def _getLockfileName(self):
-        return self._getConfigValue('lock_filename')
+    def _getSoftwareHome(self):
+        return self._getConfigValue('software_home')
 
     def _getConfigValue(self, name):
         return getattr(self._config, name)
@@ -511,20 +465,14 @@
 
     def _showConfigPath( self ):
         self._report()
-        self._report('Configuration Path: %s' % CONFIG_LOCATION)
+        self._report('Configuration Path: %s' % self._getConfigLocation())
         self._report()
 
     def _showConfigValues( self ):
         self._report()
         self._report( 'Config-file specified values:' )
         self._report()
-        printable = []
-        items = self._config.items()
-        items.sort()
-        for k, v in items:
-            printable.append('%-40s: %s' % (k, v))
-        printable = '\n'.join(printable)        
-        self._report( printable )
+        self._report( str(self._config) )
         self._report()
 
     def _showCommandLine(self):
@@ -535,7 +483,7 @@
         self._report()
  
     def lockFile(self):
-        filename = os.path.join(self._getLockfileName())
+        filename = self._getConfigValue('lock_filename')
         if not os.path.exists(filename):
             return 0
         file = open(filename, 'r+')
@@ -699,7 +647,7 @@
     def usage( self ):
         self._report( USAGE )
 
-    def main( self ):
+    def main( self, config_location ):
         overrides = {}
         # add relevant options to options list
         schema_keys = getSchemaKeys()
@@ -717,15 +665,15 @@
                 self.usage()
                 sys.exit(0)
             elif k == '--config':
-                global CONFIG_LOCATION
-                CONFIG_LOCATION = v
+                config_location = v
                 overrides[k[2:]] = v
             else:
                 if k.startswith('--'):
                     k = k[2:]
                     overrides[k] = v
-        config = configure(CONFIG_LOCATION, overrides)
+        config = configure(config_location, overrides)
         self._engine._setConfig(config)
+        self._engine._setConfigLocation(config_location)
         self._engine._setCommandLineOpts(opts)
         self._engine._setOverrides(overrides)
         if args: