#301: use errno values from errno module.

This commit is contained in:
Georg Brandl 2009-12-24 12:58:53 +01:00
parent a3f11db6b7
commit 0dc0837e01
4 changed files with 11 additions and 8 deletions

View File

@ -16,7 +16,7 @@ from os import path
from docutils import nodes from docutils import nodes
from sphinx import package_dir, locale from sphinx import package_dir, locale
from sphinx.util import SEP, relative_uri from sphinx.util import SEP, EEXIST, relative_uri
from sphinx.environment import BuildEnvironment from sphinx.environment import BuildEnvironment
from sphinx.util.console import bold, purple, darkgreen, term_width_line from sphinx.util.console import bold, purple, darkgreen, term_width_line
@ -210,7 +210,7 @@ class Builder(object):
path.join(self.doctreedir, ENV_PICKLE_FILENAME)) path.join(self.doctreedir, ENV_PICKLE_FILENAME))
self.info('done') self.info('done')
except Exception, err: except Exception, err:
if type(err) is IOError and err.errno == 2: if type(err) is IOError and err.errno == EEXIST:
self.info('not found') self.info('not found')
else: else:
self.info('failed: %s' % err) self.info('failed: %s' % err)

View File

@ -22,7 +22,7 @@ except ImportError:
from docutils import nodes from docutils import nodes
from sphinx.errors import SphinxError from sphinx.errors import SphinxError
from sphinx.util import ensuredir from sphinx.util import ensuredir, ENOENT
from sphinx.util.compat import Directive from sphinx.util.compat import Directive
@ -111,7 +111,7 @@ def render_dot(self, code, options, format, prefix='graphviz'):
try: try:
p = Popen(dot_args, stdout=PIPE, stdin=PIPE, stderr=PIPE) p = Popen(dot_args, stdout=PIPE, stdin=PIPE, stderr=PIPE)
except OSError, err: except OSError, err:
if err.errno != 2: # No such file or directory if err.errno != ENOENT: # No such file or directory
raise raise
self.builder.warn('dot command %r cannot be run (needed for graphviz ' self.builder.warn('dot command %r cannot be run (needed for graphviz '
'output), check the graphviz_dot setting' % 'output), check the graphviz_dot setting' %

View File

@ -23,7 +23,7 @@ except ImportError:
from docutils import nodes from docutils import nodes
from sphinx.errors import SphinxError from sphinx.errors import SphinxError
from sphinx.util import ensuredir from sphinx.util import ensuredir, ENOENT
from sphinx.util.png import read_png_depth, write_png_depth from sphinx.util.png import read_png_depth, write_png_depth
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
@ -119,7 +119,7 @@ def render_math(self, math):
try: try:
p = Popen(ltx_args, stdout=PIPE, stderr=PIPE) p = Popen(ltx_args, stdout=PIPE, stderr=PIPE)
except OSError, err: except OSError, err:
if err.errno != 2: # No such file or directory if err.errno != ENOENT: # No such file or directory
raise raise
self.builder.warn('LaTeX command %r cannot be run (needed for math ' self.builder.warn('LaTeX command %r cannot be run (needed for math '
'display), check the pngmath_latex setting' % 'display), check the pngmath_latex setting' %
@ -147,7 +147,7 @@ def render_math(self, math):
try: try:
p = Popen(dvipng_args, stdout=PIPE, stderr=PIPE) p = Popen(dvipng_args, stdout=PIPE, stderr=PIPE)
except OSError, err: except OSError, err:
if err.errno != 2: # No such file or directory if err.errno != ENOENT: # No such file or directory
raise raise
self.builder.warn('dvipng command %r cannot be run (needed for math ' self.builder.warn('dvipng command %r cannot be run (needed for math '
'display), check the pngmath_dvipng setting' % 'display), check the pngmath_dvipng setting' %

View File

@ -26,6 +26,9 @@ from os import path
import docutils import docutils
import sphinx import sphinx
# Errnos that we need.
EEXIST = getattr(errno, 'EEXIST', 0)
ENOENT = getattr(errno, 'ENOENT', 0)
# Generally useful regular expressions. # Generally useful regular expressions.
ws_re = re.compile(r'\s+') ws_re = re.compile(r'\s+')
@ -69,7 +72,7 @@ def ensuredir(path):
os.makedirs(path) os.makedirs(path)
except OSError, err: except OSError, err:
# 0 for Jython/Win32 # 0 for Jython/Win32
if err.errno not in [0, getattr(errno, 'EEXIST', 0)]: if err.errno not in [0, EEXIST]:
raise raise