[Checkins] SVN: zc.z3monitor/trunk/ Add "interactive" command. Add "database" argument to "monitor" command.

Gary Poster gary at modernsongs.com
Thu Sep 4 00:09:03 EDT 2008


Log message for revision 90779:
  Add "interactive" command.  Add "database" argument to "monitor" command.
  
  * The new ``interactive`` command makes connections continue through multiple
    commands until you use the ``quit`` command.
  
  * The ``monitor`` command takes an optional database argument (after the legacy
    ``long`` argument)
  
  Also switched to bootstrap external.
  
  

Changed:
  _U  zc.z3monitor/trunk/
  D   zc.z3monitor/trunk/bootstrap.py
  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

-=-

Property changes on: zc.z3monitor/trunk
___________________________________________________________________
Name: svn:ignore
   - .installed.cfg
develop-eggs
bin
parts

   + .installed.cfg
develop-eggs
bin
parts
dist
*.kpf
*.bbproject
tags
TAGS
ID

Name: svn:externals
   + bootstrap svn://svn.zope.org/repos/main/zc.buildout/trunk/bootstrap


Deleted: zc.z3monitor/trunk/bootstrap.py
===================================================================
--- zc.z3monitor/trunk/bootstrap.py	2008-09-04 03:35:13 UTC (rev 90778)
+++ zc.z3monitor/trunk/bootstrap.py	2008-09-04 04:09:00 UTC (rev 90779)
@@ -1,55 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Bootstrap a buildout-based project
-
-Simply run this script in a directory containing a buildout.cfg.
-The script accepts buildout command-line options, so you can
-use the -c option to specify an alternate configuration file.
-
-$Id$
-"""
-
-import os, shutil, sys, tempfile, urllib2
-
-tmpeggs = tempfile.mkdtemp()
-
-try:
-    import pkg_resources
-except ImportError:
-    ez = {}
-    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
-                         ).read() in ez
-    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
-
-    import pkg_resources
-
-cmd = 'from setuptools.command.easy_install import main; main()'
-if sys.platform == 'win32':
-    cmd = '"%s"' % cmd # work around spawn lamosity on windows
-
-ws = pkg_resources.working_set
-assert os.spawnle(
-    os.P_WAIT, sys.executable, sys.executable,
-    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
-    dict(os.environ,
-         PYTHONPATH=
-         ws.find(pkg_resources.Requirement.parse('setuptools')).location
-         ),
-    ) == 0
-
-ws.add_entry(tmpeggs)
-ws.require('zc.buildout')
-import zc.buildout.buildout
-zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
-shutil.rmtree(tmpeggs)

Modified: zc.z3monitor/trunk/setup.py
===================================================================
--- zc.z3monitor/trunk/setup.py	2008-09-04 03:35:13 UTC (rev 90778)
+++ zc.z3monitor/trunk/setup.py	2008-09-04 04:09:00 UTC (rev 90779)
@@ -8,7 +8,7 @@
 
 setup(
     name = name,
-    version = '0.5',
+    version = '0.6.0a1',
     author = 'Jim Fulton',
     author_email = 'jim at zope.com',
     license = 'ZPL 2.1',

Modified: zc.z3monitor/trunk/src/zc/z3monitor/CHANGES.txt
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/CHANGES.txt	2008-09-04 03:35:13 UTC (rev 90778)
+++ zc.z3monitor/trunk/src/zc/z3monitor/CHANGES.txt	2008-09-04 04:09:00 UTC (rev 90779)
@@ -2,12 +2,24 @@
 Change History
 ==============
 
-0.5 (2008-4-4)
-==============
+0.6.0 (2008-??-??)
+==================
 
 Features
 --------
 
+* The new ``interactive`` command makes connections continue through multiple
+  commands until you use the ``quit`` command.
+
+* The ``monitor`` command takes an optional database argument (after the legacy
+  ``long`` argument).
+
+0.5.0 (2008-4-4)
+================
+
+Features
+--------
+
 * If the requested monitor port is in use, log and move on, rather than
   stopping the process with an exception.  This lets ``zopectl debug``
   work with a running instance.

Modified: zc.z3monitor/trunk/src/zc/z3monitor/README.txt
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/README.txt	2008-09-04 03:35:13 UTC (rev 90778)
+++ zc.z3monitor/trunk/src/zc/z3monitor/README.txt	2008-09-04 04:09:00 UTC (rev 90779)
@@ -48,6 +48,10 @@
 
     >>> 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,
@@ -65,7 +69,9 @@
       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
+      quit -- Quit the monitor
       zeocache -- Get ZEO client cache statistics
       zeostatus -- Get ZEO client status information
     -> CLOSE
@@ -91,8 +97,36 @@
     <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.
 
-The commands that come with the monitor use database information.  
+    >>> 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.
 
@@ -133,6 +167,9 @@
         seconds old. You can pass a minimum old connection age in seconds.
         If you pass a value of 0, you'll see all connections.
     <BLANKLINE>
+        If you pass a name after the integer, this is used as the database name.
+        The database name defaults to the empty string ('').
+    <BLANKLINE>
     -> CLOSE
 
     >>> connection.test_input('monitor\n')
@@ -141,6 +178,12 @@
     VmRSS:	   28764 kB 
     -> CLOSE
 
+    >>> connection.test_input('monitor 100 other\n')
+    0 
+    VmSize:	   35284 kB 
+    VmRSS:	   28764 kB 
+    -> CLOSE
+
 Note that, as of this writing, the VmSize and VmRSS lines will only be present
 on a system with procfs.  This generally includes many varieties of Linux,
 and excludes OS X and Windows.

Modified: zc.z3monitor/trunk/src/zc/z3monitor/__init__.py
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/__init__.py	2008-09-04 03:35:13 UTC (rev 90778)
+++ zc.z3monitor/trunk/src/zc/z3monitor/__init__.py	2008-09-04 04:09:00 UTC (rev 90779)
@@ -32,12 +32,16 @@
 
 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()
@@ -48,17 +52,42 @@
             zc.z3monitor.interfaces.IZ3MonitorPlugin,
             command_name)
         if command is None:
-            connection.write('invalid command %r\n' % command_name)
+            connection.write(
+                'Invalid command %r\nTry "help".\n' % command_name)
         else:
             try:
-                command(connection, *args)
+                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
 
-        connection.write(zc.ngi.END_OF_DATA)
+        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
 
@@ -84,7 +113,9 @@
 
 opened_time_search = re.compile('[(](\d+[.]\d*)s[)]').search
 
-def monitor(connection, long=100):
+def monitor(connection, long=100, database=''):
+    # this order of arguments is often inconvenient, but supports legacy usage
+    # in which ``database`` was not an option.
     """Get general process info
 
     The minimal output has:
@@ -98,10 +129,13 @@
     default, connections are considered old if they are greater than 100
     seconds old. You can pass a minimum old connection age in seconds.
     If you pass a value of 0, you'll see all connections.
+
+    If you pass a name after the integer, this is used as the database name.
+    The database name defaults to the empty string ('').
     """
 
     min = float(long)
-    db = zope.component.getUtility(ZODB.interfaces.IDatabase)
+    db = zope.component.getUtility(ZODB.interfaces.IDatabase, database)
 
     result = []
     nconnections = 0

Modified: zc.z3monitor/trunk/src/zc/z3monitor/configure.zcml
===================================================================
--- zc.z3monitor/trunk/src/zc/z3monitor/configure.zcml	2008-09-04 03:35:13 UTC (rev 90778)
+++ zc.z3monitor/trunk/src/zc/z3monitor/configure.zcml	2008-09-04 04:09:00 UTC (rev 90779)
@@ -1,6 +1,10 @@
 <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=".monitor"



More information about the Checkins mailing list