Importers: added db.prepare_import/db.commit_import to wrap imports
This commit is contained in:
parent
d8346a705f
commit
2147f72176
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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))
|
||||
|
@ -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!
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user