Importers: added db.prepare_import/db.commit_import to wrap imports

This commit is contained in:
Doug Blank 2015-05-16 00:16:33 -04:00
parent b095c6b606
commit 576db27e9d
11 changed files with 42 additions and 3 deletions

View File

@ -2472,6 +2472,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

View File

@ -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

View File

@ -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

View File

@ -103,8 +103,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 open(filename, 'r') 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

View File

@ -131,7 +131,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:

View File

@ -87,7 +87,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))

View File

@ -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!

View File

@ -75,7 +75,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

View File

@ -63,8 +63,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

View File

@ -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

View File

@ -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