They should apply in any order.
>From 223d51f05069c6ff888db8f35e1d402894245b9d Mon Sep 17 00:00:00 2001
From: James Browning <jamesb.f...@gmail.com>
Date: Tue, 1 Jul 2025 12:21:26 -0700
Subject: [PATCH] ntpviz: Adjust some white space.

---
 ntpclients/ntpviz.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ntpclients/ntpviz.py b/ntpclients/ntpviz.py
index ba758c5df..598fbc3d4 100644
--- a/ntpclients/ntpviz.py
+++ b/ntpclients/ntpviz.py
@@ -74,8 +74,8 @@ if sys.version_info[0] == 2:
 
     def open(file, mode='r', buffering=-1, encoding=None, errors=None):
         "Redefine open()"
-        return(codecs.open(filename=file, mode=mode, encoding=encoding,
-               errors=errors, buffering=buffering))
+        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
@@ -1575,7 +1575,7 @@ Python by ESR, concept and gnuplot code by Dan Drown.
                 'png': '.png',
                 'svg': '.svg',
                 'webp': '.webp',
-               }
+                }
     if args.terminal in term_map:
         args.img_ext = term_map[args.terminal]
     else:
-- 
2.50.0

>From 5e024a1ba072736b0a53915f6e9c5c9902e37606 Mon Sep 17 00:00:00 2001
From: James Browning <jamesb.f...@gmail.com>
Date: Mon, 30 Jun 2025 18:59:28 -0700
Subject: [PATCH] ntpviz: Add meta tags at chromiums behest.

---
 ntpclients/ntpviz.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ntpclients/ntpviz.py b/ntpclients/ntpviz.py
index ba758c5df..bd98e8290 100644
--- a/ntpclients/ntpviz.py
+++ b/ntpclients/ntpviz.py
@@ -1764,7 +1764,9 @@ Python by ESR, concept and gnuplot code by Dan Drown.
 <link rel="shortcut icon" href="favicon.ico">
 <meta charset="UTF-8">
 <meta http-equiv="refresh" content="1800">
+<meta name="description" content="Visualize statistics from NTPsec log files.">
 <meta name="expires" content="0">
+<meta name="viewport" content="width=device-width, initial-scale=1">
 <title>%(title)s</title>
 <style>
 dt {
-- 
2.50.0

>From 0b591eb06bce7b969bd2c9a64ad438f9b15fe126 Mon Sep 17 00:00:00 2001
From: James Browning <jamesb.f...@gmail.com>
Date: Tue, 1 Jul 2025 05:52:50 -0700
Subject: [PATCH] ntpviz: Make some conditionals Yoda style

---
 ntpclients/ntpviz.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/ntpclients/ntpviz.py b/ntpclients/ntpviz.py
index ba758c5df..f6e4cf988 100644
--- a/ntpclients/ntpviz.py
+++ b/ntpclients/ntpviz.py
@@ -65,7 +65,7 @@ ntpviz: ERROR:  can't find the Python argparse module
 """)
     sys.exit(1)
 
-if sys.version_info[0] == 2:
+if 2 == sys.version_info[0]:
     import codecs
 
     # force UTF-8 strings, otherwise some systems crash on micro.
@@ -434,7 +434,7 @@ 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.
-    if sys.version_info[0] == 2:
+    if 2 == sys.version_info[0]:
         tmp_file = tempfile.NamedTemporaryFile(mode='w',
                                                suffix='.plt', delete=False)
     else:
@@ -1020,7 +1020,7 @@ plot \
         rtt = 0
         percentages = ""
         stats = []
-        if len(peerlist) == 1:
+        if 1 == len(peerlist):
             # only one peer
             if "offset" == ptype:
                 # doing offset, not jitter
@@ -1135,7 +1135,7 @@ at 0s.</p>
                 plot_data += pt[0]
 
         stats = VizStats(pt[1], title)
-        if len(peerlist) == 1:
+        if 1 == len(peerlist):
             percentages = " %(p50)s title '50th percentile', " % stats.percs
         else:
             # skip stats on peers/offsets plots
@@ -1185,7 +1185,7 @@ plot \
             # strip the trailing ", \n"
             plot_template = plot_template[:-4] + "\n"
 
-        if len(peerlist) == 1:
+        if 1 == len(peerlist):
             # skip stats for multiplots
             html = VizStats.table_head + stats.table \
                 + VizStats.table_tail + exp,
@@ -1412,7 +1412,7 @@ AAAAgAAAAL/+AADf/QAAwAEAAO/7AADsGwAA6+sAAOsrAADrawAA6+sAAOwbAADv+wAA4AMAAN/9
 AADRxQAAxBEAAA==
 """
 
-if __name__ == '__main__':
+if '__main__' == __name__:
     bin_ver = "ntpsec-@NTPSEC_VERSION_EXTENDED@"
     ntp.util.stdversioncheck(bin_ver)
 
@@ -1668,7 +1668,7 @@ Python by ESR, concept and gnuplot code by Dan Drown.
                            endtime=args.endtime)
                     for d in args.statsdirs]
 
