GraphvizParser

Changeset

9:cedca431c02f
2012-03-07 Paul Boddie raw files shortlog changelog graph Incorporated encoding and subprocess fixes from Frederick Capovilla. rel-0-2-1
README.txt (file) docs/COPYING.txt (file) parsers/graphviz.py (file)
     1.1 --- a/README.txt	Sat Jan 14 21:04:42 2012 +0100
     1.2 +++ b/README.txt	Wed Mar 07 00:48:28 2012 +0100
     1.3 @@ -90,7 +90,9 @@
     1.4  
     1.5    * Comments must start at the beginning of the graphviz block and at the
     1.6      beginning of their respective lines. They must also not contain any extra
     1.7 -    whitespace surrounding the = sign.
     1.8 +    whitespace surrounding the = sign. It would arguably be better if the
     1.9 +    configuration of images were done using the argument notation employed by
    1.10 +    other parsers.
    1.11  
    1.12    * SVG image sizing can only be done by extracting the dimensions from an
    1.13      uncompressed ("svg" format, not "svgz" format) output representation.
     2.1 --- a/docs/COPYING.txt	Sat Jan 14 21:04:42 2012 +0100
     2.2 +++ b/docs/COPYING.txt	Wed Mar 07 00:48:28 2012 +0100
     2.3 @@ -3,6 +3,7 @@
     2.4  
     2.5  Copyright (C) 2008 Wayne Tucker
     2.6  Copyright (C) 2011, 2012 Paul Boddie <paul@boddie.org.uk>
     2.7 +Copyright (C) 2012 Frederick Capovilla (Libéo) <fcapovilla@live.ca>
     2.8  
     2.9  This software is free software; you can redistribute it and/or
    2.10  modify it under the terms of the GNU General Public License as
     3.1 --- a/parsers/graphviz.py	Sat Jan 14 21:04:42 2012 +0100
     3.2 +++ b/parsers/graphviz.py	Wed Mar 07 00:48:28 2012 +0100
     3.3 @@ -1,21 +1,23 @@
     3.4 -# -*- coding: iso-8859-1 -*-
     3.5 +# -*- coding: utf-8 -*-
     3.6  """
     3.7      MoinMoin - Graphviz Parser
     3.8      Based loosely on GNUPLOT parser by MoinMoin:KwonChanYoung
     3.9  
    3.10      @copyright: 2008 Wayne Tucker
    3.11      @copyright: 2011, 2012 Paul Boddie <paul@boddie.org.uk>
    3.12 +    @copyright: 2012 Frederick Capovilla (Libéo) <fcapovilla@live.ca>
    3.13      @license: GNU GPL, see COPYING for details.
    3.14  """
    3.15  
    3.16 -__version__ = "0.2"
    3.17 +__version__ = "0.2.1"
    3.18  
    3.19  # Change this to the directory that the Graphviz binaries (dot, neato, etc.)
    3.20  # are installed in.
    3.21  
    3.22 -BINARY_PATH = '/usr/bin'
    3.23 +BINARY_PATH = '/usr/bin/'
    3.24  
    3.25  from os.path import join
    3.26 +from StringIO import StringIO
    3.27  import os
    3.28  import subprocess
    3.29  import sha
    3.30 @@ -113,7 +115,7 @@
    3.31              logging.warn('format %s is incompatible with cmapx option' % format)
    3.32              cmapx = None
    3.33  
    3.34 -        digest = sha.new(self.raw).hexdigest()
    3.35 +        digest = sha.new(self.raw.encode('utf-8')).hexdigest()
    3.36  
    3.37          # Make sure that an attachments directory exists and that old graphs are
    3.38          # deleted.
    3.39 @@ -232,23 +234,19 @@
    3.40                  stdout=subprocess.PIPE,
    3.41                  stderr=subprocess.PIPE)
    3.42  
    3.43 -        p.stdin.write(graph_def)
    3.44 -        p.stdin.flush()
    3.45 -        p.stdin.close()
    3.46 -
    3.47 -        p.wait()
    3.48 +        (stdoutdata, stderrdata) = p.communicate(input=graph_def.encode('utf-8'))
    3.49  
    3.50          # Graph data always goes via standard output so that we can extract the
    3.51          # width and height if possible.
    3.52  
    3.53          if need_output:
    3.54 -            output, attrs = self.process_output(p.stdout, format)
    3.55 +            output, attrs = self.process_output(StringIO(stdoutdata), format)
    3.56          else:
    3.57              output, attrs = None, {}
    3.58  
    3.59          # Test for errors.
    3.60  
    3.61 -        errors = p.stderr.read()
    3.62 +        errors = stderrdata
    3.63  
    3.64          if len(errors) > 0:
    3.65              raise GraphVizError, errors
    3.66 @@ -289,7 +287,7 @@
    3.67          found = False
    3.68          attrs = {}
    3.69  
    3.70 -        for line in output.xreadlines():
    3.71 +        for line in output.readlines():
    3.72              if not found and line.startswith("<svg "):
    3.73                  for match in self.attr_regexp.finditer(line):
    3.74                      attrs[match.group("attr")] = match.group("value")