version 1.31, 2010/05/10 15:50:32
|
version 1.33, 2011/06/23 09:14:53
|
Line 6 import logging
|
Line 6 import logging
|
import sys |
import sys |
import types |
import types |
import time |
import time |
|
import re |
|
|
from xml import sax |
from xml import sax |
from amara import saxtools |
from amara import saxtools |
Line 22 except:
|
Line 23 except:
|
|
|
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
|
|
version_string = "V0.6.5 ROC 10.5.2010" |
version_string = "V0.6.7 ROC 21.6.2011" |
|
|
def unicodify(text, withNone=False): |
def unicodify(text, withNone=False): |
"""decode str (utf-8 or latin-1 representation) into unicode object""" |
"""decode str (utf-8 or latin-1 representation) into unicode object""" |
Line 68 def sql_quote(v):
|
Line 69 def sql_quote(v):
|
v=string.join(string.split(v,dkey),quote_dict[dkey]) |
v=string.join(string.split(v,dkey),quote_dict[dkey]) |
return "'%s'"%v |
return "'%s'"%v |
|
|
|
def sqlName(s, lc=True, more=''): |
|
"""returns restricted ASCII-only version of string""" |
|
if s is None: |
|
return "" |
|
|
|
# remove ' |
|
s = s.replace("'","") |
|
# all else -> "_" |
|
s = re.sub('[^A-Za-z0-9_'+more+']','_',s) |
|
if lc: |
|
return s.lower() |
|
|
|
return s |
|
|
def SimpleSearch(curs,query, args=None, ascii=False): |
def SimpleSearch(curs,query, args=None, ascii=False): |
"""execute sql query and return data""" |
"""execute sql query and return data""" |
#logger.debug("executing: "+query) |
#logger.debug("executing: "+query) |
Line 351 class xml_handler:
|
Line 366 class xml_handler:
|
#Element closed. Wrap up |
#Element closed. Wrap up |
if self.lc_names: |
if self.lc_names: |
# clean name |
# clean name |
sqlname = name.replace(" ","_").lower() |
sqlname = sqlName(name) |
else: |
else: |
sqlname = name |
sqlname = name |
self.xml_field_names.append(name) |
self.xml_field_names.append(name) |
Line 389 class xml_handler:
|
Line 404 class xml_handler:
|
|
|
if self.sync_mode: |
if self.sync_mode: |
# delete unmatched entries in db |
# delete unmatched entries in db |
|
if self.rowcnt > 0: |
self.logger.info("deleting unmatched rows from db") |
self.logger.info("deleting unmatched rows from db") |
delQuery = "DELETE FROM %s WHERE \"%s\" = %%s"%(self.table,self.id_field) |
delQuery = "DELETE FROM %s WHERE \"%s\" = %%s"%(self.table,self.id_field) |
for id in self.dbIDs.keys(): |
for id in self.dbIDs.keys(): |
Line 402 class xml_handler:
|
Line 418 class xml_handler:
|
|
|
self.dbCon.commit() |
self.dbCon.commit() |
|
|
|
else: |
|
# safety in case we had an empty file |
|
self.logger.warning("no rows read! not deleting unmatched rows!") |
|
|
# reinstate backup tables |
# reinstate backup tables |
if self.backup_table and not self.id_field: |
if self.backup_table and not self.id_field: |
backup_name = "%s_%s"%(self.orig_table,time.strftime('%Y_%m_%d_%H_%M_%S')) |
backup_name = "%s_%s"%(self.orig_table,time.strftime('%Y_%m_%d_%H_%M_%S')) |