[Checkins] SVN: zope.paste/trunk/zope/paste/ Support multiple database through a ZConfig file. You can still do the

Philipp von Weitershausen philikon at philikon.de
Thu Mar 29 18:49:30 EDT 2007


Log message for revision 73932:
  Support multiple database through a ZConfig file. You can still do the
  file_storage shortcut if you don't want a separate file and a Data.fs is
  enough for you.
  

Changed:
  U   zope.paste/trunk/zope/paste/factory.py
  A   zope.paste/trunk/zope/paste/schema.xml

-=-
Modified: zope.paste/trunk/zope/paste/factory.py
===================================================================
--- zope.paste/trunk/zope/paste/factory.py	2007-03-29 22:16:16 UTC (rev 73931)
+++ zope.paste/trunk/zope/paste/factory.py	2007-03-29 22:49:30 UTC (rev 73932)
@@ -1,12 +1,36 @@
+import os.path
+import ZConfig
+import zope.event
 import zope.app.appsetup
+from zope.app.appsetup.appsetup import multi_database
 from zope.app.wsgi import WSGIPublisherApplication
 
-def zope_app_factory(global_conf, site_definition, file_storage,
-                     devmode='no'):
+def zope_app_factory(global_conf, site_definition, file_storage=None,
+                     db_definition=None, devmode='no'):
+    # load ZCML (usually site.zcml)
     features = ()
     if devmode.lower() in ('yes', 'true', 'on'):
         features += ('devmode',)
     zope.app.appsetup.config(site_definition, features)
 
-    db = zope.app.appsetup.database(file_storage)
+    if file_storage is None and db_definition is None:
+        raise TypeError("You must either provide a 'file_storage' or a "
+                        "'db_definition' setting.")
+
+    if file_storage is not None and db_definition is not None:
+        raise TypeError("You may only provide a 'file_storage' or a "
+                        "'db_definition' setting, not both.")
+
+    # open database
+    if file_storage is not None:
+        db = zope.app.appsetup.database(file_storage)
+    else:
+        schema_xml = os.path.join(os.path.dirname(__file__), 'schema.xml')
+        schema = ZConfig.loadSchema(schema_xml)
+        cfgroot, cfghandlers = ZConfig.loadConfig(schema, db_definition)
+
+        result, databases = multi_database(cfgroot.databases)
+        db = result[0]
+        zope.event.notify(zope.app.appsetup.DatabaseOpened(db))
+
     return WSGIPublisherApplication(db)

Added: zope.paste/trunk/zope/paste/schema.xml
===================================================================
--- zope.paste/trunk/zope/paste/schema.xml	2007-03-29 22:16:16 UTC (rev 73931)
+++ zope.paste/trunk/zope/paste/schema.xml	2007-03-29 22:49:30 UTC (rev 73932)
@@ -0,0 +1,5 @@
+<schema>
+  <import package="ZODB" />
+  <multisection type="ZODB.database" name="*" required="yes"
+                attribute="databases" />
+</schema>
\ No newline at end of file


Property changes on: zope.paste/trunk/zope/paste/schema.xml
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list