[Epydoc-commits] SF.net SVN: epydoc: [1210] trunk/epydoc/src/epydoc/markup
Brought to you by:
edloper
From: <ed...@us...> - 2006-04-10 13:25:55
|
Revision: 1210 Author: edloper Date: 2006-04-10 06:25:50 -0700 (Mon, 10 Apr 2006) ViewCVS: http://svn.sourceforge.net/epydoc/?rev=1210&view=rev Log Message: ----------- - DotGraph.to_html() now takes an extra argument, the image filename, and is responsible for writing the image file. This lets me use a single call to dot generate both the image and the client image map when dotversion>1.8.10 Modified Paths: -------------- trunk/epydoc/src/epydoc/docwriter/dotgraph.py trunk/epydoc/src/epydoc/docwriter/html.py trunk/epydoc/src/epydoc/markup/epytext.py trunk/epydoc/src/epydoc/markup/restructuredtext.py Modified: trunk/epydoc/src/epydoc/docwriter/dotgraph.py =================================================================== --- trunk/epydoc/src/epydoc/docwriter/dotgraph.py 2006-04-10 13:23:24 UTC (rev 1209) +++ trunk/epydoc/src/epydoc/docwriter/dotgraph.py 2006-04-10 13:25:50 UTC (rev 1210) @@ -128,7 +128,7 @@ self.uid = '%s_%s' % (self.uid, n) self._uids.add(self.uid) - def to_html(self, image_url, center=True): + def to_html(self, image_file, image_url, center=True): """ Return the HTML code that should be uesd to display this graph (including a client-side image map). @@ -136,7 +136,17 @@ :param image_url: The URL of the image file for this graph; this should be generated separately with the `write()` method. """ - cmapx = self.render('cmapx') or '' + # If dotversion >1.8.10, then we can generate the image and + # the cmapx with a single call to dot. Otherwise, we need to + # run dot twice. + if get_dot_version() > [1,8,10]: + cmapx = self._run_dot('-Tgif', '-o%s' % image_file, '-Tcmapx') + if cmapx is None: return '' # failed to render + else: + if not self.write(image_file): + return '' # failed to render + cmapx = self.render('cmapx') or '' + title = plaintext_to_html(self.title or '') caption = plaintext_to_html(self.caption or '') if title or caption: @@ -209,14 +219,12 @@ :return: True if rendering was successful. """ - s = self.render(language) - if s is not None: - out = open(filename, 'wb') - out.write(s) - out.close() - return True - else: - return False + result = self._run_dot('-T%s' % language, + '-o%s' % filename) + # Decode into unicode, if necessary. + if language == 'cmapx' and result is not None: + result = result.decode('utf-8') + return (result is not None) def render(self, language='gif'): """ @@ -224,14 +232,13 @@ format `language`. Return the result as a string, or `None` if the rendering failed. """ + return self._run_dot('-T%s' % language) + + def _run_dot(self, *options): try: - result, err = run_subprocess([DOT_COMMAND, '-T%s' % language], + result, err = run_subprocess((DOT_COMMAND,)+options, self.to_dotfile()) - # Decode into unicode, if necessary. - if language == 'cmapx' and result is not None: - result = result.decode('utf-8') - if err: - log.warning("Graphviz dot warning(s):\n%s" % err) + if err: log.warning("Graphviz dot warning(s):\n%s" % err) except OSError, e: log.warning("Unable to render Graphviz dot graph:\n%s" % e) #log.debug(self.to_dotfile()) Modified: trunk/epydoc/src/epydoc/docwriter/html.py =================================================================== --- trunk/epydoc/src/epydoc/docwriter/html.py 2006-04-10 13:23:24 UTC (rev 1209) +++ trunk/epydoc/src/epydoc/docwriter/html.py 2006-04-10 13:25:50 UTC (rev 1210) @@ -1334,18 +1334,13 @@ #{ 2.10. Graphs #//////////////////////////////////////////////////////////// + # [xx] use DotGraph.to_html?? def render_graph(self, graph, css='graph-without-title'): if graph is None: return '' - # Write the graph's image to a file - path = os.path.join(self._directory, graph.uid) - if not graph.write('%s.gif' % path, 'gif'): - return '' - # Generate the image map. - cmapx = graph.render('cmapx') or '' - # Display the graph. - uid = graph.uid - return ('%s\n<img src="%s.gif" alt="%s" usemap="#%s" ismap="ismap" ' - 'class="%s"/>\n' % (cmapx, uid, uid, uid, css)) + graph.caption = graph.title = None + image_url = '%s.gif' % graph.uid + image_file = os.path.join(self._directory, image_url) + return graph.to_html(image_file, image_url) def render_callgraph(self, callgraph): graph_html = self.render_graph(callgraph, css='graph-with-title') Modified: trunk/epydoc/src/epydoc/markup/epytext.py =================================================================== --- trunk/epydoc/src/epydoc/markup/epytext.py 2006-04-10 13:23:24 UTC (rev 1209) +++ trunk/epydoc/src/epydoc/markup/epytext.py 2006-04-10 13:25:50 UTC (rev 1210) @@ -1831,14 +1831,14 @@ else: return '[??]' elif tree.tagName == 'graph': + # Generate the graph. graph = self._build_graph(variables[0], variables[1:], linker, docindex, context) if not graph: return '' - # Write the graph's image to a file - path = os.path.join(directory, graph.uid) - if not graph.write('%s.gif' % path, 'gif'): - return '' - return graph.to_html('%s.gif' % graph.uid) + # Write the graph. + image_url = '%s.gif' % graph.uid + image_file = os.path.join(directory, image_url) + return graph.to_html(image_file, image_url) else: raise ValueError('Unknown epytext DOM element %r' % tree.tagName) Modified: trunk/epydoc/src/epydoc/markup/restructuredtext.py =================================================================== --- trunk/epydoc/src/epydoc/markup/restructuredtext.py 2006-04-10 13:23:24 UTC (rev 1209) +++ trunk/epydoc/src/epydoc/markup/restructuredtext.py 2006-04-10 13:25:50 UTC (rev 1210) @@ -533,11 +533,11 @@ # Generate the graph. graph = node.graph(self._docindex, self._context, self._linker) if graph is None: return - # Write the graph's image to a file - path = os.path.join(self._directory, graph.uid) - if not graph.write('%s.gif' % path, 'gif'): - return - self.body.append(graph.to_html('%s.gif' % graph.uid)) + + # Write the graph. + image_url = '%s.gif' % graph.uid + image_file = os.path.join(self._directory, image_url) + self.body.append(graph.to_html(image_file, image_url)) def depart_dotgraph(self, node): pass # Nothing to do. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |