[Zope3-checkins] SVN: Zope3/trunk/ Implemented new rdb:gadflyRoot directive that allows us to change the

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Jul 8 19:21:24 EDT 2004


Log message for revision 26273:
Implemented new rdb:gadflyRoot directive that allows us to change the 
root directory for gadfly databases as requested by an XXX that is now 
gone.



-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/doc/CHANGES.txt	2004-07-08 23:21:24 UTC (rev 26273)
@@ -10,6 +10,8 @@
 
     New features
 
+      - Implemented rdb:gadflyRoot directive.    
+
       - Schemas are now copied before they are appended to content type or
         instance. This should probably become a policy later.
 

Added: Zope3/trunk/src/zope/app/rdb/gadfly-meta.zcml
===================================================================
--- Zope3/trunk/src/zope/app/rdb/gadfly-meta.zcml	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/src/zope/app/rdb/gadfly-meta.zcml	2004-07-08 23:21:24 UTC (rev 26273)
@@ -0,0 +1,11 @@
+<configure 
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directive 
+      namespace="http://namespaces.zope.org/rdb"
+      name="gadflyRoot" 
+      schema=".gadflymeta.IGadflyRoot"
+      handler=".gadflymeta.gadflyRootHandler" />
+
+</configure>

Modified: Zope3/trunk/src/zope/app/rdb/gadflyda.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/gadflyda.py	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/src/zope/app/rdb/gadflyda.py	2004-07-08 23:21:24 UTC (rev 26273)
@@ -30,12 +30,6 @@
     # The registerable object needs to have a container
     __name__ = __parent__ = None 
     
-    def _getGadflyRoot(self):
-        # XXX: Need to write a configuration directive for setting this up
-        # At the moment gadfly root is 'gadfly' under the instance home (which
-        # is assumed to be the current directory ATM).
-        return 'gadfly'
-
     def _connection_factory(self):
         """Create a Gadfly DBI connection based on the DSN.
 
@@ -51,7 +45,7 @@
                 )
 
         connection = conn_info['dbname']
-        dir = os.path.join(self._getGadflyRoot(),
+        dir = os.path.join(getGadflyRoot(),
                            conn_info['parameters'].get('dir', connection))
 
         if not os.path.isdir(dir):
@@ -64,3 +58,13 @@
             db = gadfly.gadfly(connection, dir)
 
         return db
+
+_gadflyRoot = 'gadfly'
+
+def setGadflyRoot(path='gadfly'):
+    global _gadflyRoot
+    _gadflyRoot = path
+
+def getGadflyRoot():
+    global _gadflyRoot
+    return _gadflyRoot

Added: Zope3/trunk/src/zope/app/rdb/gadflymeta.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/gadflymeta.py	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/src/zope/app/rdb/gadflymeta.py	2004-07-08 23:21:24 UTC (rev 26273)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""'gadflyRoot' Directive Handler
+
+$Id: metaconfigure.py 25177 2004-06-02 13:17:31Z jim $
+"""
+from zope.configuration.fields import Path
+from zope.interface import Interface
+
+from zope.app import zapi
+from zope.app.rdb.interfaces import IZopeDatabaseAdapter
+from zope.app.rdb.gadflyda import setGadflyRoot 
+
+class IGadflyRoot(Interface):
+    """This directive creates a globale connection to an RDBMS."""
+
+    path = Path(
+        title=u"Path of Gadfly Root",
+        description=u"Specifies the path of the gadfly root relative to the"
+                    u"packge.",
+        required=True)
+
+
+def gadflyRootHandler(_context, path):
+    _context.action(
+            discriminator = ('gadflyRoot',),
+            callable = setGadflyRoot,
+            args = (path,) )

Modified: Zope3/trunk/src/zope/app/rdb/meta.zcml
===================================================================
--- Zope3/trunk/src/zope/app/rdb/meta.zcml	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/src/zope/app/rdb/meta.zcml	2004-07-08 23:21:24 UTC (rev 26273)
@@ -8,4 +8,6 @@
       schema=".metadirectives.IProvideConnectionDirective"
       handler=".metaconfigure.connectionhandler" />
 
+  <include file="gadfly-meta.zcml" />
+
 </configure>

Added: Zope3/trunk/src/zope/app/rdb/tests/gadflyroot.zcml
===================================================================
--- Zope3/trunk/src/zope/app/rdb/tests/gadflyroot.zcml	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/src/zope/app/rdb/tests/gadflyroot.zcml	2004-07-08 23:21:24 UTC (rev 26273)
@@ -0,0 +1,7 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:rdb="http://namespaces.zope.org/rdb">
+
+  <include package="zope.app.rdb" file="gadfly-meta.zcml"/>
+  <rdb:gadflyRoot path="./test/dir" />
+ 
+</configure>

