[Zope3-checkins]
SVN: Zope3/trunk/src/zope/app/applicationcontrol/browser/
Added support for multiple databases in ZODB Control View.
Jodok Batlogg
jodok.batlogg at lovelysystems.com
Wed Jan 31 06:29:01 EST 2007
Log message for revision 72272:
Added support for multiple databases in ZODB Control View.
Changed:
A Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/ftesting.zcml
U Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py
A Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/zodb.txt
U Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.pt
U Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.py
-=-
Added: Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/ftesting.zcml
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/ftesting.zcml 2007-01-31 08:35:25 UTC (rev 72271)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/ftesting.zcml 2007-01-31 11:28:58 UTC (rev 72272)
@@ -0,0 +1,56 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ xmlns:meta="http://namespaces.zope.org/meta"
+ i18n_domain="zope">
+
+ <include package="zope.app.zcmlfiles" />
+ <include package="zope.app.securitypolicy" file="meta.zcml" />
+ <include package="zope.app.server" />
+ <include package="zope.app.authentication" />
+
+ <securityPolicy
+ component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+ <include package="zope.app.securitypolicy" />
+
+ <role id="zope.Anonymous" title="Everybody"
+ description="All users have this role implicitly" />
+
+ <role id="zope.Manager" title="Site Manager" />
+
+
+ <principal
+ id="zope.manager"
+ title="Administrator"
+ login="mgr"
+ password="mgrpw" />
+ <grant
+ role="zope.Manager"
+ principal="zope.manager"
+ />
+
+ <unauthenticatedPrincipal
+ id="zope.anybody"
+ title="Unauthenticated User" />
+
+ <unauthenticatedGroup
+ id="zope.Anybody"
+ title="Unauthenticated Users"
+ />
+
+ <authenticatedGroup
+ id="zope.Authenticated"
+ title="Authenticated Users"
+ />
+
+ <everybodyGroup
+ id="zope.Everybody"
+ title="All Users"
+ />
+
+ <grant permission="zope.View"
+ role="zope.Anonymous" />
+
+ <grantAll role="zope.Manager" />
+
+</configure>
\ No newline at end of file
Property changes on: Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/ftesting.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py 2007-01-31 08:35:25 UTC (rev 72271)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py 2007-01-31 11:28:58 UTC (rev 72272)
@@ -16,25 +16,39 @@
$Id$
"""
import unittest
+import ZODB.tests.util
+from ZODB.interfaces import IDatabase
+from zope.app.testing import functional
+from zope import component
-from zope.app.testing.functional import BrowserTestCase
+functional.defineLayer('TestLayer', 'ftesting.zcml')
-class ZODBControlTest(BrowserTestCase):
+def setUp(test):
+ test.databases = test.globs['getRootFolder']()._p_jar.db().databases
+ db2 = ZODB.tests.util.DB(databases=test.databases, database_name='2')
- def testZODBControlOverview(self):
- response = self.publish('/++etc++process/@@ZODBControl.html',
- basic='globalmgr:globalmgrpw',
- form={'days': u'3'})
- body = response.getBody()
- self.assert_('value="3"' in body)
- self.assert_('>Demo Storage</' in body)
- self.assert_('>1 KB</' in body)
+ for name, db in test.databases.items():
+ component.provideUtility(db, IDatabase, name=name)
+
+def tearDown(test):
+ for db in test.databases.values():
+ db.close()
+
+
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(ZODBControlTest))
+ suites = (
+ functional.FunctionalDocFileSuite('zodb.txt',
+ setUp=setUp, tearDown=tearDown,
+ ),
+ )
+ for s in suites:
+ s.layer=TestLayer
+ suite.addTest(s)
return suite
+
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
Added: Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/zodb.txt
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/zodb.txt 2007-01-31 08:35:25 UTC (rev 72271)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/zodb.txt 2007-01-31 11:28:58 UTC (rev 72272)
@@ -0,0 +1,28 @@
+=================
+ZODB Control View
+=================
+
+We provide default views which are relevant for administering mount points.
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.addHeader('Authorization','Basic mgr:mgrpw')
+ >>> browser.handleErrors = False
+
+ >>> browser.open('http://localhost/++etc++process/@@ZODBControl.html')
+
+All registered databases are displayed. Each database can be packed by
+selecting the according checkbox. Let us select the second database now:
+
+ >>> browser.getControl(name='dbs:list').value=['2']
+
+Now we define to pack the database back to 7 days:
+
+ >>> browser.getControl(name='days').value='7'
+
+Finally let's submit the form and start packing the database:
+
+ >>> browser.getControl(name='PACK').click()
+
+ >>> 'ZODB "2" successfully packed.' in browser.contents
+ True
\ No newline at end of file
Property changes on: Zope3/trunk/src/zope/app/applicationcontrol/browser/ftests/zodb.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.pt
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.pt 2007-01-31 08:35:25 UTC (rev 72271)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.pt 2007-01-31 11:28:58 UTC (rev 72272)
@@ -4,43 +4,54 @@
<title i18n:translate="">ZODB Controller</title>
</head>
<body>
- <div metal:fill-slot="body">
-
- <div class="row" tal:define="status view/pack"
- tal:condition="status">
+ <div id="message" metal:fill-slot="message">
+ <div class="row" tal:repeat="status view/update">
<div class="field" tal:content="status" i18n:translate=""/>
</div>
-
+ </div>
+ <div metal:fill-slot="body">
+ <form action="." method="post" tal:attributes="action request/URL">
<div class="row">
- <div class="label"
- i18n:translate="">Name of database</div>
- <div class="field" tal:content="view/getName">My Database</div>
- </div>
+ <table border="1">
+ <tr>
+ <th i18n:translate="">Pack</th>
+ <th i18n:translate="">Utility Name</th>
+ <th i18n:translate="">Database Name</th>
+ <th i18n:translate="">Size</th>
+ </tr>
+ <tr tal:repeat="db view/databases">
+ <td>
+ <input type="checkbox" name="dbs:list"
+ tal:attributes="value db/utilName"/>
+ </td>
+ <td>
+ <span tal:replace="db/utilName"/>
+ </td>
- <div class="row">
- <div class="label"
- i18n:translate="">Size of database</div>
- <div class="field" tal:content="view/getSize"
- i18n:translate="">1.1 MB</div>
- </div>
+ <td>
+ <span tal:replace="db/dbName"/>
+ </td>
+ <td>
+ <span tal:replace="db/size"/>
+ </td>
+ </tr>
+ </table>
- <form action="." method="post" tal:attributes="action request/URL">
<div class="row">
- <div class="label" i18n:translate="">Keep up to</div>
- <div class="field">
+ <span class="label" i18n:translate="">Keep up to</span>
+ <span class="field">
<input type="text" size="4" name="days" value="0"
tal:attributes="value request/days|string:0" />
<span tal:omit-tag="" i18n:translate="">days</span>
- </div>
- </div>
- <div class="row">
+ </span>
<div class="controls">
<input type="submit" name="PACK" value="Pack"
i18n:attributes="value pack-button"/>
</div>
</div>
+
+ </div>
</form>
-
</div>
</body>
</html>
Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.py 2007-01-31 08:35:25 UTC (rev 72271)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/zodbcontrol.py 2007-01-31 11:28:58 UTC (rev 72272)
@@ -20,29 +20,53 @@
from ZODB.FileStorage.FileStorage import FileStorageError
from zope.app.i18n import ZopeMessageFactory as _
from zope.size import byteDisplay
+from ZODB.interfaces import IDatabase
+from zope import component
-
class ZODBControlView(object):
- def getName(self):
- """Get the database name."""
- return self.request.publication.db.getName()
-
- def getSize(self):
+ status = None
+
+ @property
+ def databases(self):
+ res = []
+ for name, db in component.getUtilitiesFor(
+ IDatabase):
+ d = dict(
+ dbName = db.getName(),
+ utilName = str(name),
+ size = self._getSize(db),
+ )
+ res.append(d)
+ return res
+
+ def _getSize(self, db):
"""Get the database size in a human readable format."""
- size = self.request.publication.db.getSize()
+ size = db.getSize()
if not isinstance(size, (int, long, float)):
return str(size)
return byteDisplay(size)
- def pack(self):
- """Do the packing!"""
- days = int(self.request.form.get('days', 0))
- status = ''
- if 'PACK' in self.request:
+ def update(self):
+ if self.status is not None:
+ return self.status
+ status = []
+ if 'PACK' in self.request.form:
+ dbs = self.request.form.get('dbs', [])
try:
- self.request.publication.db.pack(days=days)
- status = _('ZODB successfully packed.')
- except FileStorageError, err:
- status = _(err)
- return status
+ days = int(self.request.form.get('days','').strip() or 0)
+ except ValueError:
+ status.append(_('Error: Invalid Number'))
+ self.status = status
+ return self.status
+ for dbName in dbs:
+ db = component.getUtility(IDatabase, name=dbName)
+ try:
+ db.pack(days=days)
+ status.append(_('ZODB "${name}" successfully packed.',
+ mapping=dict(name=str(dbName))))
+ except FileStorageError, err:
+ status.append(_('ERROR packing ZODB "${name}": ${err}',
+ mapping=dict(name=str(dbName), err=err)))
+ self.status = status
+ return self.status
More information about the Zope3-Checkins
mailing list