[Git][NTPsec/ntpsec][master] ntpviz: now 100% polyglot.

Gary E. Miller gitlab at mg.gitlab.com
Fri Oct 7 01:48:54 UTC 2016


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
0e3f5e10 by Gary E. Miller at 2016-10-06T18:44:00-07:00
ntpviz: now 100% polyglot.

No need to edit two lines to go between Python 2 and 3.

- - - - -


1 changed file:

- ntpstats/ntpviz


Changes:

=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -174,13 +174,19 @@ def gnuplot(template, outfile=None):
     else:
         out = open(outfile, "w")
     # shell=True is a security hazard
+    # would be grat to capture stderr, but the Pythin doc says
+    # that can lead to deadlock on large stderr output.  gnuplot
+    # can output a lot to stderr...
     proc = subprocess.Popen("gnuplot",
                             shell=False, bufsize=4096,
                             stdin=subprocess.PIPE, stdout=out)
-    # next line works in Python 3, not Python 2
-    # proc.stdin.write(template.encode('ascii','ignore'))
-    # next line works in Python 2, not Python 3
-    proc.stdin.write(template)
+    v = sys.version_info
+    if 3 <= v[0]:
+        # next line works in Python 3, not Python 2
+        proc.stdin.write(template.encode('ascii','ignore'))
+    else:
+        # next line works in Python 2, not Python 3
+        proc.stdin.write(template)
     proc.stdin.close()
     return proc.wait()
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/0e3f5e100135f8b801861a8d665ccaa2b55a77f2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161007/304c26b8/attachment.html>


More information about the vc mailing list