]> The Tcpdump Group git mirrors - libpcap/commitdiff
Make minor improvements to visopts.py.
authorDenis Ovsienko <[email protected]>
Thu, 20 Aug 2020 21:36:59 +0000 (22:36 +0100)
committerDenis Ovsienko <[email protected]>
Thu, 20 Aug 2020 22:23:31 +0000 (23:23 +0100)
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]

testprogs/visopts.py

index ef316c60fc416e134e5e5af55189f3c0ec0a92cb..80c14639c3d5c354f8d507415d2f358c6ab3effd 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 """
-This program parse the output from pcap_compile() to visualize the CFG after
+This program parses the output from pcap_compile() to visualize the CFG after
 each optimize phase.
 
 Usage guide:
@@ -15,23 +15,24 @@ Usage guide:
        testprogs/filtertest -g EN10MB host 192.168.1.1 > a.txt
 3. Send a.txt to this program's standard input
        cat a.txt | testprogs/visopts.py
+   (Graphviz must be installed)
 4. Step 2&3 can be merged:
        testprogs/filtertest -g EN10MB host 192.168.1.1 | testprogs/visopts.py
 5. The standard output is something like this:
        generated files under directory: /tmp/visopts-W9ekBw
          the directory will be removed when this programs finished.
        open this link: http://localhost:39062/expr1.html
-6. Using open link at the 3rd line `http://localhost:39062/expr1.html'
+6. Open the URL at the 3rd line in a browser.
 
 Note:
-1. The CFG is translated to SVG an document, expr1.html embeded them as external
-   document. If you open expr1.html as local file using file:// protocol, some
-   browsers will deny such requests so the web pages will not shown properly.
-   For chrome, you can run it using following command to avoid this:
+1. The CFG is translated to SVG images, expr1.html embeds them as external
+   documents. If you open expr1.html as local file using file:// protocol, some
+   browsers will deny such requests so the web page will not work properly.
+   For Chrome, you can run it using the following command to avoid this:
        chromium --disable-web-security
-   That's why this program start a localhost http server.
-2. expr1.html use jquery from https://ajax.googleapis.com, so you need internet
-   access to show the web page.
+   That's why this program starts a localhost HTTP server.
+2. expr1.html uses jQuery from https://ajax.googleapis.com, so it needs Internet
+   access to work.
 """
 
 import sys, os
@@ -255,7 +256,13 @@ def render_on_html(infile):
             log += line
 
         if indot == 2:
-            p = subprocess.Popen(['dot', '-Tsvg'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+            try:
+                p = subprocess.Popen(['dot', '-Tsvg'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+            except OSError as ose:
+                print "Failed to run 'dot':", ose
+                print "(Is Graphviz installed?)"
+                exit(1)
+
             svg = p.communicate(dot)[0]
             with file("expr1_g%03d.svg" % (gid), "wt") as f:
                 f.write(svg)
@@ -296,7 +303,7 @@ def main():
     os.chdir(tempfile.mkdtemp(prefix="visopts-"))
     atexit.register(shutil.rmtree, os.getcwd())
     print "generated files under directory: %s" % os.getcwd()
-    print "  the directory will be removed when this programs finished."
+    print "  the directory will be removed when this program has finished."
 
     if not render_on_html(sys.stdin):
         return 1