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:
parent
ddb29b1628
commit
9b0cf1b976
@ -586,11 +586,11 @@ 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:
|
||||||
#an error not catched in the export_function itself
|
#an error not catched in the export_function itself
|
||||||
success = False
|
success = False
|
||||||
|
@ -179,34 +179,35 @@ class PackageWriter:
|
|||||||
#---------------------------------------------------------------
|
#---------------------------------------------------------------
|
||||||
|
|
||||||
try:
|
try:
|
||||||
archive = tarfile.open(self.filename,'w:gz')
|
with tarfile.open(self.filename, 'w:gz') as archive:
|
||||||
except EnvironmentError as msg:
|
|
||||||
|
# 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))
|
log.warning(str(msg))
|
||||||
self.user.notify_error(_('Failure writing %s') % self.filename, str(msg))
|
self.user.notify_error(_('Failure writing %s') % self.filename, str(msg))
|
||||||
return 0
|
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
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user