[Git][NTPsec/ntpsec][master] Fix ntpviz file encodings
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Nov 26 15:38:56 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
03176993 by Richard Laager at 2017-11-26T15:38:34+00:00
Fix ntpviz file encodings
This fixes ntpviz on python3. We need to specify the file encoding.
- - - - -
1 changed file:
- ntpclients/ntpviz
Changes:
=====================================
ntpclients/ntpviz
=====================================
--- a/ntpclients/ntpviz
+++ b/ntpclients/ntpviz
@@ -56,6 +56,12 @@ ntpviz: can't find the Python argparse module
""")
sys.exit(1)
+if sys.version_info[0] == 2:
+ import codecs
+ def open(file, mode='r', buffering=-1, encoding=None, errors=None):
+ return codecs.open(filename=file, mode=mode, encoding=encoding,
+ errors=errors, buffering=buffering)
+
# believe it or not, Python has no way to make a simple constant!
MS_PER_S = 1e3 # milliseconds per second
NS_PER_S = 1e9 # nanoseconds per second
@@ -379,13 +385,17 @@ def gnuplot(template, outfile=None):
if outfile is None:
out = None
else:
- out = open(outfile, "w")
+ out = open(outfile, "w", encoding='utf-8')
##
# can be 30% faster to write to a tmp file than to pipe to gnuplot
# bonus, we can keep the plot file for debug.
- tmp_file = tempfile.NamedTemporaryFile(mode='w',
- suffix='.plt', delete=False)
+ if sys.version_info[0] == 2:
+ tmp_file = tempfile.NamedTemporaryFile(mode='w',
+ suffix='.plt', delete=False)
+ else:
+ tmp_file = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8',
+ suffix='.plt', delete=False)
# note that tmp_file is a file handle, it is not a file object
tmp_file.write(template)
tmp_file.close()
@@ -1832,7 +1842,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
header = os.path.join(args.outdir, "header")
if os.path.isfile(header):
try:
- header_file = open(header, 'r')
+ header_file = open(header, 'r', encoding='utf-8')
header_txt = header_file.read()
index_buffer += '<br>\n' + header_txt + '\n'
except IOError:
@@ -1926,7 +1936,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
footer = os.path.join(args.outdir, "footer")
if os.path.isfile(footer):
try:
- footer_file = open(footer, 'r')
+ footer_file = open(footer, 'r', encoding='utf-8')
footer_txt = footer_file.read()
index_buffer += '<br>\n' + footer_txt + '\n'
except IOError:
@@ -1935,12 +1945,12 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
# and send the file buffer
index_filename = os.path.join(args.outdir, "index.html")
- with open(index_filename + ".tmp", "w") as ifile:
+ with open(index_filename + ".tmp", "w", encoding='utf-8') as ifile:
ifile.write(index_buffer)
# create csv file, as a tmp file
csv_filename = os.path.join(args.outdir, "summary.csv")
- with open(csv_filename + ".tmp", "w") as csv_file:
+ with open(csv_filename + ".tmp", "w", encoding='utf-8') as csv_file:
csv_ob = csv.writer(csv_file)
csv_ob.writerow(VizStats.csv_head)
for row in csvs:
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/03176993a0465257270108e21516ff30aa600f51
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/03176993a0465257270108e21516ff30aa600f51
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171126/fa8dce5d/attachment.html>
More information about the vc
mailing list