[Zope-Checkins] CVS: ZODB3/ZODB - config.py:1.11
Jeremy Hylton
jeremy@zope.com
Fri, 23 May 2003 17:31:40 -0400
Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv13137/ZODB
Modified Files:
config.py
Log Message:
Add methods for opening a storage from a configuration.
Useful for the interim case of ZODB 3.2 and Zope 2.6, where you want
to load from a config file in custom_zodb.py.
=== ZODB3/ZODB/config.py 1.10 => 1.11 ===
--- ZODB3/ZODB/config.py:1.10 Tue Jan 28 18:15:56 2003
+++ ZODB3/ZODB/config.py Fri May 23 17:31:40 2003
@@ -22,27 +22,50 @@
import ZODB
-schema_path = os.path.join(ZODB.__path__[0], "config.xml")
-_schema = None
+db_schema_path = os.path.join(ZODB.__path__[0], "config.xml")
+_db_schema = None
-def getSchema():
- global _schema
- if _schema is None:
- _schema = ZConfig.loadSchema(schema_path)
- return _schema
+s_schema_path = os.path.join(ZODB.__path__[0], "storage.xml")
+_s_schema = None
+
+def getDbSchema():
+ global _db_schema
+ if _db_schema is None:
+ _db_schema = ZConfig.loadSchema(db_schema_path)
+ return _db_schema
+
+def getStorageSchema():
+ global _s_schema
+ if _s_schema is None:
+ _s_schema = ZConfig.loadSchema(s_schema_path)
+ return _s_schema
def databaseFromString(s):
return databaseFromFile(StringIO.StringIO(s))
def databaseFromFile(f):
- config, handle = ZConfig.loadConfigFile(getSchema(), f)
+ config, handle = ZConfig.loadConfigFile(getDbSchema(), f)
return databaseFromConfig(config.database)
def databaseFromURL(url):
- config, handler = ZConfig.loadConfig(getSchema(), url)
+ config, handler = ZConfig.loadConfig(getDbSchema(), url)
return databaseFromConfig(config.database)
def databaseFromConfig(section):
+ return section.open()
+
+def storageFromString(s):
+ return storageFromFile(StringIO.StringIO(s))
+
+def storageFromFile(f):
+ config, handle = ZConfig.loadConfigFile(getStorageSchema(), f)
+ return storageFromConfig(config.storage)
+
+def storageFromURL(url):
+ config, handler = ZConfig.loadConfig(getStorageSchema(), url)
+ return storageFromConfig(config.storage)
+
+def storageFromConfig(section):
return section.open()