Fall back to expat if libxml2 is not present
This commit is contained in:
parent
6df078b8e2
commit
019eb0f96c
@ -25,15 +25,22 @@ def destroy():
|
|||||||
log.info(idindex + " deleted")
|
log.info(idindex + " deleted")
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
import libxml2
|
|
||||||
from planet import logger as log
|
from planet import logger as log
|
||||||
cache = config.cache_directory()
|
cache = config.cache_directory()
|
||||||
index=os.path.join(cache,'index')
|
index=os.path.join(cache,'index')
|
||||||
if not os.path.exists(index): os.makedirs(index)
|
if not os.path.exists(index): os.makedirs(index)
|
||||||
index = dbhash.open(filename(index, 'id'),'c')
|
index = dbhash.open(filename(index, 'id'),'c')
|
||||||
|
|
||||||
|
try:
|
||||||
|
import libxml2
|
||||||
|
except:
|
||||||
|
libxml2 = False
|
||||||
|
from xml.dom import minidom
|
||||||
|
|
||||||
for file in glob(cache+"/*"):
|
for file in glob(cache+"/*"):
|
||||||
if not os.path.isdir(file):
|
if os.path.isdir(file):
|
||||||
|
continue
|
||||||
|
elif libxml2:
|
||||||
try:
|
try:
|
||||||
doc = libxml2.parseFile(file)
|
doc = libxml2.parseFile(file)
|
||||||
ctxt = doc.xpathNewContext()
|
ctxt = doc.xpathNewContext()
|
||||||
@ -45,6 +52,19 @@ def create():
|
|||||||
doc.freeDoc()
|
doc.freeDoc()
|
||||||
except:
|
except:
|
||||||
log.error(file)
|
log.error(file)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
doc = minidom.parse(file)
|
||||||
|
doc.normalize()
|
||||||
|
ids = doc.getElementsByTagName('id')
|
||||||
|
entry = [e for e in ids if e.parentNode.nodeName == 'entry']
|
||||||
|
source = [e for e in ids if e.parentNode.nodeName == 'source']
|
||||||
|
if entry and source:
|
||||||
|
index[filename('',entry[0].childNodes[0].nodeValue)] = \
|
||||||
|
source[0].childNodes[0].nodeValue
|
||||||
|
doc.freeDoc()
|
||||||
|
except:
|
||||||
|
log.error(file)
|
||||||
|
|
||||||
log.info(str(len(index.keys())) + " entries indexed")
|
log.info(str(len(index.keys())) + " entries indexed")
|
||||||
index.close()
|
index.close()
|
||||||
|
@ -52,10 +52,7 @@ class idIndexTest(unittest.TestCase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
module = 'dbhash'
|
module = 'dbhash'
|
||||||
import dbhash
|
|
||||||
module = 'libxml2'
|
|
||||||
import libxml2
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warn(module + " is not available => can't test id index")
|
logger.warn("dbhash is not available => can't test id index")
|
||||||
for method in dir(idIndexTest):
|
for method in dir(idIndexTest):
|
||||||
if method.startswith('test_'): delattr(idIndexTest,method)
|
if method.startswith('test_'): delattr(idIndexTest,method)
|
||||||
|
Loading…
Reference in New Issue
Block a user