From 2147f721768feb4fe16d436cdd29042d7d39ddca Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 16 May 2015 00:16:33 -0400 Subject: [PATCH] Importers: added db.prepare_import/db.commit_import to wrap imports --- gramps/plugins/database/bsddb_support/write.py | 12 ++++++++++++ gramps/plugins/database/dictionarydb.py | 13 +++++++++++++ gramps/plugins/database/djangodb.py | 2 +- gramps/plugins/importer/importcsv.py | 2 ++ gramps/plugins/importer/importgedcom.py | 2 ++ gramps/plugins/importer/importgeneweb.py | 2 ++ gramps/plugins/importer/importgpkg.py | 2 ++ gramps/plugins/importer/importprogen.py | 2 ++ gramps/plugins/importer/importvcard.py | 2 ++ gramps/plugins/importer/importxml.py | 2 ++ gramps/webapp/reports.py | 4 ++-- 11 files changed, 42 insertions(+), 3 deletions(-) diff --git a/gramps/plugins/database/bsddb_support/write.py b/gramps/plugins/database/bsddb_support/write.py index cca39eae7..9630b3ce2 100644 --- a/gramps/plugins/database/bsddb_support/write.py +++ b/gramps/plugins/database/bsddb_support/write.py @@ -2470,6 +2470,18 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): _("Version"): bsddb_version, } + def prepare_import(self): + """ + Initialization before imports + """ + pass + + def commit_import(self): + """ + Post process after imports + """ + pass + def mk_backup_name(database, base): """ Return the backup name of the database table diff --git a/gramps/plugins/database/dictionarydb.py b/gramps/plugins/database/dictionarydb.py index 38ad398ac..44e3721fa 100644 --- a/gramps/plugins/database/dictionarydb.py +++ b/gramps/plugins/database/dictionarydb.py @@ -1810,3 +1810,16 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback): def rebuild_secondary(self, update): ## FIXME pass + + def prepare_import(self): + """ + Initialization before imports + """ + pass + + def commit_import(self): + """ + Post process after imports + """ + pass + diff --git a/gramps/plugins/database/djangodb.py b/gramps/plugins/database/djangodb.py index ca55eb0b1..f7fe47892 100644 --- a/gramps/plugins/database/djangodb.py +++ b/gramps/plugins/database/djangodb.py @@ -518,7 +518,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback): self.dji.add_tag_detail(obj.serialize()) self.use_import_cache = False self.import_cache = {} - self.dji.update_publics() + self.request_rebuild() def transaction_commit(self, txn): pass diff --git a/gramps/plugins/importer/importcsv.py b/gramps/plugins/importer/importcsv.py index 2b25a588f..c39362425 100644 --- a/gramps/plugins/importer/importcsv.py +++ b/gramps/plugins/importer/importcsv.py @@ -151,8 +151,10 @@ def importData(dbase, filename, user): parser = CSVParser(dbase, user, (config.get('preferences.tag-on-import-format') if config.get('preferences.tag-on-import') else None)) try: + dbase.prepare_import() with OpenFileOrStdin(filename, 'b') as filehandle: parser.parse(filehandle) + dbase.commit_import() except EnvironmentError as err: user.notify_error(_("%s could not be opened\n") % filename, str(err)) return diff --git a/gramps/plugins/importer/importgedcom.py b/gramps/plugins/importer/importgedcom.py index da257a764..72db2d29d 100644 --- a/gramps/plugins/importer/importgedcom.py +++ b/gramps/plugins/importer/importgedcom.py @@ -130,7 +130,9 @@ def importData(database, filename, user): try: read_only = database.readonly database.readonly = False + database.prepare_import() gedparse.parse_gedcom_file(False) + database.commit_import() database.readonly = read_only ifile.close() except IOError as msg: diff --git a/gramps/plugins/importer/importgeneweb.py b/gramps/plugins/importer/importgeneweb.py index 01707577a..b4505efd3 100644 --- a/gramps/plugins/importer/importgeneweb.py +++ b/gramps/plugins/importer/importgeneweb.py @@ -86,7 +86,9 @@ def importData(database, filename, user): return try: + database.prepare_import() status = g.parse_geneweb_file() + database.commit_import() except IOError as msg: errmsg = _("%s could not be opened\n") % filename user.notify_error(errmsg,str(msg)) diff --git a/gramps/plugins/importer/importgpkg.py b/gramps/plugins/importer/importgpkg.py index 3c7f1b4c7..2a164b09d 100644 --- a/gramps/plugins/importer/importgpkg.py +++ b/gramps/plugins/importer/importgpkg.py @@ -93,7 +93,9 @@ def impData(database, name, user): imp_db_name = os.path.join(tmpdir_path, XMLFILE) importer = importData + database.prepare_import() info = importer(database, imp_db_name, user) + database.commit_import() newmediapath = database.get_mediapath() #import of gpkg should not change media path as all media has new paths! diff --git a/gramps/plugins/importer/importprogen.py b/gramps/plugins/importer/importprogen.py index 584a3281e..202f56118 100644 --- a/gramps/plugins/importer/importprogen.py +++ b/gramps/plugins/importer/importprogen.py @@ -74,7 +74,9 @@ def _importData(database, filename, user): return try: + database.prepare_import() status = g.parse_progen_file() + database.commit_import() except ProgenError as msg: user.notify_error(_("Pro-Gen data error"), str(msg)) return diff --git a/gramps/plugins/importer/importvcard.py b/gramps/plugins/importer/importvcard.py index 15cf804e5..4d504931f 100644 --- a/gramps/plugins/importer/importvcard.py +++ b/gramps/plugins/importer/importvcard.py @@ -62,8 +62,10 @@ def importData(database, filename, user): """Function called by Gramps to import data on persons in VCard format.""" parser = VCardParser(database) try: + database.prepare_import() with OpenFileOrStdin(filename) as filehandle: parser.parse(filehandle) + database.commit_import() except EnvironmentError as msg: user.notify_error(_("%s could not be opened\n") % filename, str(msg)) return diff --git a/gramps/plugins/importer/importxml.py b/gramps/plugins/importer/importxml.py index 51525dbd6..21ce6a7a0 100644 --- a/gramps/plugins/importer/importxml.py +++ b/gramps/plugins/importer/importxml.py @@ -122,6 +122,7 @@ def importData(database, filename, user): line_cnt = 0 person_cnt = 0 + database.prepare_import() with ImportOpenFileContextManager(filename, user) as xml_file: if xml_file is None: return @@ -162,6 +163,7 @@ def importData(database, filename, user): "valid Gramps database.")) return + database.commit_import() database.readonly = read_only return info diff --git a/gramps/webapp/reports.py b/gramps/webapp/reports.py index c0c7f480e..35cc66356 100644 --- a/gramps/webapp/reports.py +++ b/gramps/webapp/reports.py @@ -85,9 +85,9 @@ def import_file(db, filename, user): print("ERROR:", name, exception) return False import_function = getattr(mod, pdata.import_function) - db.prepare_import() + #db.prepare_import() retval = import_function(db, filename, user) - db.commit_import() + #db.commit_import() return retval return False