Skip to content
Commits on Source (5)
......@@ -290,14 +290,14 @@ def gnuplot(template, outfile=None):
# 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, tmp_filename = tempfile.mkstemp( suffix='.plt')
tmp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.plt', delete=False)
# note that tmp_file is a file handle, it is not a file object
os.write( tmp_file, template)
os.close(tmp_file)
tmp_file.write(template)
tmp_file.close()
# shell=True is a security hazard, do not use
try:
rcode = subprocess.call( ['gnuplot', tmp_filename], stdout=out)
rcode = subprocess.call(['gnuplot', tmp_file.name], stdout=out)
except OSError as e:
if e.errno == os.errno.ENOENT:
# gnuplot not found
......@@ -309,12 +309,12 @@ def gnuplot(template, outfile=None):
if 0 != rcode:
sys.stderr.write("ntpviz: WARNING: plot returned %s\n" % rcode)
sys.stderr.write("ntpviz: WARNING: plot file %s\n" % tmp_filename)
sys.stderr.write("ntpviz: WARNING: plot file %s\n" % tmp_file.name)
elif 2 <= args.debug_level:
sys.stderr.write("ntpviz: INFO: plot file %s\n" % tmp_filename)
sys.stderr.write("ntpviz: INFO: plot file %s\n" % tmp_file.name)
else:
# remove tmp file
os.remove(tmp_filename)
os.remove(tmp_file.name)
return rcode
......@@ -444,7 +444,7 @@ file.</p>
return ''
tempsmap = self.tempssplit()
tempslist = tempsmap.keys()
tempslist = list(tempsmap.keys())
tempslist.sort()
if not len( tempsmap) or not len( tempslist):
sys.stderr.write("ntpviz: WARNING: no temps to graph\n")
......@@ -525,7 +525,7 @@ file, and field 3 from the temp log .</p>
"Generate gnuplot code graphing local temperature statistics"
sitename = self.sitename
tempsmap = self.tempssplit()
tempslist = tempsmap.keys()
tempslist = list(tempsmap.keys())
tempslist.sort()
if not len( tempsmap) or not len( tempslist):
......@@ -576,7 +576,7 @@ component of frequency drift.</p>
"Generate gnuplot code graphing local GPS statistics"
sitename = self.sitename
gpsmap = self.gpssplit()
gpslist = gpsmap.keys()
gpslist = list(gpsmap.keys())
gpslist.sort()
if not len( gpsmap) or not len( gpslist):
......@@ -758,7 +758,7 @@ plot \
peerdict = self.peersplit()
if not peerlist:
peerlist = peerdict.keys()
peerlist = list(peerdict.keys())
if not len( peerlist):
sys.stderr.write("ntpviz: WARNING: no peer data to graph\n")
return ''
......@@ -1461,13 +1461,13 @@ Python by ESR, concept and gnuplot code by Dan Drown.
# if no ntpsec favicon.ico, write one.
ico_filename = os.path.join(args.outdir, "favicon.ico")
if not os.path.lexists( ico_filename ):
with open( ico_filename, "w" ) as wp:
with open( ico_filename, "wb" ) as wp:
wp.write(binascii.a2b_base64(ntpsec_ico))
# if no ntpsec logo, write one.
logo_filename = os.path.join(args.outdir, "ntpsec-logo.png")
if not os.path.lexists( logo_filename ):
with open( logo_filename, "w" ) as wp:
with open( logo_filename, "wb" ) as wp:
wp.write(binascii.a2b_base64(ntpsec_logo))
report_time = datetime.datetime.utcnow() # the time now is...
......@@ -1645,7 +1645,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
("peer-offsets", stats.peer_offsets_gnuplot()),
]
peerlist = stats.peersplit().keys()
peerlist = list(stats.peersplit().keys())
# sort for output order stability
peerlist.sort()
for key in peerlist:
......@@ -1714,12 +1714,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", "wb") as ifile:
with open(index_filename + ".tmp", "w") 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", "wb" ) as csv_file:
with open( csv_filename + ".tmp", "w" ) as csv_file:
csv_ob = csv.writer(csv_file)
csv_ob.writerow(VizStats.csv_head)
for row in csvs:
......
......@@ -88,9 +88,9 @@ class NTPStats:
if starttime > os.path.getmtime(logpart):
continue
if logpart.endswith("gz"):
lines += gzip.open(logpart, 'rb').readlines()
lines += gzip.open(logpart, 'rt').readlines()
else:
lines += open(logpart, 'rb').readlines()
lines += open(logpart, 'r').readlines()
except IOError:
sys.stderr.write("ntpviz: WARNING: could not read %s\n" \
% logpart)
......