Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Support multiple database through a ZConfig file. You can still do the
Browse files Browse the repository at this point in the history
file_storage shortcut if you don't want a separate file and a Data.fs is
enough for you.
  • Loading branch information
philikon committed Mar 29, 2007
1 parent e592039 commit f848a9b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
30 changes: 27 additions & 3 deletions zope/paste/factory.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions zope/paste/schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<schema>
<import package="ZODB" />
<multisection type="ZODB.database" name="*" required="yes"
attribute="databases" />
</schema>

0 comments on commit f848a9b

Please sign in to comment.