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,9 +586,9 @@ class ExportAssistant(ManagedWindow, Gtk.Assistant):
ix = self.get_selected_format_index() ix = self.get_selected_format_index()
config.set('behavior.recent-export-type', ix) config.set('behavior.recent-export-type', ix)
export_function = self.map_exporters[ix].get_export_function() export_function = self.map_exporters[ix].get_export_function()
success = export_function(self.dbstate.db, success = export_function(
filename, self.dbstate.db, filename,
User(error=ErrorDialog, parent=self.uistate.window, User(error=ErrorDialog, parent=self.window,
callback=self.callback), callback=self.callback),
self.option_box_instance) self.option_box_instance)
except: except:

View File

@ -179,23 +179,22 @@ class PackageWriter:
#--------------------------------------------------------------- #---------------------------------------------------------------
try: try:
archive = tarfile.open(self.filename,'w:gz') with tarfile.open(self.filename, 'w:gz') as archive:
except EnvironmentError 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 # Write media files first, since the database may be modified
# during the process (i.e. when removing object) # during the process (i.e. when removing object)
for m_id in self.db.get_media_handles(sort_handles=True): 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) mobject = self.db.get_media_from_handle(m_id)
filename = media_path_full(self.db, mobject.get_path()) filename = media_path_full(self.db, mobject.get_path())
archname = str(mobject.get_path()) archname = str(mobject.get_path())
if os.path.isfile(filename) and os.access(filename, os.R_OK): if os.path.isfile(filename) and os.access(filename,
os.R_OK):
archive.add(filename, archname, filter=fix_mtime) archive.add(filename, archname, filter=fix_mtime)
# Write XML now # Write XML now
g = BytesIO() with BytesIO() as g:
gfile = XmlWriter(self.db, self.user, 2) gfile = XmlWriter(self.db, self.user, 2)
gfile.write_handle(g) gfile.write_handle(g)
tarinfo = tarfile.TarInfo('data.gramps') tarinfo = tarfile.TarInfo('data.gramps')
@ -206,7 +205,9 @@ class PackageWriter:
tarinfo.gid = os.getgid() tarinfo.gid = os.getgid()
g.seek(0) g.seek(0)
archive.addfile(tarinfo, g) archive.addfile(tarinfo, g)
archive.close()
g.close()
return True return True
except (EnvironmentError, OSError) as msg:
log.warning(str(msg))
self.user.notify_error(_('Failure writing %s') % self.filename, str(msg))
return 0