[Checkins] SVN: zc.monitor/trunk/ initial import.
Gary Poster
gary at modernsongs.com
Sun Sep 14 14:35:05 EDT 2008
Log message for revision 91142:
initial import.
Changed:
_U zc.monitor/trunk/
A zc.monitor/trunk/CHANGES.txt
A zc.monitor/trunk/README.txt
A zc.monitor/trunk/bootstrap.py
A zc.monitor/trunk/buildout.cfg
A zc.monitor/trunk/setup.py
A zc.monitor/trunk/src/
A zc.monitor/trunk/src/zc/
A zc.monitor/trunk/src/zc/__init__.py
A zc.monitor/trunk/src/zc/monitor/
A zc.monitor/trunk/src/zc/monitor/CHANGES.txt
A zc.monitor/trunk/src/zc/monitor/README.txt
A zc.monitor/trunk/src/zc/monitor/__init__.py
A zc.monitor/trunk/src/zc/monitor/interfaces.py
A zc.monitor/trunk/src/zc/monitor/tests.py
-=-
Property changes on: zc.monitor/trunk
___________________________________________________________________
Name: svn:ignore
+ .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
Added: zc.monitor/trunk/CHANGES.txt
===================================================================
--- zc.monitor/trunk/CHANGES.txt (rev 0)
+++ zc.monitor/trunk/CHANGES.txt 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1 @@
+See CHANGES.txt in package.
Property changes on: zc.monitor/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.monitor/trunk/README.txt
===================================================================
--- zc.monitor/trunk/README.txt (rev 0)
+++ zc.monitor/trunk/README.txt 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1 @@
+A network-accessible command-line monitoring interface.
Property changes on: zc.monitor/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.monitor/trunk/bootstrap.py
===================================================================
--- zc.monitor/trunk/bootstrap.py (rev 0)
+++ zc.monitor/trunk/bootstrap.py 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1 @@
+link .bootstrap/bootstrap.py
\ No newline at end of file
Property changes on: zc.monitor/trunk/bootstrap.py
___________________________________________________________________
Name: svn:special
+ *
Added: zc.monitor/trunk/buildout.cfg
===================================================================
--- zc.monitor/trunk/buildout.cfg (rev 0)
+++ zc.monitor/trunk/buildout.cfg 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,12 @@
+[buildout]
+develop = .
+parts = test interpreter
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zc.monitor
+
+[interpreter]
+recipe = zc.recipe.egg
+eggs = zc.monitor
+interpreter = py
Property changes on: zc.monitor/trunk/buildout.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.monitor/trunk/setup.py
===================================================================
--- zc.monitor/trunk/setup.py (rev 0)
+++ zc.monitor/trunk/setup.py 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,27 @@
+from setuptools import setup, find_packages
+
+name = 'zc.monitor'
+
+long_description = (open('src/zc/monitor/README.txt').read() +
+ "\n\n" +
+ open('src/zc/monitor/CHANGES.txt').read())
+
+setup(
+ name = name,
+ version = '0.1.0',
+ author = 'Jim Fulton',
+ author_email = 'jim at zope.com',
+ license = 'ZPL 2.1',
+ keywords = 'zope3',
+ description=open('README.txt').read(),
+ long_description=long_description,
+
+ packages = find_packages('src'),
+ namespace_packages = ['zc'],
+ package_dir = {'': 'src'},
+ install_requires = [
+ 'setuptools', 'zc.ngi', 'zope.component', 'zope.testing',
+ ],
+ include_package_data = True,
+ zip_safe = False,
+ )
Added: zc.monitor/trunk/src/zc/__init__.py
===================================================================
--- zc.monitor/trunk/src/zc/__init__.py (rev 0)
+++ zc.monitor/trunk/src/zc/__init__.py 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,5 @@
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Added: zc.monitor/trunk/src/zc/monitor/CHANGES.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/CHANGES.txt (rev 0)
+++ zc.monitor/trunk/src/zc/monitor/CHANGES.txt 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,8 @@
+==============
+Change History
+==============
+
+0.1.0 (2008-09-14)
+------------------
+
+Initial release
Property changes on: zc.monitor/trunk/src/zc/monitor/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.monitor/trunk/src/zc/monitor/README.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/README.txt (rev 0)
+++ zc.monitor/trunk/src/zc/monitor/README.txt 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,134 @@
+==============
+Monitor Server
+==============
+
+The monitor server is a server 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.
+
+ >>> import zc.ngi.testing
+ >>> import zc.monitor
+
+ >>> connection = zc.ngi.testing.TextConnection()
+ >>> server = zc.monitor.Server(connection)
+
+The server supports an extensible set of commands. It looks up
+commands as named zc.monitor.interfaces.IMonitorPlugin "utilities", as defined
+by the zope.component package.
+
+To see this, we'll create a hello plugin:
+
+ >>> 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)
+
+and register it:
+
+ >>> import zope.component, zc.monitor.interfaces
+ >>> zope.component.provideUtility(
+ ... hello, zc.monitor.interfaces.IMonitorPlugin, 'hello')
+
+Now we can give the hello command to the server:
+
+ >>> connection.test_input('hello\n')
+ Hi world, nice to meet ya!
+ -> CLOSE
+
+We can pass a name:
+
+ >>> connection.test_input('hello Jim\n')
+ Hi Jim, nice to meet ya!
+ -> CLOSE
+
+The server comes with a few basic commands. Let's register
+them so we can see what they do:
+
+ >>> 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 first is the help command. Giving help without input, gives a
+list of available commands:
+
+ >>> connection.test_input('help\n')
+ Supported commands:
+ hello -- Say hello
+ help -- Get help about server commands
+ interactive -- Turn on monitor's interactive mode
+ quit -- Quit the monitor
+ -> CLOSE
+
+We can get detailed help by specifying a command name:
+
+ >>> 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>
+ In interactive mode, an empty line repeats the last 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>
+
+Notice that the result of the commands did not end with "-> CLOSE", which would
+have indicated a closed connection.
+
+Also notice that the interactive mode allows you to repeat commands.
+
+ >>> connection.test_input('hello\n')
+ Hi world, nice to meet ya!
+ >>> connection.test_input('\n')
+ Hi world, nice to meet ya!
+ >>> connection.test_input('hello Jim\n')
+ Hi Jim, nice to meet ya!
+ >>> connection.test_input('\n')
+ Hi Jim, nice to meet ya!
+
+Now we will use ``quit`` to close the connection.
+
+ >>> connection.test_input('quit\n')
+ Goodbye.
+ -> CLOSE
Property changes on: zc.monitor/trunk/src/zc/monitor/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.monitor/trunk/src/zc/monitor/__init__.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/__init__.py (rev 0)
+++ zc.monitor/trunk/src/zc/monitor/__init__.py 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,133 @@
+##############################################################################
+#
+# Copyright (c) 2005-2008 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.
+#
+##############################################################################
+"""Zope 3 Monitor Server
+"""
+
+import errno, logging, traceback, socket
+
+import zope.component
+
+import zc.ngi.adapters
+import zc.monitor.interfaces
+
+INTERACTIVE_MARKER = object()
+QUIT_MARKER = object()
+
+class Server:
+
+ last_command = None
+
+ 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:
+ if self.last_command is not None:
+ command_name, args = self.last_command
+ else:
+ return
+ else:
+ command_name = args.pop(0)
+ self.last_command = (command_name, args)
+ command = zope.component.queryUtility(
+ zc.monitor.interfaces.IMonitorPlugin,
+ 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 start(port):
+ """start monitor server.
+
+ Returns True if monitor server started; returns False if the port is
+ already in use; and raises an exception otherwise.
+ """
+ import zc.ngi.async
+ try:
+ zc.ngi.async.listener(('', port), Server)
+ except socket.error, e:
+ if e.args[0] == errno.EADDRINUSE:
+ # Don't kill the process just because somebody else has our port.
+ # This might be a zopectl debug or some other innocuous problem.
+ logging.warning(
+ 'unable to start z3monitor server because port %d is in use.',
+ port)
+ return False
+ else:
+ raise
+ return True
+
+# default commands
+
+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.
+
+ In interactive mode, an empty line repeats the last 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.monitor.interfaces.IMonitorPlugin)))
+ + '\n'))
+ else:
+ command = zope.component.getUtility(
+ zc.monitor.interfaces.IMonitorPlugin,
+ command_name)
+ connection.write("Help for %s:\n\n%s\n"
+ % (command_name, command.__doc__)
+ )
Added: zc.monitor/trunk/src/zc/monitor/interfaces.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/interfaces.py (rev 0)
+++ zc.monitor/trunk/src/zc/monitor/interfaces.py 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2005-2008 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.
+#
+##############################################################################
+
+import zope.interface
+
+class IMonitorPlugin(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.
+ """
Added: zc.monitor/trunk/src/zc/monitor/tests.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/tests.py (rev 0)
+++ zc.monitor/trunk/src/zc/monitor/tests.py 2008-09-14 18:35:05 UTC (rev 91142)
@@ -0,0 +1,24 @@
+##############################################################################
+#
+# Copyright (c) 2004-2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+import unittest
+
+from zope.testing import doctest
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite(
+ 'README.txt',
+ ),
+
+ ))
More information about the Checkins
mailing list