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

authorDavid Douard <david.douard@logilab.fr>
changesetadf1a1829274
branchdefault
phasedraft
hiddenyes
parent revision#4085cf1c6908 [test] fix text_to_dict doctest (closes #174440)
child revision#7f202eb5d0fd [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 adf1a182927408e3359330a9261269f034fe88df
# Parent 4085cf1c6908a87efd83c0b503fd8f3f3c0ef163
[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."""