[Checkins] SVN: zc.z3monitor/trunk/s depend on zc.monitor. prepare for 0.7.0.

Gary Poster gary at modernsongs.com
Sun Sep 14 15:32:09 EDT 2008


Log message for revision 91145:
  depend on zc.monitor.  prepare for 0.7.0.

Changed:
  U   zc.z3monitor/trunk/setup.py
  U   zc.z3monitor/trunk/src/zc/z3monitor/CHANGES.txt
  U   zc.z3monitor/trunk/src/zc/z3monitor/README.txt
  U   zc.z3monitor/trunk/src/zc/z3monitor/__init__.py
  U   zc.z3monitor/trunk/src/zc/z3monitor/configure.zcml
  U   zc.z3monitor/trunk/src/zc/z3monitor/interfaces.py

-=-
Modified: zc.z3monitor/trunk/setup.py
===================================================================
--- zc.z3monitor/trunk/setup.py	2008-09-14 19:25:29 UTC (rev 91144)
+++ zc.z3monitor/trunk/setup.py	2008-09-14 19:32:08 UTC (rev 91145)
@@ -20,8 +20,8 @@
     namespace_packages = ['zc'],
     package_dir = {'': 'src'},
     install_requires = [
-        'setuptools', 'zc.ngi', 'ZODB3', 'zope.component',
-        'zope.publisher', 'zope.app.appsetup',
+        'setuptools', 'zc.monitor', 'ZODB3', 'zope.component',
+        'zope.publisher', 'zope.app.appsetup', 'zope.testing',
         ],
     include_package_data = True,
     zip_safe = False,

Modified: zc.z3monitor/trunk/src/zc/z3monitor/CHANGES.txt
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/CHANGES.txt	2008-09-14 19:25:29 UTC (rev 91144)
+++ zc.z3monitor/trunk/src/zc/z3monitor/CHANGES.txt	2008-09-14 19:32:08 UTC (rev 91145)
@@ -5,8 +5,19 @@
 0.7.0 (2008-??-??)
 ==================
 
-(No changes at this time)
+Features
+--------
 
+* The zc.monitor ``interactive`` mode now supports repeating the previous
+  command by sending an empty line.
+
+Other
+-----
+
+* The server and the ``help``, ``interactive``, and ``quit`` commands have
+  been factored out into a new zc.monitor package, on which zc.z3monitor now
+  depends.
+
 0.6.0 (2008-09-14)
 ==================
 

Modified: zc.z3monitor/trunk/src/zc/z3monitor/README.txt
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/README.txt	2008-09-14 19:25:29 UTC (rev 91144)
+++ zc.z3monitor/trunk/src/zc/z3monitor/README.txt	2008-09-14 19:32:08 UTC (rev 91145)
@@ -2,56 +2,54 @@
 Zope 3 Monitor Server
 =====================
 
-The Zope 3 monitor server is a server that runs in a Zope 3 process
-and that provides a command-line interface to request various bits of
-information.  The server is zc.ngi based, so we can use the zc.ngi
-testing infrastructure to demonstrate it.
+The Zope 3 monitor server is a server that runs in a Zope 3 process and that
+provides a command-line interface to request various bits of information.  It
+is based on zc.monitor, which is itself based on zc.ngi, so we can use the
+zc.ngi testing infrastructure to demonstrate it.
 
-    >>> import zc.ngi.testing
-    >>> import zc.z3monitor
+This package provides several Zope 3 and ZODB monitoring and introspection
+tools that work within the zc.monitor server.  These are demonstrated below.
 
-    >>> connection = zc.ngi.testing.TextConnection()
-    >>> server = zc.z3monitor.Server(connection)
+Please see the zc.monitor documentation for details on how the server works.
 
-The server supports an extensible set of commands.  It looks up
-commands as named zc.z3monitor.interfaces.IZ3MonitorPlugin plugins.
+This package also supports starting a monitor using ZConfig, and provides a
+default configure.zcml for registering plugins.  
 
