[Checkins] SVN: Sandbox/ulif/grokadmin/trunk/src/grokadmin/ Removal of normal and broken applications.

Uli Fouquet uli at gnufix.de
Sun Oct 7 19:14:19 EDT 2007


Log message for revision 80699:
  Removal of normal and broken applications.

Changed:
  U   Sandbox/ulif/grokadmin/trunk/src/grokadmin/README.txt
  U   Sandbox/ulif/grokadmin/trunk/src/grokadmin/app.py
  U   Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/apps.py
  A   Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/brokenobjs.py

-=-
Modified: Sandbox/ulif/grokadmin/trunk/src/grokadmin/README.txt
===================================================================
--- Sandbox/ulif/grokadmin/trunk/src/grokadmin/README.txt	2007-10-07 22:52:55 UTC (rev 80698)
+++ Sandbox/ulif/grokadmin/trunk/src/grokadmin/README.txt	2007-10-07 23:14:19 UTC (rev 80699)
@@ -2,6 +2,13 @@
 GrokAdmin: the Grok Administrator and Developer UI
 ==================================================
 
-GrokAdmin is a grok application, which provides tools to administer
+GrokAdmin is a grok application, which provides tools to administrate
 Grok applications and to improve development of it.
 
+Features:
+---------
+
+- add/remove usual grok applications.
+
+- remove broken applications.
+

Modified: Sandbox/ulif/grokadmin/trunk/src/grokadmin/app.py
===================================================================
--- Sandbox/ulif/grokadmin/trunk/src/grokadmin/app.py	2007-10-07 22:52:55 UTC (rev 80698)
+++ Sandbox/ulif/grokadmin/trunk/src/grokadmin/app.py	2007-10-07 23:14:19 UTC (rev 80699)
@@ -123,6 +123,47 @@
         self.redirect(self.url(self.context))
 
 
+class Delete(grok.View):
+    """Delete an application.
+    """
+    grok.require('grok.ManageApplications')
+
+    def render(self, items=None):
+        if items is None:
+            self.redirect(self.url(self.context))
+            return
+        msg = u''
+        app_folder = get_apps_folder(self.context)
+        if not isinstance(items, list):
+            items = [items]
+        for name in items:
+            try:
+                del app_folder[name]
+                msg = (u'%sApplication `%s` was successfully '
+                       u'deleted.\n' % (msg, name))
+            except AttributeError:
+                # Object is broken.. Try it the hard way...
+                # TODO: Try to repair before deleting.
+                obj = app_folder[name]
+                if not hasattr(app_folder, 'data'):
+                    msg = (
+                        u'%sCould not delete application `%s`: no '
+                        u'`data` attribute found.\n' % (msg, name))
+                    continue
+                if not isinstance(app_folder.data, OOBTree):
+                    msg = (
+                        u'%sCould not delete application `%s`: no '
+                        u'`data` is not a BTree.\n' % (msg, name))
+                    continue
+                app_folder.data.pop(name)
+                app_folder._p_changed = True
+                msg = (u'%sBroken application `%s` was successfully '
+                       u'deleted.\n' % (msg, name))
+
+        self.flash(msg)
+        self.redirect(self.url(self.context))
+
+
 def get_apps_folder(context):
     """Return a folder where apps can be added for a context.
 

Modified: Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/apps.py
===================================================================
--- Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/apps.py	2007-10-07 22:52:55 UTC (rev 80698)
+++ Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/apps.py	2007-10-07 23:14:19 UTC (rev 80699)
@@ -78,7 +78,7 @@
 
 We are able to delete installed mammoth-managers
 
-  >>> browser.open("http://localhost/applications")
+  >>> browser.open("http://localhost/admin/applications")
   >>> print browser.contents
   <html xmlns="http://www.w3.org/1999/xhtml">
   ...

Added: Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/brokenobjs.py
===================================================================
--- Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/brokenobjs.py	                        (rev 0)
+++ Sandbox/ulif/grokadmin/trunk/src/grokadmin/ftests/application/brokenobjs.py	2007-10-07 23:14:19 UTC (rev 80699)
@@ -0,0 +1,96 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""
+=========================
+Removal of broken objects
+=========================
+
+The admin-UI now supports detection and deletion of broken objects. It
+is still limited to IApplication objects in the root folder. Options
+to repair broken objects are also still missing.
+
+We first setup the environment:
+
+  >>> import grok
+  >>> grok.grok(__name__)
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+  >>> root = getRootFolder()
+
+Now we install an instance of ``GrokAdmin`` named `admin`::
+
+  >>> from grokadmin.app import GrokAdmin
+  >>> root['admin'] = GrokAdmin()
+  >>> list(root.keys())
+  [u'admin']
+
+If no broken applications are in the root, everything should look as
+usual:
+
+  >>> browser.open('http://localhost/admin/applications')
+  >>> 'Broken applications:' not in browser.contents
+  True
+
+Now we grok this module, to have a new application type available,
+which is intentionally broken:
+
+  >>> browser.open('http://localhost/admin/applications')
+  >>> 'PseudoBroken' in browser.contents
+  True
+
+We add an instance of that new type:
+
+  >>> subform = browser.getForm(name='PseudoBroken')
+  >>> subform
+  <zope.testbrowser.browser.Form object at 0x...>
+
+  >>> subform.getControl('Name your new app').value = 'mybrokenobj'
+  >>> subform.getControl('Create').click()
+
+and the broken object should show up in the applications list:
+
+ >>> print browser.contents
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ ...
+ ...Broken applications:...
+ ...
+ ...(broken type: ...brokenobjs.PseudoBroken)...
+ ...This application is broken!...
+ ...
+
+If we want to delete the broken object, we can do so:
+
+  >>> ctrl = browser.getControl(name='items')
+  >>> ctrl.getControl(value='mybrokenobj').selected = True
+  >>> browser.getControl('Delete Selected').click()
+  >>> print browser.contents
+  <html xmlns="http://www.w3.org/1999/xhtml">
+  ...
+  ...Application `mybrokenobj` was successfully deleted.
+  ...
+
+and the 'Broken applications' section won't show up anymore:
+
+  >>> 'Broken applications:' not in browser.contents
+  True
+
+
+"""
+import grok
+from ZODB.broken import Broken
+class PseudoBroken(grok.Application, grok.Container, Broken):
+    """A class intentionally broken.
+    """
+    pass



More information about the Checkins mailing list