[Checkins] SVN: zc.monitor/trunk/src/zc/monitor/ Added a simplified registration interface.

Jim Fulton jim at zope.com
Mon Dec 12 11:42:22 UTC 2011


Log message for revision 123719:
  Added a simplified registration interface.
  

Changed:
  U   zc.monitor/trunk/src/zc/monitor/CHANGES.txt
  U   zc.monitor/trunk/src/zc/monitor/README.txt
  U   zc.monitor/trunk/src/zc/monitor/__init__.py

-=-
Modified: zc.monitor/trunk/src/zc/monitor/CHANGES.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/CHANGES.txt	2011-12-12 11:42:07 UTC (rev 123718)
+++ zc.monitor/trunk/src/zc/monitor/CHANGES.txt	2011-12-12 11:42:22 UTC (rev 123719)
@@ -2,6 +2,11 @@
 Change History
 ==============
 
+0.3.0 (2011-12-12)
+------------------
+
+- Added a simplified registration interface.
+
 0.2.1 (2011-12-10)
 ------------------
 

Modified: zc.monitor/trunk/src/zc/monitor/README.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/README.txt	2011-12-12 11:42:07 UTC (rev 123718)
+++ zc.monitor/trunk/src/zc/monitor/README.txt	2011-12-12 11:42:22 UTC (rev 123719)
@@ -46,15 +46,22 @@
     -> CLOSE
 
 The server comes with a few basic commands.  Let's register
-them so we can see what they do:
+them so we can see what they do.  We'll use the simplfied registration
+interface:
 
-    >>> 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')
+    >>> zc.monitor.register(zc.monitor.help)
+    >>> zc.monitor.register(zc.monitor.interactive)
+    >>> zc.monitor.register(zc.monitor.quit)
 
+The simplified interface takes a command object (usually a function)
+and an optional name.  Bu default, the name is taken from the
+``__name__`` attribute of the command. You can also specify a name:
+
+    >>> zc.monitor.register(zc.monitor.quit, 'exit')
+
+The simplified interface simply registers a utility, as we did above
+for the hello command.
+
 The first is the help command.  Giving help without input, gives a
 list of available commands:
 
@@ -62,6 +69,7 @@
     >>> server = zc.monitor.Server(connection)
     >>> connection.test_input('help\n')
     Supported commands:
+      exit -- Quit the monitor
       hello -- Say hello
       help -- Get help about server commands
       interactive -- Turn on monitor's interactive mode

Modified: zc.monitor/trunk/src/zc/monitor/__init__.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/__init__.py	2011-12-12 11:42:07 UTC (rev 123718)
+++ zc.monitor/trunk/src/zc/monitor/__init__.py	2011-12-12 11:42:22 UTC (rev 123719)
@@ -153,3 +153,9 @@
         connection.write("Help for %s:\n\n%s\n"
                          % (command_name, command.__doc__)
                          )
+
+def register(command, name=None):
+    if name is None:
+        name = command.__name__
+    zope.component.provideUtility(
+        command, zc.monitor.interfaces.IMonitorPlugin, name)



More information about the checkins mailing list