-To see this, we'll create a hello plugin:
+The ZConfig setup is not demonstrated in this documentation, but the usage is
+simple.  In your ZConfig file, provide a "product-config" stanza for
+zc.z3monitor that specifies the port on which the zc.monitor server should
+listen.  For instance, this stanza will start a monitor server on port 8888::
 
-    >>> def hello(connection, name='world'):
-    ...     """Say hello
-    ...     
-    ...     Provide a name if you're not the world.
-    ...     """
-    ...     connection.write("Hi %s, nice to meet ya!\n" % name) 
+    <product-config zc.z3monitor>
+        port 8888
+    </product-config>
 
-and register it:
+To include the default commands of zc.monitor and zc.z3monitor, simply include
+the configure.zcml from this package::
 
-    >>> import zope.component, zc.z3monitor.interfaces
-    >>> zope.component.provideUtility(
-    ...   hello, zc.z3monitor.interfaces.IZ3MonitorPlugin, 'hello')
+    <include package="zc.z3monitor" />
 
-Now we can give the hello command to the server:
+Now let's look at the commands that this package provides.  We'll get a test
+connection to the monitor server and register the plugins that zc.monitor and
+zc.z3monitor provide.
 
-    >>> connection.test_input('hello\n')
-    Hi world, nice to meet ya!
-    -> CLOSE
+    >>> import zc.ngi.testing
+    >>> import zc.monitor
+    >>> import zc.monitor.interfaces
+    >>> import zc.z3monitor
+    >>> import zc.z3monitor.interfaces
+    >>> import zope.component
 
-We can pass a name:
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
 
-    >>> connection.test_input('hello Jim\n')
-    Hi Jim, nice to meet ya!
-    -> CLOSE
+    >>> zope.component.provideUtility(zc.monitor.help,
+    ...     zc.monitor.interfaces.IMonitorPlugin, 'help')
+    >>> zope.component.provideUtility(zc.monitor.interactive,
+    ...     zc.monitor.interfaces.IMonitorPlugin, 'interactive')
+    >>> zope.component.provideUtility(zc.monitor.quit,
+    ...     zc.monitor.interfaces.IMonitorPlugin, 'quit')
 
