[Zope-Checkins] CVS: Zope/inst - zctl.in:1.1.2.3

Chris McDonough chrism@zope.com
Mon, 2 Sep 2002 14:38:47 -0400


Update of /cvs-repository/Zope/inst
In directory cvs.zope.org:/tmp/cvs-serv16840/inst

Modified Files:
      Tag: chrism-install-branch
	zctl.in 
Log Message:
Fix the configfile generator to show prettier output.

Add a 'shell' command to zctl which allows you to do things like:
"!vi zope.conf" from within zctl.


=== Zope/inst/zctl.in 1.1.2.2 => 1.1.2.3 ===
--- Zope/inst/zctl.in:1.1.2.2	Mon Sep  2 03:35:09 2002
+++ Zope/inst/zctl.in	Mon Sep  2 14:38:46 2002
@@ -92,8 +92,9 @@
         """
         lock_status = self.lockFile()
         if lock_status:
-            self._report('Cannot start Zope.  Another Zope instance must '
-                         ' be running.  Use "stop" to stop it.')
+            self._report('Cannot start Zope.  Another Zope instance has locked'
+                         ' the "%s" file.  Use "stop" to stop it.' % 
+                         self.getPidfileName())
             self._report()
             return
         zope_py = os.path.join(self._getZopeHome(), 'zope.py')
@@ -150,7 +151,43 @@
 
             Syntax:  status
         """
-        self._doPrintStatus()
+        """
+        Report on process ids and port status
+        """
+        pidfile_name = self._getPidfileName()
+        try:
+            pids = get_pids(pidfile_name)
+        except IOError:
+            self._report('Pid file %s could not be found' % pidfile_name)
+            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._getDirective(key)
+            if ports is not None:
+
+                pstat = []
+
+                for port in ports:
+                    ok = self._checkService( 'localhost', port )
+                    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):
         """
@@ -166,6 +203,26 @@
             self._report('Zope stopped successfully')
         return status
 
+    def shell(self, arg=None):
+        """
+            Run a command using the system shell.  Commands passed to zctl
+            which start with a '!' will also be interpreted by the
+            system shell.
+
+            Syntax: [ shell [command] | !command ]
+
+            Examples:
+
+            'shell vi zope.conf'
+            '!vi zope.conf'
+        """
+        if sys.platform == 'win32':
+            os.system('cmd "%s"' % arg)
+        elif os.name == 'posix':
+            os.system('sh -c "%s"' % arg)
+        else:
+            self._report('No shell known for system %s' % os.name)
+
     def _kill( self, sig):
         try:
             pidfile_name = self._getPidfileName()
@@ -351,42 +408,6 @@
         else:
             return 1
 
-    def _doPrintStatus( self ):
-        """
-        Report on process ids and port status
-        """
-        try:
-            pids = get_pids(self._getPidfileName())
-        except IOError:
-            self._report('pid file could not be found.')
-            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._getDirective(key)
-            if ports is not None:
-
-                pstat = []
-
-                for port in ports:
-                    ok = self._checkService( 'localhost', port )
-                    status = ok and 'OK' or 'dead'
-                    pstat.append( '%5s (%s)' % ( port, status ) )
-
-                self._report( '%-20s : %s' % ( '%s ports' % name
-                                               , ' '.join( pstat ) ) )
-
     def _showDict( self, d ):
 
         if d:
@@ -523,6 +544,7 @@
     do_run           = _MAKEDO( 'run' )
     do_debug         = _MAKEDO( 'debug' )
     do_quit          = _MAKEDO( 'quit' )
+    do_shell         = _MAKEDO( 'shell' )
 
     #
     #   Command-line processing
@@ -543,7 +565,7 @@
         
         for k, v in o:
             if k in ('-h', '--help'):
-                usage()
+                self.usage()
                 sys.exit(0)
             elif k == '--config-file':
                 filename = v