[Zope3-checkins] SVN: Zope3/trunk/ Added `getInfo(generation)` method to `zope.app.generations`'s

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Dec 9 12:52:41 EST 2004


Log message for revision 28597:
  Added `getInfo(generation)` method to `zope.app.generations`'s
  `ISchemaManager`. It will return some information about the evolver
  that brings the database to the specified generation. This way we can
  document the various evolutions. The standard `ISchemaManager`
  implementation uses the `evolve()` function's docstring to determine
  the information string. Added a view showing the information strings
  via the Web UI.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/generations/browser/configure.zcml
  A   Zope3/trunk/src/zope/app/generations/browser/managerdetails.pt
  A   Zope3/trunk/src/zope/app/generations/browser/managerdetails.py
  U   Zope3/trunk/src/zope/app/generations/browser/managers.pt
  U   Zope3/trunk/src/zope/app/generations/browser/tests.py
  U   Zope3/trunk/src/zope/app/generations/demo/evolve1.py
  U   Zope3/trunk/src/zope/app/generations/demo/evolve2.py
  U   Zope3/trunk/src/zope/app/generations/generations.py
  U   Zope3/trunk/src/zope/app/generations/interfaces.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/doc/CHANGES.txt	2004-12-09 17:52:40 UTC (rev 28597)
@@ -10,6 +10,14 @@
 
     New features
 
+      - Added `getInfo(generation)` method to `zope.app.generations`'s
+        `ISchemaManager`. It will return some information about the evolver
+        that brings the database to the specified generation. This way we can
+        document the various evolutions. The standard `ISchemaManager`
+        implementation uses the `evolve()` function's docstring to determine
+        the information string. Added a view showing the information strings
+        via the Web UI.
+
       - Implemented local permission. This is not really that interesting
         right now, since we do not support TTW development yet, but it will
         become important somewhen.

Modified: Zope3/trunk/src/zope/app/generations/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/generations/browser/configure.zcml	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/browser/configure.zcml	2004-12-09 17:52:40 UTC (rev 28597)
@@ -12,4 +12,12 @@
     permission="zope.ManageApplication"
     />
 
+<page
+    name="generations_managerdetails.html"
+    for="zope.app.applicationcontrol.interfaces.IApplicationControl"
+    class=".managerdetails.ManagerDetails"
+    template="managerdetails.pt"
+    permission="zope.ManageApplication"
+    />
+
 </zope:configure>

Added: Zope3/trunk/src/zope/app/generations/browser/managerdetails.pt
===================================================================
--- Zope3/trunk/src/zope/app/generations/browser/managerdetails.pt	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/browser/managerdetails.pt	2004-12-09 17:52:40 UTC (rev 28597)
@@ -0,0 +1,30 @@
+<html metal:use-macro="context/@@standard_macros/view" i18n:domain="zope">
+<head>
+<title metal:fill-slot="title">Manager Detials</title>
+</head>
+<body>
+<div metal:fill-slot="body">
+
+<h1 i18n:translate="">
+ <b i18n:name="application_id" tal:content="view/id" />
+ Application Manager Details
+</h1>
+<br/>
+
+<tal:block repeat="evolver view/getEvolvers">
+
+<h2 i18n:translate="">
+  Evolver 
+  from Generation <b i18n:name="from" tal:content="evolver/from"/>
+  to Generation <b i18n:name="to" tal:content="evolver/to"/>
+</h2>
+<br />
+<div tal:content="structure evolver/info">
+  Evolution information.
+</div>
+
+</tal:block>
+
+</div>
+</body>
+</html>

Added: Zope3/trunk/src/zope/app/generations/browser/managerdetails.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/browser/managerdetails.py	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/browser/managerdetails.py	2004-12-09 17:52:40 UTC (rev 28597)
@@ -0,0 +1,89 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Manager Details View
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+from zope.app import zapi
+from zope.app.generations.interfaces import ISchemaManager
+from zope.app.renderer.rest import ReStructuredTextToHTMLRenderer
+
+class ManagerDetails(object):
+    r"""Show Details of a particular Schema Manager's Evolvers
+
+    This method needs to use the component architecture, so
+    we'll set it up:
+    
+      >>> from zope.app.tests.placelesssetup import setUp, tearDown
+      >>> setUp()
+    
+    We need to define some schema managers.  We'll define just one:
+    
+      >>> from zope.app.generations.generations import SchemaManager
+      >>> from zope.app.tests import ztapi
+      >>> app1 = SchemaManager(0, 3, 'zope.app.generations.demo')
+      >>> ztapi.provideUtility(ISchemaManager, app1, 'foo.app1')
+
+    Now let's create the view:
+
+      >>> from zope.publisher.browser import TestRequest
+      >>> details = ManagerDetails()
+      >>> details.context = None
+      >>> details.request = TestRequest(environ={'id': 'foo.app1'})
+
+    Let's now see that the view gets the ID correctly from the request:
+
+      >>> details.id
+      'foo.app1'
+
+    Now check that we get all the info from the evolvers:
+
+      >>> info = details.getEvolvers()
+      >>> import pprint
+      >>> pp = pprint.PrettyPrinter(width=76)
+      >>> pp.pprint(info)
+      [{'from': 0,
+        'info': u'<div class="document">\nEvolver 1</div>\n',
+        'to': 1},
+       {'from': 1,
+        'info': u'<div class="document">\nEvolver 2</div>\n',
+        'to': 2},
+       {'info': '', 'to': 3, 'from': 2}]
+
+    We'd better clean up:
+
+      >>> tearDown()
+    """
+
+    id = property(lambda self: self.request['id'])
+
+    def getEvolvers(self):
+        id = self.id
+        manager = zapi.getUtility(ISchemaManager, id)
+
+        evolvers = []
+
+        for gen in range(manager.minimum_generation, manager.generation):
+
+            info = manager.getInfo(gen+1)
+            if info is None:
+                info = ''
+            else:
+                renderer = ReStructuredTextToHTMLRenderer(info, self.request)
+                info = renderer.render()
+                
+            evolvers.append({'from': gen, 'to': gen+1, 'info': info})
+
+        return evolvers

