From 8fedea421d71098f1860f3922e238af8ca0aa07a Mon Sep 17 00:00:00 2001 From: sebd <> Date: Mon, 9 May 2005 15:51:33 +0000 Subject: [PATCH] Support for initial container population file. --- src/modules/dbxmldatabases.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/modules/dbxmldatabases.py b/src/modules/dbxmldatabases.py index 918d5bf..4dea765 100644 --- a/src/modules/dbxmldatabases.py +++ b/src/modules/dbxmldatabases.py @@ -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.