version 1.8, 2007/03/29 18:31:32
|
version 1.9, 2007/04/02 09:48:13
|
Line 85 class TableColumn:
|
Line 85 class TableColumn:
|
|
|
|
|
class xml_handler: |
class xml_handler: |
|
|
def __init__(self,options): |
def __init__(self,options): |
''' |
"""SAX handler to import FileMaker XML file (FMPXMLRESULT format) into the table. |
SAX handler to import FileMaker XML file (FMPXMLRESULT format) into the table. |
|
@param options: dict of options |
@param options: dict of options |
@param options.dsn: database connection string |
@param options.dsn: database connection string |
@param options.table: name of the table the xml shall be imported into |
@param options.table: name of the table the xml shall be imported into |
Line 100 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 |
''' |
""" |
|
|
# set up parser |
# set up parser |
self.event = None |
self.event = None |
self.top_dispatcher = { |
self.top_dispatcher = { |
Line 115 class xml_handler:
|
Line 114 class xml_handler:
|
self.db = self.dbCon.cursor() |
self.db = self.dbCon.cursor() |
assert self.db, "AIIEE no db cursor for %s!!"%options.dsn |
assert self.db, "AIIEE no db cursor for %s!!"%options.dsn |
|
|
self.table = options.table |
self.table = getattr(options,"table",None) |
self.update_fields = options.update_fields |
self.update_fields = getattr(options,"update_fields",None) |
self.id_field = options.id_field |
self.id_field = getattr(options,"id_field",None) |
self.sync_mode = options.sync_mode |
self.sync_mode = getattr(options,"sync_mode",None) |
self.lc_names = options.lc_names |
self.lc_names = getattr(options,"lc_names",None) |
self.keep_fields = options.keep_fields |
self.keep_fields = getattr(options,"keep_fields",None) |
self.ascii_db = options.ascii_db |
self.ascii_db = getattr(options,"ascii_db",None) |
self.replace_table = options.replace_table |
self.replace_table = getattr(options,"replace_table",None) |
self.backup_table = options.backup_table |
self.backup_table = getattr(options,"backup_table",None) |
|
|
logging.debug("dsn: "+repr(options.dsn)) |
logging.debug("dsn: "+repr(getattr(options,"dsn",None))) |
logging.debug("table: "+repr(self.table)) |
logging.debug("table: "+repr(self.table)) |
logging.debug("update_fields: "+repr(self.update_fields)) |
logging.debug("update_fields: "+repr(self.update_fields)) |
logging.debug("id_field: "+repr(self.id_field)) |
logging.debug("id_field: "+repr(self.id_field)) |
Line 233 class xml_handler:
|
Line 232 class xml_handler:
|
# update existing fields |
# update existing fields |
self.update_fields = self.sql_fields |
self.update_fields = self.sql_fields |
|
|
|
|
else: |
else: |
# update all fields |
# update all fields |
if self.lc_names: |
if self.lc_names: |
Line 453 class xml_handler:
|
Line 453 class xml_handler:
|
|
|
|
|
|
|
## |
if __name__ == "__main__": |
## public static int main() |
|
## |
|
|
|
from optparse import OptionParser |
from optparse import OptionParser |
|
|
opars = OptionParser() |
opars = OptionParser() |
Line 513 logging.basicConfig(level=loglevel,
|
Line 510 logging.basicConfig(level=loglevel,
|
format='%(asctime)s %(levelname)s %(message)s', |
format='%(asctime)s %(levelname)s %(message)s', |
datefmt='%H:%M:%S') |
datefmt='%H:%M:%S') |
|
|
|
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 |
update_fields = None |
|
|
if options.update_fields: |
if getattr(options,'update_fields',None): |
uf = {} |
uf = {} |
for f in options.update_fields.split(','): |
for f in options.update_fields.split(','): |
(n,t) = f.split(':') |
(n,t) = f.split(':') |
Line 523 if options.update_fields:
|
Line 536 if options.update_fields:
|
|
|
options.update_fields = uf |
options.update_fields = uf |
|
|
if options.id_field and options.replace_table: |
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") |
logging.error("ABORT: sorry, you can't do both sync (id_field) and replace") |
sys.exit(1) |
sys.exit(1) |
|
|
Line 538 parser.setFeature(sax.handler.feature_na
|
Line 551 parser.setFeature(sax.handler.feature_na
|
parser.parse(options.filename) |
parser.parse(options.filename) |
|
|
|
|
print "DONE!" |
|