-    if len(statlist) == 1:
+    if 1 == len(statlist):
         stats = statlist[0]
 
         if args.show_local_offset or \
@@ -1811,7 +1811,7 @@ tbody tr:nth-child(6n+6) {
 ''' % locals()
 
     # Ugh.  Not clear what to do in the multiplot case
-    if len(statlist) == 1:
+    if 1 == len(statlist):
         try:
             start_time = datetime.datetime.fromtimestamp(
                 stats.starttime, datetime.timezone.utc).strftime('%c')
-- 
2.50.0

>From 4c9a23148f51c2c4116ba3a907c1ec2fc9532a40 Mon Sep 17 00:00:00 2001
From: James Browning <jamesb.f...@gmail.com>
Date: Tue, 1 Jul 2025 15:28:20 -0700
Subject: [PATCH] ntpviz: correct usaage for no os.errno ever.

---
 ntpclients/ntpviz.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ntpclients/ntpviz.py b/ntpclients/ntpviz.py
index ba758c5df..4a589db9f 100644
--- a/ntpclients/ntpviz.py
+++ b/ntpclients/ntpviz.py
@@ -48,6 +48,7 @@ import binascii
 import collections
 import csv
 import datetime
+import errno
 import math
 import re
 import os
@@ -448,7 +449,7 @@ def gnuplot(template, outfile=None):
     try:
         rcode = subprocess.call(['gnuplot', tmp_file.name], stdout=out)
     except OSError as e:
-        if e.errno == os.errno.ENOENT:
+        if errno.ENOENT == e.errno:
             # gnuplot not found
             sys.stderr.write("ntpviz: ERROR: gnuplot not found in path\n")
         else:
-- 
2.50.0

>From 7efe75431951f8c34154a2af06be24bdc331895f Mon Sep 17 00:00:00 2001
From: James Browning <jamesb.f...@gmail.com>
Date: Mon, 30 Jun 2025 19:01:26 -0700
Subject: [PATCH] ntpviz: Add height and width to graphs at chromiums behest.

---
 ntpclients/ntpviz.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ntpclients/ntpviz.py b/ntpclients/ntpviz.py
index ba758c5df..388f52cdf 100644
--- a/ntpclients/ntpviz.py
+++ b/ntpclients/ntpviz.py
@@ -1956,7 +1956,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/";>NTPsec project</a>
 </body>
 </html>
 '''
-    imagewrapper = "<img src='%%s%s' alt='%%s plot'>\n" % args.img_ext
+    imagewrapper = "<img src='%%s%s' alt='%%s plot' width='%%d' height='%%d>\n" % args.img_ext
 
     # buffer the index.html output so the index.html is not empty
     # during the run
@@ -2002,6 +2002,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/";>NTPsec project</a>
                                stats.peer_jitters_gnuplot([key])))
 
         stats = []
+        _w, _h = [int(s) for s in args.img_size.split(',')]
         for (imagename, image) in imagepairs:
             if not image:
                 continue
@@ -2018,7 +2019,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/";>NTPsec project</a>
             div_name = imagename.replace('-', ' ')
             # Windows hates colons in filename
             imagename = imagename.replace(':', '-')
-            index_buffer += imagewrapper % (imagename, div_name)
+            index_buffer += imagewrapper % (imagename, div_name, _w, _h)
 
             if image['html']:
                 index_buffer += "<div>\n%s</div>\n" % image['html']
-- 
2.50.0

>From e1a729b9125fa7f94528287b6c8370fdbda57c00 Mon Sep 17 00:00:00 2001
From: James Browning <jamesb.f...@gmail.com>
Date: Tue, 1 Jul 2025 05:54:43 -0700
Subject: [PATCH] ntp.ntpstats, ntpviz: change refclock name punting code

