[graph] More explicit error message if dot is not found/executable (closes #253516)

authorDavid Douard <david.douard@logilab.fr>
changeset3ff9bfb473eb
branchdefault
phasedraft
hiddenyes
parent revision#68d4551aee67 [test] fix text_to_dict doctest (closes #174440)
child revision#e0d972362b72 [modutils] Use a cache when abspathing sys.path for file_from_modpath.
files modified by this revision
graph.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1409568136 -7200
# Mon Sep 01 12:42:16 2014 +0200
# Node ID 3ff9bfb473eb2164b07106d0e72e76bd38f33a64
# Parent 68d4551aee6724ca49384da8a714051b6c211576
[graph] More explicit error message if dot is not found/executable (closes #253516)

diff --git a/graph.py b/graph.py
@@ -27,10 +27,11 @@
1  import os.path as osp
2  import os
3  import sys
4  import tempfile
5  import codecs
6 +import errno
7 
8  def escape(value):
9      """Make <value> usable in a dot file."""
10      lines = [line.replace('"', '\\"') for line in value.split('\n')]
11      data = '\\l'.join(lines)
@@ -112,17 +113,22 @@
12          if target != 'dot':
13              if sys.platform == 'win32':
14                  use_shell = True
15              else:
16                  use_shell = False
17 -            if mapfile:
18 -                subprocess.call([self.renderer,  '-Tcmapx', '-o', mapfile, '-T', target, dot_sourcepath, '-o', outputfile],
19 -                                shell=use_shell)
20 -            else:
21 -                subprocess.call([self.renderer, '-T',  target,
22 -                                 dot_sourcepath, '-o',  outputfile],
23 -                                shell=use_shell)
24 +            try:
25 +                if mapfile:
26 +                    subprocess.call([self.renderer,  '-Tcmapx', '-o', mapfile, '-T', target, dot_sourcepath, '-o', outputfile],
27 +                                    shell=use_shell)
28 +                else:
29 +                    subprocess.call([self.renderer, '-T',  target,
30 +                                     dot_sourcepath, '-o',  outputfile],
31 +                                    shell=use_shell)
32 +            except OSError as e:
33 +                if e.errno == errno.ENOENT:
34 +                    e.strerror = 'File not found or not executable: {0}'.format(self.renderer)
35 +                    raise
36              os.unlink(dot_sourcepath)
37          return outputfile
38 
39      def emit(self, line):
40          """Adds <line> to final output."""