[zopeorg-checkins] CVS: NZO_SiteLayout/bin - zeoctl.in:1.2

Tres Seaver tseaver at zope.com
Mon Apr 29 16:02:32 EDT 2002


Update of /cvs-zopeorg/NZO_SiteLayout/bin
In directory cvs.zope.org:/tmp/cvs-serv10187/bin

Modified Files:
	zeoctl.in 
Log Message:
 - Add buildout for storage server.

=== NZO_SiteLayout/bin/zeoctl.in 1.1.1.1 => 1.2 ===
 """
-    ZEO storage server controller.
+    Zope appserver controller.
 """
 BASE_DIR = '<<BASE_DIR>>'
 
-USAGE = """zeoctl:  ZEO storage server controller
+USAGE = """\
+
+zeoctl:  ZEO storage server controller
 
 Usage:
     zeoctl [--config=filepath] [commands*]
@@ -14,43 +16,38 @@
                     %(config_file)s
 
 Commands:
-    help [command]
+    help [<command>]
     start
     stop
     restart
     logrotate
     status
-    run
-    debug
+    show [<info>*]
 
     If no commands supplied, runs as an interactive read-eval-print
     interpreter.
 """
 
+from ZopeCtl import ZEOCtl, normalizeDocstring
 
-def _MAKEHELP( command ):
+#
+#   Read-eval-print interpreter
+#
+def _MAKEDO( command ):
     """
         Work around insistence of 'Cmd.help' on printing docstrings with
-        full indentation;  we fabricate a function which does what we
-        want, instead, to permit seating it as 'help_command' within
+        full indentation;  we fabricate a function which has the docstring
+        it expects, using the one from ZopeCtl as a starting point;
+        the generated function is suitable for use as 'do_command' within
         the Cmd-derived class.
     """
 
-    def xhelp( self, command=command ):
-        doc = getattr( self, 'do_' + command ).__doc__
-        lines = doc.split( '\n' )
-        lines = [ line.strip() for line in lines ]
-        print '\n'.join( lines )
-        
-    return xhelp
-
-def _MAKESTUB( command ):
+    def xdo( self, args=None, command=command ):
+        getattr( self._engine, command )( args )
 
-    def xstub( self, command=command, *args ):
-        print "Not implemented: %s" % command
+    xdo.func_doc = normalizeDocstring( getattr( ZEOCtl, command ) )
         
-    return xstub
-
+    return xdo
 
 import cmd
 
@@ -58,65 +55,43 @@
     """
         Interactive command processor.
     """
-    #
-    #   Control engine
-    #
-    _config_file = BASE_DIR + '/etc/zeo.conf'
+    def __init__( self, prompt='zeoctl> ', verbosity=1, base_dir=BASE_DIR ):
 
-    start       = _MAKESTUB( 'start' )
-    restart     = _MAKESTUB( 'restart' )
-    logrotate   = _MAKESTUB( 'logrotate' )
-    stop        = _MAKESTUB( 'stop' )
-    status      = _MAKESTUB( 'status' )
+        self._engine    = ZEOCtl( self._report, base_dir )
+        self.prompt     = prompt
+        self._verbosity = verbosity
 
-    #
-    #   Read-eval-print interpreter
-    #
-    prompt = 'zeoctl> '
+    def _report( self, msg='', level=1 ):
 
-    def do_start( self, arg ):
-        """
-            Start the ZEO storage server.
-        """
-        self.start()
-
-    def do_restart( self, arg ):
-        """
-            Restart the ZEO storage server.
-        """
-        self.restart()
-
-    def do_logrotate( self, arg ):
-        """
-            Rotate the ZEO storage server's logfiles.
-        """
-        self.logrotate()
-
-    def do_stop( self, arg ):
-        """
-            Stop the ZEO storage server.
-        """
-        self.stop()
-
-    def do_status( self, arg ):
-        """
-            Print a message showing the status of the ZEO storage server.
-        """
-        self.status()
+        if self._verbosity >= level:
+            print msg
 
     def default( self, line ):
 
         if line == 'EOF':
-            print
+            self._report()
             return 1
 
+        try:
+            tokens = line.split()
+            method, args = tokens[0], ' '.join( tokens[1:] )
+            method = getattr( self._engine, method, None )
+            if method is not None:
+                method( args )
+                return None
+        except:
+            pass
+
         return cmd.Cmd.default( self, line )
 
-    help_start      = _MAKEHELP( 'start' )
-    help_restart    = _MAKEHELP( 'restart' )
-    help_logrotate  = _MAKEHELP( 'logrotate' )
-    help_stop       = _MAKEHELP( 'stop' )
-    help_status     = _MAKEHELP( 'status' )
+    do_start      = _MAKEDO( 'start' )
+    do_start      = _MAKEDO( 'start' )
+    do_restart    = _MAKEDO( 'restart' )
+    do_logrotate  = _MAKEDO( 'logrotate' )
+    do_logtail    = _MAKEDO( 'logtail' )
+    do_stop       = _MAKEDO( 'stop' )
+    do_status     = _MAKEDO( 'status' )
+    do_show       = _MAKEDO( 'show' )
 
     #
     #   Command-line processing
@@ -125,7 +100,8 @@
 
         import sys
 
-        print USAGE % { 'config_file' : self._config_file }
+        self._report( USAGE % { 'config_file'
+                              : self._engine._getConfigFile() } )
 
         sys.exit( 2 )
 
@@ -143,12 +119,12 @@
         for k, v in options:
 
             if k == '--config':
-                self._config_file = os.path.normpath( v )
+                self._engine._setConfigFile( os.path.normpath( v ) )
             else:
                 usage()
 
         if args:
-            self.cmdqueue.extend( args )
+            self.cmdqueue.append( ' '.join( args ) )
             self.cmdqueue.append( 'EOF' )
 
         self.cmdloop()






More information about the zopeorg-checkins mailing list