version 1.79, 2006/03/28 19:54:41
|
version 1.80, 2006/04/20 14:08:35
|
Line 82 class ZSQLExtendFolder(Folder,Persistent
|
Line 82 class ZSQLExtendFolder(Folder,Persistent
|
|
|
|
|
|
|
def importXMLFile(self,table,data,identify=None,RESPONSE=None): |
def importXMLFile(self,table,data=None,identify=None,filename=None,RESPONSE=None): |
#TODO: finish importXMLFile |
#TODO: finish importXMLFile |
''' |
''' |
Import XML file into the table |
Import XML file into the table |
Line 92 class ZSQLExtendFolder(Folder,Persistent
|
Line 92 class ZSQLExtendFolder(Folder,Persistent
|
@param identify: (optional) field res. tag which identifies a entry uniquely for updating purposes. |
@param identify: (optional) field res. tag which identifies a entry uniquely for updating purposes. |
@param RESPONSE: (optional) |
@param RESPONSE: (optional) |
''' |
''' |
from xml.dom.pulldom import parseString |
from xml.dom.pulldom import parseString,parse |
|
|
|
|
|
zLOG.LOG("import xml",zLOG.INFO,"called") |
#fh=file("/tmp/fmpxml.xml") |
#fh=file("/tmp/fmpxml.xml") |
import bz2 |
import bz2 |
import base64 |
import base64 |
|
|
ret="" |
ret="" |
|
if data: |
data=bz2.decompress(base64.decodestring(data)) |
data=bz2.decompress(base64.decodestring(data)) |
#data=fh.read() |
|
|
|
|
zLOG.LOG("import xml",zLOG.INFO,"received file") |
doc=parseString(data) |
doc=parseString(data) |
|
zLOG.LOG("import xml",zLOG.INFO,"parsed file") |
|
|
|
elif filename: |
|
fh=file(filename) |
|
doc=parse(fh) |
|
zLOG.LOG("import xml",zLOG.INFO,"parsed file") |
while 1: |
while 1: |
node=doc.getEvent() |
node=doc.getEvent() |
|
|
Line 124 class ZSQLExtendFolder(Folder,Persistent
|
Line 131 class ZSQLExtendFolder(Folder,Persistent
|
field=dataSet[nr] |
field=dataSet[nr] |
|
|
searchStr="""select %s from %s where %s = '%s'"""%(identify,table,identify,field) |
searchStr="""select %s from %s where %s = '%s'"""%(identify,table,identify,field) |
|
zLOG.LOG("import xml",zLOG.INFO,searchStr) |
search=self.ZSQLSimpleSearch(searchStr) |
search=self.ZSQLSimpleSearch(searchStr) |
if search: |
if search: |
update=True |
update=True |
Line 137 class ZSQLExtendFolder(Folder,Persistent
|
Line 145 class ZSQLExtendFolder(Folder,Persistent
|
field=dataSet[nr] |
field=dataSet[nr] |
|
|
queryStr="""UPDATE %s SET %s WHERE %s = '%s' """%(table,setStr,identify,field) |
queryStr="""UPDATE %s SET %s WHERE %s = '%s' """%(table,setStr,identify,field) |
|
zLOG.LOG("update xml",zLOG.INFO,queryStr) |
self.ZSQLSimpleSearch(queryStr) |
self.ZSQLSimpleSearch(queryStr) |
ret+="ud: %s \n"%field |
ret+="ud: %s \n"%field |
else: |
else: |
Line 148 class ZSQLExtendFolder(Folder,Persistent
|
Line 157 class ZSQLExtendFolder(Folder,Persistent
|
|
|
queryStr="""INSERT INTO %s (%s) VALUES (%s)"""%(table,fields,values) |
queryStr="""INSERT INTO %s (%s) VALUES (%s)"""%(table,fields,values) |
self.ZSQLSimpleSearch(queryStr) |
self.ZSQLSimpleSearch(queryStr) |
|
zLOG.LOG("update xml",zLOG.INFO,queryStr) |
ret+="ad: %s \n"%field |
ret+="ad: %s \n"%field |
|
|
elif node[1].nodeName=="METADATA": |
elif node[1].nodeName=="METADATA": |
Line 159 class ZSQLExtendFolder(Folder,Persistent
|
Line 169 class ZSQLExtendFolder(Folder,Persistent
|
for name in names: |
for name in names: |
fieldNames.append(name.getAttribute('NAME')) |
fieldNames.append(name.getAttribute('NAME')) |
|
|
|
zLOG.LOG("update xml: fieldnames",zLOG.INFO,repr(fieldNames)) |
qstr="""select attname from pg_attribute, pg_class where attrelid = pg_class.oid and relname = '%s' """ |
qstr="""select attname from pg_attribute, pg_class where attrelid = pg_class.oid and relname = '%s' """ |
columns=[x.attname for x in self.ZSQLSimpleSearch(qstr%table)] |
columns=[x.attname for x in self.ZSQLSimpleSearch(qstr%table)] |
|
|
for fieldName in fieldNames: |
for fieldName in fieldNames: |
|
zLOG.LOG("update xml: fieldname",zLOG.INFO,repr(fieldName)) |
if fieldName not in columns: |
if fieldName not in columns: |
qstr="""alter table %s add %s %s""" |
qstr="""alter table %s add %s %s""" |
self.ZSQLSimpleSearch(qstr%(table,fieldName,'text')) |
self.ZSQLSimpleSearch(qstr%(table,fieldName,'text')) |
|
zLOG.LOG("update xml: fieldname add",zLOG.INFO,qstr%(table,fieldName,'text')) |
#fn=node[1].getAttribute("xml:id") |
#fn=node[1].getAttribute("xml:id") |
#nf=file("xtf/"+fn+".xtf",'w') |
#nf=file("xtf/"+fn+".xtf",'w') |
#nf.write("""<texts xmlns="http://emegir.info/xtf" xmlns:lem="http://emegir.info/lemma" >"""+node[1].toxml()+"</texts>") |
#nf.write("""<texts xmlns="http://emegir.info/xtf" xmlns:lem="http://emegir.info/lemma" >"""+node[1].toxml()+"</texts>") |