Modified: Zope3/trunk/src/zope/app/rdb/tests/test_gadflyadapter.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/tests/test_gadflyadapter.py	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/src/zope/app/rdb/tests/test_gadflyadapter.py	2004-07-08 23:21:24 UTC (rev 26273)
@@ -15,12 +15,12 @@
 
 $Id$
 """
-
 import os
 import tempfile
 from unittest import TestCase, TestSuite, main, makeSuite
 
 from zope.app.rdb import DatabaseAdapterError
+from zope.app.rdb.gadflyda import GadflyAdapter, setGadflyRoot
 
 class GadflyTestBase(TestCase):
 
@@ -32,17 +32,17 @@
         TestCase.tearDown(self)
         if self.tempdir:
             os.rmdir(self.tempdir)
+        setGadflyRoot()
 
     def getGadflyRoot(self):
         # note that self is GadflyTestBase here
         if not self.tempdir:
             self.tempdir = tempfile.mkdtemp('gadfly')
+        setGadflyRoot(self.tempdir)
         return self.tempdir
 
     def _create(self, *args):
-        from zope.app.rdb.gadflyda import GadflyAdapter
         obj = GadflyAdapter(*args)
-        obj._getGadflyRoot = self.getGadflyRoot
         return obj
 
 
@@ -89,14 +89,32 @@
         try: os.unlink(os.path.join(dir, "test", "demo.gfd"))
         except: pass
         os.rmdir(os.path.join(dir, "test"))
-        try: os.unlink(os.path.join(dir, "regular"))
-        except: pass
+        try:
+            os.unlink(os.path.join(dir, "regular"))
+        except:
+            pass
         GadflyTestBase.tearDown(self)
 
 
 class TestGadflyAdapterDefault(GadflyTestBase):
     """Test with pre-existing databases"""
 
+    def setUp(self):
+        # Create a directory for the database.
+        GadflyTestBase.setUp(self)
+        dir = self.getGadflyRoot()
+        os.mkdir(os.path.join(dir, "demo"))
+
+    def tearDown(self):
+        # Remove the files and directories created.
+        dir = self.getGadflyRoot()
+        try:
+            os.unlink(os.path.join(dir, "demo", "demo.gfd"))
+        except:
+            pass
+        os.rmdir(os.path.join(dir, "demo"))
+        GadflyTestBase.tearDown(self)
+
     def test__connection_factory_create(self):
         # Should create a database if the directory is empty.
         a = self._create("dbi://demo")
@@ -113,21 +131,7 @@
         conn = a._connection_factory()
         conn.rollback()         # is it really a connection?
 
-    def setUp(self):
-        # Create a directory for the database.
-        GadflyTestBase.setUp(self)
-        dir = self.getGadflyRoot()
-        os.mkdir(os.path.join(dir, "demo"))
 
-    def tearDown(self):
-        # Remove the files and directories created.
-        dir = self.getGadflyRoot()
-        try: os.unlink(os.path.join(dir, "demo", "demo.gfd"))
-        except: pass
-        os.rmdir(os.path.join(dir, "demo"))
-        GadflyTestBase.tearDown(self)
-
-
 def test_suite():
     return TestSuite((
         makeSuite(TestGadflyAdapter),

Added: Zope3/trunk/src/zope/app/rdb/tests/test_gadflyrootdirective.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/tests/test_gadflyrootdirective.py	2004-07-08 23:20:00 UTC (rev 26272)
+++ Zope3/trunk/src/zope/app/rdb/tests/test_gadflyrootdirective.py	2004-07-08 23:21:24 UTC (rev 26273)
@@ -0,0 +1,40 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""Test 'rdb' ZCML Namespace Directives
+
+$Id: test_directives.py 25177 2004-06-02 13:17:31Z jim $
+"""
+import unittest
+
+from zope.configuration import xmlconfig
+
+import zope.app.rdb.tests
+from zope.app.rdb.gadflyda import getGadflyRoot
+
+class DirectiveTest(unittest.TestCase):
+
+    def test_gadflyRoot(self):
+
+        self.assertEqual(getGadflyRoot(), 'gadfly')
+        self.context = xmlconfig.file("gadflyroot.zcml", zope.app.rdb.tests)
+        self.assert_('src/zope/app/rdb/tests/test/dir' in getGadflyRoot())
+
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(DirectiveTest),
+        ))
+
+if __name__ == '__main__':
+    unittest.main()



More information about the Zope3-Checkins mailing list