This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |