[pypy-svn] r18122 - in pypy/dist/pypy: bin translator/tool/pygame
arigo at codespeak.net
arigo at codespeak.net
Tue Oct 4 11:13:26 CEST 2005
Author: arigo
Date: Tue Oct 4 11:13:19 2005
New Revision: 18122
Added:
pypy/dist/pypy/bin/dotviewer.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/tool/pygame/cyrvetic.ttf (props changed)
pypy/dist/pypy/translator/tool/pygame/graphclient.py
Log:
Added a unified entry-point script to view dot graphs. The result is a tool
that can display .dot files (compiled behind the scene using either a local
'dot' or Codespeak's) as well as "browse" a remote graph server (as run with
translate_pypy --graphserve).
Added: pypy/dist/pypy/bin/dotviewer.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/bin/dotviewer.py Tue Oct 4 11:13:19 2005
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+"""
+Command-line interface for a dot file viewer -- either viewing normal .dot
+files or connecting to a graph server like a browser.
+"""
+
+import autopath
+import sys, py
+from pypy.translator.tool.pygame import graphclient
+
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print >> sys.stderr, 'Usage: %s filename.dot' % (sys.argv[0],)
+ print >> sys.stderr, ' %s hostname:port' % (sys.argv[0],)
+ print >> sys.stderr, ' %s :port' % (sys.argv[0],)
+ print >> sys.stderr
+ print >> sys.stderr, ('In the first form, show the graph contained '
+ 'in a .dot file.')
+ print >> sys.stderr, ('In the other forms, connect to a graph server '
+ 'like goal/translate_pypy.')
+ sys.exit(2)
+ filename = sys.argv[1]
+ if py.path.local(filename).check():
+ graphclient.display_dot_file(filename)
+ elif filename.count(':') != 1:
+ print >> sys.stderr, 'No such file:', filename
+ sys.exit(1)
+ else:
+ hostname, port = sys.argv[1].split(':')
+ port = int(port)
+ graphclient.display_remote_layout(hostname, port)
Modified: pypy/dist/pypy/translator/tool/pygame/graphclient.py
==============================================================================
--- pypy/dist/pypy/translator/tool/pygame/graphclient.py (original)
+++ pypy/dist/pypy/translator/tool/pygame/graphclient.py Tue Oct 4 11:13:19 2005
@@ -41,18 +41,25 @@
str(plainfile),
data=request)
-class ClientGraphLayout(GraphLayout):
-
- def __init__(self, connexion, key, dot, links, **ignored):
- # generate a temporary .dot file and call dot on it
- DOT_FILE.write(dot)
+class DotGraphLayout(GraphLayout):
+ """A graph layout computed by dot from a .dot file.
+ """
+ def __init__(self, dotfilename):
try:
- dot2plain(DOT_FILE, PLAIN_FILE, use_codespeak=False)
+ dot2plain(dotfilename, PLAIN_FILE, use_codespeak=False)
GraphLayout.__init__(self, PLAIN_FILE)
except (py.error.Error, IOError, TypeError, ValueError):
# failed, try via codespeak
- dot2plain(DOT_FILE, PLAIN_FILE, use_codespeak=True)
+ dot2plain(dotfilename, PLAIN_FILE, use_codespeak=True)
GraphLayout.__init__(self, PLAIN_FILE)
+
+
+class ClientGraphLayout(DotGraphLayout):
+
+ def __init__(self, connexion, key, dot, links, **ignored):
+ # generate a temporary .dot file and call dot on it
+ DOT_FILE.write(dot)
+ DotGraphLayout.__init__(self, DOT_FILE)
self.connexion = connexion
self.key = key
self.links.update(links)
@@ -119,6 +126,10 @@
conn.initiate_display(0)
display.run()
+def display_dot_file(filename):
+ display = DotGraphLayout(filename).get_display()
+ display.run()
+
if __name__ == '__main__':
import sys
More information about the Pypy-commit
mailing list