Fix ExportPkg so errors are not lost, and has progress bar for media (#957)

* Fix Export Assistant so error messages get correct parent window

* Fix ExportPkg so errors are not lost, and has progress bar for media

Fixes #11457
This commit is contained in:
Paul Culley 2020-01-09 11:36:38 -06:00 committed by GitHub
parent ddb29b1628
commit 9b0cf1b976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 33 deletions

View File

@ -586,11 +586,11 @@ class ExportAssistant(ManagedWindow, Gtk.Assistant):
ix = self.get_selected_format_index()
config.set('behavior.recent-export-type', ix)
export_function = self.map_exporters[ix].get_export_function()
success = export_function(self.dbstate.db,
filename,
User(error=ErrorDialog, parent=self.uistate.window,
callback=self.callback),
self.option_box_instance)
success = export_function(
self.dbstate.db, filename,
User(error=ErrorDialog, parent=self.window,
callback=self.callback),
self.option_box_instance)
except:
#an error not catched in the export_function itself
success = False

View File

@ -179,34 +179,35 @@ class PackageWriter:
#---------------------------------------------------------------
try:
archive = tarfile.open(self.filename,'w:gz')
except EnvironmentError as msg:
with tarfile.open(self.filename, 'w:gz') as archive:
# Write media files first, since the database may be modified
# during the process (i.e. when removing object)
handles = self.db.get_media_handles(sort_handles=True)
for indx, m_id in enumerate(handles):
self.user.callback(indx * 100 / len(handles))
mobject = self.db.get_media_from_handle(m_id)
filename = media_path_full(self.db, mobject.get_path())
archname = str(mobject.get_path())
if os.path.isfile(filename) and os.access(filename,
os.R_OK):
archive.add(filename, archname, filter=fix_mtime)
# Write XML now
with BytesIO() as g:
gfile = XmlWriter(self.db, self.user, 2)
gfile.write_handle(g)
tarinfo = tarfile.TarInfo('data.gramps')
tarinfo.size = len(g.getvalue())
tarinfo.mtime = time.time()
if not win():
tarinfo.uid = os.getuid()
tarinfo.gid = os.getgid()
g.seek(0)
archive.addfile(tarinfo, g)
return True
except (EnvironmentError, OSError) as msg:
log.warning(str(msg))
self.user.notify_error(_('Failure writing %s') % self.filename, str(msg))
return 0
# Write media files first, since the database may be modified
# during the process (i.e. when removing object)
for m_id in self.db.get_media_handles(sort_handles=True):
mobject = self.db.get_media_from_handle(m_id)
filename = media_path_full(self.db, mobject.get_path())
archname = str(mobject.get_path())
if os.path.isfile(filename) and os.access(filename, os.R_OK):
archive.add(filename, archname, filter=fix_mtime)
# Write XML now
g = BytesIO()
gfile = XmlWriter(self.db, self.user, 2)
gfile.write_handle(g)
tarinfo = tarfile.TarInfo('data.gramps')
tarinfo.size = len(g.getvalue())
tarinfo.mtime = time.time()
if not win():
tarinfo.uid = os.getuid()
tarinfo.gid = os.getgid()
g.seek(0)
archive.addfile(tarinfo, g)
archive.close()
g.close()
return True