[Zope3-dev] Plans for z3.py

Shane Hathaway shane@zope.com
Wed, 13 Feb 2002 11:31:56 -0500


Hi folks,

z3.py is expanding and it's about time to make it smarter.  However, 
before anyone proceeds with this, I have an idea.  I'd like to consider 
reusing some code I created in the "pma" project (an NNTP server built 
on ZODB--see the zodbex project at SourceForge.)

The ObjectCLI class lets you invoke methods of a Python object directly 
from the command line.  The concept is similar to Zope's publisher, 
which lets you call methods directly from the Web.  Say you created a 
class like this:

class ServerControl:
   """A proxy server."""

   def start(port):
     """Starts the server on the specified port."""

   def stop():
     """Stops the server."""


With two or three lines of glue, you can then invoke the methods of a 
ServerControl instance directly from the command line:

python server_control.py start --port=3128
python server_control.py stop

You can also get the documentation of ServerControl, primarily derived 
from the docstrings:

python server_control.py --help

And you can get more in-depth documentation about each method:

python server_control.py start --help


The author of the ServerControl class never has to use getopt().  All 
you have to do is expose an object to the command line via ObjectCLI. 
(ObjectCLI uses getopt() to do its work.)  A major benefit is that the 
command line arguments and the implementation are less likely to fall 
out of sync.

Thoughts?

Shane