Nicer error message when exporting a generated csv catalog to a file open in another program on windows. Fixes #1155539 (Creating a CSV)

This commit is contained in:
Kovid Goyal 2013-03-15 16:03:06 +05:30
parent fa1fd8d11f
commit 40c30cfe58

View File

@ -5,7 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import re, os, shutil
import re, os, shutil, errno
from PyQt4.Qt import QModelIndex
@ -93,6 +93,15 @@ class GenerateCatalogAction(InterfaceAction):
if export_dir:
destination = os.path.join(export_dir, '%s.%s' % (
sanitize_file_name_unicode(job.catalog_title), job.fmt.lower()))
try:
shutil.copyfile(job.catalog_file_path, destination)
except EnvironmentError as err:
if getattr(err, 'errno', None) == errno.EACCES: # Permission denied
import traceback
error_dialog(self, _('Permission denied'),
_('Could not open %s. Is it being used by another'
' program?')%destination, det_msg=traceback.format_exc(),
show=True)
return
raise