From d1d7eb99a0530ceb5b353e9a3876711cdcbd804e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 14 Sep 2011 11:40:11 -0600 Subject: [PATCH] Fix #850183 (fix hardcoded errno values) --- src/calibre/ebooks/html/input.py | 4 ++-- src/calibre/ebooks/pdf/pdftohtml.py | 2 +- src/calibre/gui2/metadata/basic_widgets.py | 6 +++--- src/calibre/gui2/metadata/single.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/calibre/ebooks/html/input.py b/src/calibre/ebooks/html/input.py index 69eb493c7d..f68ea4f678 100644 --- a/src/calibre/ebooks/html/input.py +++ b/src/calibre/ebooks/html/input.py @@ -11,7 +11,7 @@ __docformat__ = 'restructuredtext en' Input plugin for HTML or OPF ebooks. ''' -import os, re, sys, uuid, tempfile +import os, re, sys, uuid, tempfile, errno from urlparse import urlparse, urlunparse from urllib import unquote from functools import partial @@ -75,7 +75,7 @@ class IgnoreFile(Exception): def __init__(self, msg, errno): Exception.__init__(self, msg) - self.doesnt_exist = errno == 2 + self.doesnt_exist = errno == errno.ENOENT self.errno = errno class HTMLFile(object): diff --git a/src/calibre/ebooks/pdf/pdftohtml.py b/src/calibre/ebooks/pdf/pdftohtml.py index a791dab48a..9d81c73c2a 100644 --- a/src/calibre/ebooks/pdf/pdftohtml.py +++ b/src/calibre/ebooks/pdf/pdftohtml.py @@ -53,7 +53,7 @@ def pdftohtml(output_dir, pdf_path, no_images): p = popen(cmd, stderr=logf._fd, stdout=logf._fd, stdin=subprocess.PIPE) except OSError as err: - if err.errno == 2: + if err.errno == errno.ENOENT: raise ConversionError(_('Could not find pdftohtml, check it is in your PATH')) else: raise diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index a349b8ca92..fe20be765f 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import textwrap, re, os +import textwrap, re, os, errno from PyQt4.Qt import (Qt, QDateEdit, QDate, pyqtSignal, QMessageBox, QIcon, QToolButton, QWidget, QLabel, QGridLayout, QApplication, @@ -98,7 +98,7 @@ class TitleEdit(EnLineEdit): getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False, commit=False) except (IOError, OSError) as err: - if getattr(err, 'errno', -1) == 13: # Permission denied + if getattr(err, 'errno', -1) == errno.EACCES: # Permission denied import traceback fname = err.filename if err.filename else 'file' error_dialog(self, _('Permission denied'), @@ -262,7 +262,7 @@ class AuthorsEdit(MultiCompleteComboBox): self.books_to_refresh |= db.set_authors(id_, authors, notify=False, allow_case_change=True) except (IOError, OSError) as err: - if getattr(err, 'errno', -1) == 13: # Permission denied + if getattr(err, 'errno', -1) == errno.EACCES: # Permission denied import traceback fname = err.filename if err.filename else 'file' error_dialog(self, _('Permission denied'), diff --git a/src/calibre/gui2/metadata/single.py b/src/calibre/gui2/metadata/single.py index a2666b0351..bbc5f6fce4 100644 --- a/src/calibre/gui2/metadata/single.py +++ b/src/calibre/gui2/metadata/single.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os +import os, errno from functools import partial from PyQt4.Qt import (Qt, QVBoxLayout, QHBoxLayout, QWidget, QPushButton, @@ -427,7 +427,7 @@ class MetadataSingleDialogBase(ResizableDialog): self.books_to_refresh |= getattr(widget, 'books_to_refresh', set([])) except IOError as err: - if err.errno == 13: # Permission denied + if err.errno == errno.EACCES: # Permission denied import traceback fname = err.filename if err.filename else 'file' error_dialog(self, _('Permission denied'),