-The server comes with a number of useful commands.  Let's register
-them so we can see what they do:
-
-    >>> zope.component.provideUtility(zc.z3monitor.help,
-    ...     zc.z3monitor.interfaces.IZ3MonitorPlugin, 'help')
-    >>> zope.component.provideUtility(zc.z3monitor.interactive,
-    ...     zc.z3monitor.interfaces.IZ3MonitorPlugin, 'interactive')
-    >>> zope.component.provideUtility(zc.z3monitor.quit,
-    ...     zc.z3monitor.interfaces.IZ3MonitorPlugin, 'quit')
     >>> zope.component.provideUtility(zc.z3monitor.monitor,
     ...     zc.z3monitor.interfaces.IZ3MonitorPlugin, 'monitor')
     >>> zope.component.provideUtility(zc.z3monitor.dbinfo,
@@ -61,13 +59,12 @@
     >>> zope.component.provideUtility(zc.z3monitor.zeostatus,
     ...     zc.z3monitor.interfaces.IZ3MonitorPlugin, 'zeostatus')
 
-The first is the help command.  Giving help without input, gives a
-list of available commands:
+We'll use the zc.monitor ``help`` command to see the list of available
+commands:
 
     >>> connection.test_input('help\n')
     Supported commands:
       dbinfo -- Get database statistics
-      hello -- Say hello
       help -- Get help about server commands
       interactive -- Turn on monitor's interactive mode
       monitor -- Get general process info
@@ -76,60 +73,10 @@
       zeostatus -- Get ZEO client status information
     -> CLOSE
 
-We can get detailed help by specifying a command name:
+The commands that come with the zc.z3monitor package use database information.
+They access databases as utilities.  Let's create some test databases and
+register them as utilities.
 
-    >>> connection.test_input('help help\n')
-    Help for help:
-    <BLANKLINE>
-    Get help about server commands
-    <BLANKLINE>
-        By default, a list of commands and summaries is printed.  Provide
-        a command name to get detailed documentation for a command.
-    <BLANKLINE>
-    -> CLOSE
-
-    >>> connection.test_input('help hello\n')
-    Help for hello:
-    <BLANKLINE>
-    Say hello
-    <BLANKLINE>
-        Provide a name if you're not the world.
-    <BLANKLINE>
-    -> CLOSE
-
-The ``interactive`` command switches the monitor into interactive mode.  As
-seen above, the monitor usually responds to a single command and then closes
-the connection.  In "interactive mode", the connection is not closed until
-the ``quit`` command is used.  This can be useful when accessing the monitor
-via telnet for diagnostics.
-
-    >>> connection.test_input('interactive\n')
-    Interactive mode on.  Use "quit" To exit.
-    >>> connection.test_input('help interactive\n')
-    Help for interactive:
-    <BLANKLINE>
-    Turn on monitor's interactive mode
-    <BLANKLINE>
-        Normally, the monitor releases the connection after a single command.
-        By entering the interactive mode, the monitor will not end the connection
-        until you enter the "quit" command.
-    <BLANKLINE>
-    >>> connection.test_input('help quit\n')
-    Help for quit:
-    <BLANKLINE>
-    Quit the monitor
-    <BLANKLINE>
-        This is only really useful in interactive mode (see the "interactive"
-        command).
-    <BLANKLINE>
-    >>> connection.test_input('quit\n')
-    Goodbye.
-    -> CLOSE
-
-The other commands that come with the monitor use database information.  
-They access databases as utilities.  Let's create some test databases
-and register them as utilities.
-
     >>> from ZODB.tests.util import DB
     >>> main = DB()
     >>> from zope import component

Modified: zc.z3monitor/trunk/src/zc/z3monitor/__init__.py
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/__init__.py	2008-09-14 19:25:29 UTC (rev 91144)
+++ zc.z3monitor/trunk/src/zc/z3monitor/__init__.py	2008-09-14 19:32:08 UTC (rev 91145)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2005 Zope Corporation and Contributors.
+# Copyright (c) 2005-2008 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -14,13 +14,12 @@
 """Zope 3 Monitor Server
 """
 
-import errno, logging, os, re, time, traceback, socket
+import os, re, time
 
 import ZODB.ActivityMonitor
 import ZODB.interfaces
-
+import zc.monitor
 import zope.component
-import zope.component.interfaces
 import zope.interface
 import zope.publisher.browser
 import zope.publisher.interfaces.browser
@@ -30,87 +29,6 @@
 import zope.app.appsetup.product
 import zope.app.publication.interfaces
 
-import zc.ngi.adapters
-
-INTERACTIVE_MARKER = object()
-QUIT_MARKER = object()
-
-class Server:
-
-    def __init__(self, connection):
-        connection = zc.ngi.adapters.Lines(connection)
-        self.connection = connection
-        connection.setHandler(self)
-        self.mode = QUIT_MARKER
-
-    def handle_input(self, connection, data):
-        args = data.strip().split()
-        if not args:
-            return
-        command_name = args.pop(0)
-        command = zope.component.queryUtility(
-            zc.z3monitor.interfaces.IZ3MonitorPlugin,
-            command_name)
-        if command is None:
-            connection.write(
-                'Invalid command %r\nTry "help".\n' % command_name)
-        else:
-            try:
-                res = command(connection, *args)
-            except Exception, v:
-                traceback.print_exc(100, connection)
-                print >> connection, "%s: %s\n" % (v.__class__.__name__, v)
-            if res is INTERACTIVE_MARKER:
-                self.mode = res
-            elif res is QUIT_MARKER:
-                self.mode = res
-
-        if self.mode is QUIT_MARKER:
-            connection.write(zc.ngi.END_OF_DATA)
-
-
-def interactive(connection):
-    """Turn on monitor's interactive mode
-    
-    Normally, the monitor releases the connection after a single command.
-    By entering the interactive mode, the monitor will not end the connection
-    until you enter the "quit" command.
-    """
-    connection.write('Interactive mode on.  Use "quit" To exit.\n')
-    return INTERACTIVE_MARKER
-
-def quit(connection):
-    """Quit the monitor
-    
-    This is only really useful in interactive mode (see the "interactive"
-    command).
-    """
-    connection.write('Goodbye.\n')
-    return QUIT_MARKER
-
-def help(connection, command_name=None):
-    """Get help about server commands
-
-    By default, a list of commands and summaries is printed.  Provide
-    a command name to get detailed documentation for a command.
-    """
-    if command_name is None:
-        connection.write(str(
-            "Supported commands:\n  "
-            + '\n  '.join(sorted(
-                "%s -- %s" % (name, (u.__doc__ or '?').split('\n', 1)[0])
-                for (name, u) in
-                zope.component.getUtilitiesFor(
-                    zc.z3monitor.interfaces.IZ3MonitorPlugin)))
-            + '\n'))
-    else:
-        command = zope.component.getUtility(
-            zc.z3monitor.interfaces.IZ3MonitorPlugin,
-            command_name)
-        connection.write("Help for %s:\n\n%s\n"
-                         % (command_name, command.__doc__)
-                         )
-
 opened_time_search = re.compile('[(](\d+[.]\d*)s[)]').search
 
 def monitor(connection, long=100, database=''):
@@ -254,19 +172,7 @@
             db.setActivityMonitor(ZODB.ActivityMonitor.ActivityMonitor())
 
     port = int(config['port'])
-    import zc.ngi.async
-    try:
-        zc.ngi.async.listener(('', port), Server)
-    except socket.error, e:
-        if e.args[0] == errno.EADDRINUSE:
-            # this might be a zopectl debug.  Don't kill the process just
-            # because somebody else has our port.
-            logging.warning(
-                'unable to start z3monitor server because port %d is in use.',
-                port)
-        else:
-            raise
-        
+    zc.monitor.start(int(config['port']))
 
 @zope.component.adapter(
     zope.traversing.interfaces.IContainmentRoot,

Modified: zc.z3monitor/trunk/src/zc/z3monitor/configure.zcml
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/configure.zcml	2008-09-14 19:25:29 UTC (rev 91144)
+++ zc.z3monitor/trunk/src/zc/z3monitor/configure.zcml	2008-09-14 19:32:08 UTC (rev 91145)
@@ -1,12 +1,12 @@
 <configure xmlns="http://namespaces.zope.org/zope">
   <subscriber handler=".initialize" />
   <subscriber handler=".save_request_in_connection_info" />
-  <utility component=".interactive"
-           provides=".interfaces.IZ3MonitorPlugin" name="interactive" />
-  <utility component=".quit"
-           provides=".interfaces.IZ3MonitorPlugin" name="quit" />
-  <utility component=".help"
-           provides=".interfaces.IZ3MonitorPlugin" name="help" />
+  <utility component="zc.monitor.interactive"
+           provides="zc.monitor.interfaces.IMonitorPlugin" name="interactive" />
+  <utility component="zc.monitor.quit"
+           provides="zc.monitor.interfaces.IMonitorPlugin" name="quit" />
+  <utility component="zc.monitor.help"
+           provides="zc.monitor.interfaces.IMonitorPlugin" name="help" />
   <utility component=".monitor"
            provides=".interfaces.IZ3MonitorPlugin" name="monitor" />
   <utility component=".dbinfo"

Modified: zc.z3monitor/trunk/src/zc/z3monitor/interfaces.py
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/interfaces.py	2008-09-14 19:25:29 UTC (rev 91144)
+++ zc.z3monitor/trunk/src/zc/z3monitor/interfaces.py	2008-09-14 19:32:08 UTC (rev 91145)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2005 Zope Corporation and Contributors.
+# Copyright (c) 2005-2008 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -12,14 +12,7 @@
 #
 ##############################################################################
 
-import zope.interface
+import zc.monitor.interfaces
 
-class IZ3MonitorPlugin(zope.interface.Interface):
-
-    def __call__(output, *args):
-        """Compute some monitoring information
-
-        The output argument is a file-like object with write method.
-
-        A variable number of arguments are passed.
-        """
+class IZ3MonitorPlugin(zc.monitor.interfaces.IMonitorPlugin):
+    pass



More information about the Checkins mailing list