[Zope-Coders] DISCUSS: Let's make zctl official

Shane Hathaway shane@zope.com
Wed, 12 Dec 2001 11:56:25 -0500


Paul Everitt wrote:

> 
> Howdy.  It seems that a lot of insiders love to use zctl to administer 
> their Zope processes.  Unfortunately:
> 
>   o There are a number of versions lying around.
> 
>   o Documentation is scattered.
> 
>   o Few people know about it.
> 
> There are proposals in the fishbowl about it.  I think this would be 
> nice, bite-sized chunk for a committer to pick up and get into Zope.
> 
> Casey picked up "Death to index_html" (or the aspect related to 
> configuring object creation, I believe).  Who wants to be second to 
> tackle a much-needed improvement in Zope?

Before we integrate zctl, I'd like to suggest a simple rearchitecting of 
zctl for extensibility and simplicity.  In my "pma" project I came up 
with a way to create a command-line interface for Python objects, 
similar to the way ZPublisher provides a Web interface for Python 
objects.  Command-line arguments are transparently translated into 
arguments to a function call.

An example:


class ZopeCtl:
   """Zope control program.
   """

   def start_zeo(self, host='', port=12345):
      """Starts the ZEO server.

      --host (optional): the hostname to listen on.
      --port (optional): the port to serve.
      """
      # Do stuff here

def main():
   from objectcli import ObjectCLI
   cli = ObjectCLI(ZopeCtl())
   cli()

if __name__ == '__main__':
   main()


ObjectCLI provides a standardish command-line interface.  It expects a 
command which corresponds to a method name as the first argument.  If it 
does not get a command or it gets "--help", it prints usage information 
from the ZopeCtl docstring and the docstrings of the methods.  If it 
gets a command followed by "--help", it prints detailed information 
provided by the docstring of a method.

ObjectCLI uses getopt() to do its work.  The really neat thing is you 
can just subclass ZopeCtl to add or modify commands.  That way 
ZServerSSL wouldn't need to patch zctl, for example.

You can find objectcli.py at the URL below.  I'm thinking of suggesting 
it be added to the Python standard library, but only after it gets some 
mileage.

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/zodbex/zodbex/pma/objectcli.py?rev=1.2&content-type=text/vnd.viewcvs-markup

Shane