Skip to content

Commit 9a0d155

Browse files
committed
Make minor improvements to visopts.py.
When dot fails to start, print a user-friendly error message instead of dumping the stack trace. Fixup some wording here and there. [skip ci]
1 parent 2f7e6af commit 9a0d155

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

testprogs/visopts.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
"""
4-
This program parse the output from pcap_compile() to visualize the CFG after
4+
This program parses the output from pcap_compile() to visualize the CFG after
55
each optimize phase.
66
77
Usage guide:
@@ -15,23 +15,24 @@
1515
testprogs/filtertest -g EN10MB host 192.168.1.1 > a.txt
1616
3. Send a.txt to this program's standard input
1717
cat a.txt | testprogs/visopts.py
18+
(Graphviz must be installed)
1819
4. Step 2&3 can be merged:
1920
testprogs/filtertest -g EN10MB host 192.168.1.1 | testprogs/visopts.py
2021
5. The standard output is something like this:
2122
generated files under directory: /tmp/visopts-W9ekBw
2223
the directory will be removed when this programs finished.
2324
open this link: http://localhost:39062/expr1.html
24-
6. Using open link at the 3rd line `http://localhost:39062/expr1.html'
25+
6. Open the URL at the 3rd line in a browser.
2526
2627
Note:
27-
1. The CFG is translated to SVG an document, expr1.html embeded them as external
28-
document. If you open expr1.html as local file using file:// protocol, some
29-
browsers will deny such requests so the web pages will not shown properly.
30-
For chrome, you can run it using following command to avoid this:
28+
1. The CFG is translated to SVG images, expr1.html embeds them as external
29+
documents. If you open expr1.html as local file using file:// protocol, some
30+
browsers will deny such requests so the web page will not work properly.
31+
For Chrome, you can run it using the following command to avoid this:
3132
chromium --disable-web-security
32-
That's why this program start a localhost http server.
33-
2. expr1.html use jquery from https://ajax.googleapis.com, so you need internet
34-
access to show the web page.
33+
That's why this program starts a localhost HTTP server.
34+
2. expr1.html uses jQuery from https://ajax.googleapis.com, so it needs Internet
35+
access to work.
3536
"""
3637

3738
import sys, os
@@ -255,7 +256,13 @@ def render_on_html(infile):
255256
log += line
256257

257258
if indot == 2:
258-
p = subprocess.Popen(['dot', '-Tsvg'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
259+
try:
260+
p = subprocess.Popen(['dot', '-Tsvg'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
261+
except OSError as ose:
262+
print "Failed to run 'dot':", ose
263+
print "(Is Graphviz installed?)"
264+
exit(1)
265+
259266
svg = p.communicate(dot)[0]
260267
with file("expr1_g%03d.svg" % (gid), "wt") as f:
261268
f.write(svg)
@@ -296,7 +303,7 @@ def main():
296303
os.chdir(tempfile.mkdtemp(prefix="visopts-"))
297304
atexit.register(shutil.rmtree, os.getcwd())
298305
print "generated files under directory: %s" % os.getcwd()
299-
print " the directory will be removed when this programs finished."
306+
print " the directory will be removed when this program has finished."
300307

301308
if not render_on_html(sys.stdin):
302309
return 1

0 commit comments

Comments
 (0)