From 40c30cfe58b306171c5a6c79a0f7734afd5e9d5e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Mar 2013 16:03:06 +0530 Subject: [PATCH] Nicer error message when exporting a generated csv catalog to a file open in another program on windows. Fixes #1155539 (Creating a CSV) --- src/calibre/gui2/actions/catalog.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/actions/catalog.py b/src/calibre/gui2/actions/catalog.py index a6c0877049..fbc8181d8e 100644 --- a/src/calibre/gui2/actions/catalog.py +++ b/src/calibre/gui2/actions/catalog.py @@ -5,7 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __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())) - shutil.copyfile(job.catalog_file_path, destination) - + 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