version 1.9, 2007/04/02 09:48:13
|
version 1.14, 2007/07/31 11:28:48
|
Line 98 class xml_handler:
|
Line 98 class xml_handler:
|
@param options.keep_fields: (optional) don't add fields to SQL database |
@param options.keep_fields: (optional) don't add fields to SQL database |
@param options.ascii_db: (optional) assume ascii encoding in db |
@param options.ascii_db: (optional) assume ascii encoding in db |
@param options.replace_table: (optional) delete and re-insert data |
@param options.replace_table: (optional) delete and re-insert data |
|
@param options.backup_table: (optional) create backup of old table (breaks indices) |
""" |
""" |
|
|
# set up parser |
# set up parser |
Line 133 class xml_handler:
|
Line 134 class xml_handler:
|
logging.debug("keep_fields: "+repr(self.keep_fields)) |
logging.debug("keep_fields: "+repr(self.keep_fields)) |
logging.debug("ascii_db: "+repr(self.ascii_db)) |
logging.debug("ascii_db: "+repr(self.ascii_db)) |
logging.debug("replace_table: "+repr(self.replace_table)) |
logging.debug("replace_table: "+repr(self.replace_table)) |
|
logging.debug("backup_table: "+repr(self.backup_table)) |
|
|
self.dbIDs = {} |
self.dbIDs = {} |
self.rowcnt = 0 |
self.rowcnt = 0 |
Line 229 class xml_handler:
|
Line 231 class xml_handler:
|
# check fields to update |
# check fields to update |
if self.update_fields is None: |
if self.update_fields is None: |
if self.keep_fields: |
if self.keep_fields: |
# update existing fields |
# update all existing fields from sql (when they are in the xml file) |
self.update_fields = self.sql_fields |
self.update_fields = {} |
|
for f in self.sql_fields.keys(): |
|
if self.sql_field_map.has_key(f): |
|
xf = self.sql_field_map[f] |
|
self.update_fields[f] = self.xml_field_map[xf] |
|
|
else: |
else: |
# update all fields |
# update all fields |
Line 450 class xml_handler:
|
Line 455 class xml_handler:
|
return |
return |
|
|
|
|
|
def importFMPXML(options): |
|
"""import FileMaker XML file (FMPXMLRESULT format) into the table. |
|
@param options: dict of options |
|
@param options.dsn: database connection string |
|
@param options.table: name of the table the xml shall be imported into |
|
@param options.filename: xmlfile filename |
|
@param options.update_fields: (optional) list of fields to update; default is to create all fields |
|
@param options.id_field: (optional) field which uniquely identifies an entry for updating purposes. |
|
@param options.sync_mode: (optional) really synchronise, i.e. delete entries not in XML file |
|
@param options.lc_names: (optional) lower case and clean up field names from XML |
|
@param options.keep_fields: (optional) don't add fields to SQL database |
|
@param options.ascii_db: (optional) assume ascii encoding in db |
|
@param options.replace_table: (optional) delete and re-insert data |
|
@param options.backup_table: (optional) create backup of old table (breaks indices) |
|
""" |
|
|
|
|
|
if getattr(options,'update_fields',None): |
|
uf = {} |
|
for f in options.update_fields.split(','): |
|
if f.find(':') > 0: |
|
(n,t) = f.split(':') |
|
else: |
|
n = f |
|
t = None |
|
uf[n] = TableColumn(n,t) |
|
|
|
options.update_fields = uf |
|
|
|
if getattr(options,'id_field',None) and getattr(options,'replace_table',None): |
|
logging.error("ABORT: sorry, you can't do both sync (id_field) and replace") |
|
sys.exit(1) |
|
|
|
parser = sax.make_parser() |
|
#The "consumer" is our own handler |
|
consumer = xml_handler(options) |
|
#Initialize Tenorsax with handler |
|
handler = saxtools.tenorsax(consumer) |
|
#Resulting tenorsax instance is the SAX handler |
|
parser.setContentHandler(handler) |
|
parser.setFeature(sax.handler.feature_namespaces, 1) |
|
parser.parse(options.filename) |
|
|
|
|
if __name__ == "__main__": |
if __name__ == "__main__": |
from optparse import OptionParser |
from optparse import OptionParser |
Line 512 if __name__ == "__main__":
|
Line 558 if __name__ == "__main__":
|
|
|
importFMPXML(options) |
importFMPXML(options) |
|
|
def importFMPXML(options): |
|
"""SAX handler to import FileMaker XML file (FMPXMLRESULT format) into the table. |
|
@param options: dict of options |
|
@param options.dsn: database connection string |
|
@param options.table: name of the table the xml shall be imported into |
|
@param options.filename: xmlfile filename |
|
@param options.update_fields: (optional) list of fields to update; default is to create all fields |
|
@param options.id_field: (optional) field which uniquely identifies an entry for updating purposes. |
|
@param options.sync_mode: (optional) really synchronise, i.e. delete entries not in XML file |
|
@param options.lc_names: (optional) lower case and clean up field names from XML |
|
@param options.keep_fields: (optional) don't add fields to SQL database |
|
@param options.ascii_db: (optional) assume ascii encoding in db |
|
@param options.replace_table: (optional) delete and re-insert data |
|
""" |
|
update_fields = None |
|
|
|
if getattr(options,'update_fields',None): |
|
uf = {} |
|
for f in options.update_fields.split(','): |
|
(n,t) = f.split(':') |
|
uf[n] = TableColumn(n,t) |
|
|
|
options.update_fields = uf |
|
|
|
if getattr(options,'id_field',None) and getattr(options,'replace_table',None): |
|
logging.error("ABORT: sorry, you can't do both sync (id_field) and replace") |
|
sys.exit(1) |
|
|
|
parser = sax.make_parser() |
|
#The "consumer" is our own handler |
|
consumer = xml_handler(options) |
|
#Initialize Tenorsax with handler |
|
handler = saxtools.tenorsax(consumer) |
|
#Resulting tenorsax instance is the SAX handler |
|
parser.setContentHandler(handler) |
|
parser.setFeature(sax.handler.feature_namespaces, 1) |
|
parser.parse(options.filename) |
|
|
|
|
|
|
|