Support for initial container population file.
This commit is contained in:
parent
6763e08121
commit
8fedea421d
|
@ -30,6 +30,7 @@ import sys
|
|||
|
||||
import bsddb3.db as db
|
||||
import dbxml
|
||||
import libxml2
|
||||
|
||||
import expression.core.environs as environs
|
||||
import expression.core.dataholders as dataholders
|
||||
|
@ -80,7 +81,8 @@ def __init__():
|
|||
"""
|
||||
DbXmlDatabase._environment = db.DBEnv()
|
||||
DbXmlDatabase._environment.set_shm_key(35)
|
||||
dbHome = environs.getVar("configuration").getConfigAbsolutePath(
|
||||
configuration = environs.getVar("configuration")
|
||||
dbHome = configuration.getConfigAbsolutePath(
|
||||
"""yep:module[@name="%s"]/yep:environment/@dbHome""" % __init__.__module__,
|
||||
"/var/lib/expression/db"
|
||||
)
|
||||
|
@ -101,15 +103,36 @@ def __init__():
|
|||
DbXmlDatabase._containers = {}
|
||||
for name in environs.getVar("configuration").getConfigList("""yep:module[@name="%s"]/yep:container/@name""" % __init__.__module__):
|
||||
try:
|
||||
DbXmlDatabase._containers[name] = DbXmlDatabase._manager.openContainer(
|
||||
container = DbXmlDatabase._manager.openContainer(
|
||||
name, 0
|
||||
|db.DB_CREATE
|
||||
|dbxml.DBXML_CHKSUM
|
||||
)
|
||||
except RuntimeError:
|
||||
logs.error("Could not open container %s" % name)
|
||||
__del__()
|
||||
raise
|
||||
logs.debug("Container %s was not found. Creating it." % name)
|
||||
try:
|
||||
container = DbXmlDatabase._manager.createContainer(
|
||||
name, 0
|
||||
|dbxml.DBXML_CHKSUM
|
||||
)
|
||||
except RuntimeError:
|
||||
logs.error("Could not open nor create container %s." % name)
|
||||
__del__()
|
||||
raise
|
||||
else:
|
||||
populationPath = configuration.getConfigAbsolutePath(
|
||||
"""yep:module[@name="%s"]/yep:population/@path""" % __init__.__module__,
|
||||
)
|
||||
if populationPath:
|
||||
populationDoc = libxml2.readFile(populationPath, "utf-8", 0)
|
||||
setNode = populationDoc.getRootElement()
|
||||
updateContext = container.getManager().createUpdateContext()
|
||||
for documentNode in setNode.xpathEval("container[@name='%s']/*" % name):
|
||||
for node in documentNode.xpathEval("*"):
|
||||
doc = libxml2.newDoc("1.0")
|
||||
doc.setRootElement(node)
|
||||
container.putDocument(documentNode.prop("name"), doc.serialize(), updateContext)
|
||||
DbXmlDatabase._containers[name] = container
|
||||
|
||||
|
||||
def __del__():
|
||||
""" Closes containers and the database environment.
|
||||
|
|
Reference in New Issue