Modified: Zope3/trunk/src/zope/app/generations/browser/managers.pt
===================================================================
--- Zope3/trunk/src/zope/app/generations/browser/managers.pt	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/browser/managers.pt	2004-12-09 17:52:40 UTC (rev 28597)
@@ -36,7 +36,12 @@
     <th i18n:translate="">Evolve?</th>
 </tr>
 <tr tal:repeat="app view/applications">
-    <td tal:content="app/id">foo.bar</td>
+    <td>
+      <a href=""
+         tal:attributes=
+             "href string:generations_managerdetails.html?id=${app/id}"
+         tal:content="app/id">foo.bar</a>
+    </td>
     <td tal:content="app/min">1</td>
     <td tal:content="app/max">10</td>
     <td tal:content="app/generation">2</td>

Modified: Zope3/trunk/src/zope/app/generations/browser/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/browser/tests.py	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/browser/tests.py	2004-12-09 17:52:40 UTC (rev 28597)
@@ -22,6 +22,7 @@
 def test_suite():
     return unittest.TestSuite((
         DocTestSuite('zope.app.generations.browser.managers'),
+        DocTestSuite('zope.app.generations.browser.managerdetails'),
         ))
 
 if __name__ == '__main__':

Modified: Zope3/trunk/src/zope/app/generations/demo/evolve1.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/demo/evolve1.py	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/demo/evolve1.py	2004-12-09 17:52:40 UTC (rev 28597)
@@ -22,4 +22,5 @@
 import zope.app.generations.demo
 
 def evolve(context):
+    """Evolver 1"""
     zope.app.generations.demo.evolve(context, generation)

Modified: Zope3/trunk/src/zope/app/generations/demo/evolve2.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/demo/evolve2.py	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/demo/evolve2.py	2004-12-09 17:52:40 UTC (rev 28597)
@@ -22,4 +22,5 @@
 import zope.app.generations.demo
 
 def evolve(context):
+    """Evolver 2"""
     zope.app.generations.demo.evolve(context, generation)

Modified: Zope3/trunk/src/zope/app/generations/generations.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/generations.py	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/generations.py	2004-12-09 17:52:40 UTC (rev 28597)
@@ -64,6 +64,17 @@
          >>> conn.root()[key]
          (2, 3)
 
+       You can get the information for each evolver by specifying the
+       destination generation of the evolver as argument to the `getInfo()`
+       method:
+
+         >>> manager.getInfo(1)
+         'Evolver 1'
+         >>> manager.getInfo(2)
+         'Evolver 2'
+         >>> manager.getInfo(3) is None
+         True
+
        We'd better clean up:
 
          >>> context.connection.close()
@@ -100,6 +111,15 @@
 
         evolver.evolve(context)
 
+    def getInfo(self, generation):
+        """Get the information from the evolver function's doc string."""
+        evolver = __import__(
+            "%s.evolve%d" % (self.package_name, generation),
+            {}, {}, ['*'])
+        return evolver.evolve.__doc__
+        
+        
+
 class Context(object):
     pass
 

Modified: Zope3/trunk/src/zope/app/generations/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/interfaces.py	2004-12-09 16:40:03 UTC (rev 28596)
+++ Zope3/trunk/src/zope/app/generations/interfaces.py	2004-12-09 17:52:40 UTC (rev 28597)
@@ -59,3 +59,10 @@
         a connection to make it possible to provide additional
         information later, if it becomes necessary.
         """
+
+    def getInfo(generation):
+        """Return an information string about the evolution that is used to
+        upgrade to the specified generation.
+
+        If no information is available, `None` should be returned.
+        """



More information about the Zope3-Checkins mailing list