---
 ntpclients/ntpviz.py          | 23 -----------------------
 pylib/statfiles.py            | 21 +++++++++++++++++++++
 tests/pylib/test_statfiles.py |  4 +++-
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/ntpclients/ntpviz.py b/ntpclients/ntpviz.py
index ba758c5df..98081ec6e 100644
--- a/ntpclients/ntpviz.py
+++ b/ntpclients/ntpviz.py
@@ -85,25 +85,6 @@ S_PER_MS = 1.0e-3       # seconds per millisecond
 S_PER_NS = 1.0e-9       # seconds per nanosecond
 S_PER_US = 1.0e-6       # seconds per microsecond
 
-# table to translate refclock names
-refclock_name = {'127.127.20.0': 'NMEA(0)',
-                 '127.127.20.1': 'NMEA(1)',
-                 '127.127.20.2': 'NMEA(2)',
-                 '127.127.20.3': 'NMEA(3)',
-                 '127.127.22.0': 'PPS(0)',
-                 '127.127.22.1': 'PPS(1)',
-                 '127.127.22.2': 'PPS(2)',
-                 '127.127.22.3': 'PPS(3)',
-                 '127.127.28.0': 'SHM(0)',
-                 '127.127.28.1': 'SHM(1)',
-                 '127.127.28.2': 'SHM(2)',
-                 '127.127.28.3': 'SHM(3)',
-                 '127.127.46.0': 'GPS(0)',
-                 '127.127.46.1': 'GPS(1)',
-                 '127.127.46.2': 'GPS(2)',
-                 '127.127.46.3': 'GPS(3)'}
-
-
 # Gack, python before 3.2 has no defined tzinfo for utc...
 # define our own
 class UTC(datetime.tzinfo):
@@ -1117,10 +1098,6 @@ at 0s.</p>
 <p>RMS Jitter is field 8 in the peerstats log file.</p>
 """
 
-        if len(peerlist) == 1:
-            if peerlist[0] in refclock_name:
-                title += ' ' + refclock_name[peerlist[0]]
-
         plot_data = ""
         for ip in ip_todo:
             # 20% speed up by only sending gnuplot the data it will
diff --git a/pylib/statfiles.py b/pylib/statfiles.py
index 62ee54ce8..00ac628f0 100644
--- a/pylib/statfiles.py
+++ b/pylib/statfiles.py
@@ -22,6 +22,25 @@ import sys
 import time
 
 
+refclocks = {
+    '1': 'local',
+    '4': 'spectracom',  # D2
+    '5': 'truetime',  # D2
+    '8': 'generic',
+    '11': 'arbiter',  # D2
+    '18': 'modem',
+    '20': 'nmea',  # T
+    '22': 'pps',  # T
+    '26': 'hpgps',  # T
+    '28': 'shm',  # T
+    '29': 'trimble',  # D
+    '30': 'oncore',  # D2
+    '40': 'jjy',  # T
+    '42': 'zyfer',
+    '46': 'gpsd,',  # T
+}
+
+
 class NTPStats:
     "Gather statistics for a specified NTP site"
     SecondsInDay = 24*60*60
@@ -100,6 +119,8 @@ class NTPStats:
             # driver type here.
             if key.startswith("127.127."):
                 (_, _, clock_type, unit) = key.split(".")
+                if clock_type in refclocks:
+                    return '%s(%s)' % (refclocks[clock_type], unit)
                 return "REFCLOCK(type=%s,unit=%s)" % (clock_type, unit)
             # Ordinary IP address - replace with primary hostname.
             # Punt if the lookup fails.
diff --git a/tests/pylib/test_statfiles.py b/tests/pylib/test_statfiles.py
index 9019c9a2a..a3d055557 100644
--- a/tests/pylib/test_statfiles.py
+++ b/tests/pylib/test_statfiles.py
@@ -122,7 +122,9 @@ class TestNTPStats(unittest.TestCase):
             self.assertEqual(f("1.2.3.4"), "1.2.3.4")
             # Test old style NTP
             fakesockmod.ghba_returns = [("foo.org", None, None)]
-            self.assertEqual(f("127.127.42.23"), "REFCLOCK(type=42,unit=23)")
+            self.assertEqual(f("127.127.42.23"), "zyfer(23)")
+            fakesockmod.ghba_returns = [("foo.org", None, None)]
+            self.assertEqual(f("127.127.41.23"), "REFCLOCK(type=41,unit=23)")
         finally:
             ntp.statfiles.socket = socktemp
 
-- 
2.50.0

_______________________________________________
devel mailing list
devel@ntpsec.org
https://lists.ntpsec.org/mailman/listinfo/devel

Reply via email to