[Git][NTPsec/ntpsec][master] 2 commits: In Python, when interval added to peer listings.

Eric S. Raymond gitlab at mg.gitlab.com
Sun Oct 23 02:30:48 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
6a8158de by Eric S. Raymond at 2016-10-22T20:47:05-04:00
In Python, when interval added to peer listings.

- - - - -
aa240f9b by Eric S. Raymond at 2016-10-22T22:29:45-04:00
pynptq opeers display: behave more sanely on out-of-bounds dispersion.

- - - - -


2 changed files:

- libntp/pymodule.c
- ntpq/pyntpq


Changes:

=====================================
libntp/pymodule.c
=====================================
--- a/libntp/pymodule.c
+++ b/libntp/pymodule.c
@@ -14,6 +14,7 @@
 #include "ntp_fp.h"
 #include "ntp_stdlib.h"
 #include "ntp_random.h"
+#include "timespecops.h"
 
 #include "ntp_config.h"
 #include "ntp_assert.h"
@@ -58,6 +59,24 @@ libntpc_prettydate(PyObject *self, PyObject *args)
     }
 }
 
+static PyObject *
+libntpc_lfptofloat(PyObject *self, PyObject *args)
+{
+    char *s;
+    l_fp ts;
+    struct timespec tt;
+ 
+    UNUSED_ARG(self);
+    if (!PyArg_ParseTuple(args, "s", &s))
+	return NULL;
+    if (!hextolfp(s+2, &ts)) {
+	PyErr_SetString(PyExc_ValueError, "ill-formed hex date");
+	return NULL;
+    }
+    tt = lfp_stamp_to_tspec(ts, NULL);
+    return Py_BuildValue("d", tt.tv_sec + tt.tv_nsec * 1e-9);
+}
+
 /* List of functions defined in the module */
 
 static PyMethodDef libntpc_methods[] = {
@@ -65,6 +84,8 @@ static PyMethodDef libntpc_methods[] = {
      PyDoc_STR("Status string display from peer status word.")},
     {"prettydate",     	libntpc_prettydate,  	METH_VARARGS,
      PyDoc_STR("Status string display from peer status word.")},
+    {"lfptofloat",     	libntpc_lfptofloat,  	METH_VARARGS,
+     PyDoc_STR("NTP l_fp to Python-style float time.")},
     {NULL,		NULL, 0, NULL}		/* sentinel */
 };
 


=====================================
ntpq/pyntpq
=====================================
--- a/ntpq/pyntpq
+++ b/ntpq/pyntpq
@@ -217,8 +217,8 @@ usage: help [ command ]
 
     # Unexposed helper tables and functions begin here
 
-    __common = "st t when poll reach   delay   offset    "
-    __opeerheader = "     remote           local      " + __common + "disp\n"
+    __common = "st t when poll reach   delay   offset  "
+    __opeerheader = "     remote           local      " + __common + "  disp\n"
     __peerheader  = "     remote           refid      " + __common + "jitter\n"
     __apeerheader = "     remote       refid   assid  " + __common + "jitter\n"
 
@@ -468,15 +468,17 @@ usage: help [ command ]
             else:
                 sys.stdout.write(" " * (addrwidth - len(visible)))
             # The rest of the story
-            #prettyinterval(when(&ts, &rec, &reftime)),
+            last_sync = variables.get("rec") or variables.get("reftime")
+            jd = estjitter if have_jitter else estdisp
+            jd = "      -" if jd >= 999 else ("%7.3f" % jd)
             sys.stdout.write(
-                " %2ld %c %4.4s %4.4s  %3lo  %7.3f %8.3f %7.3f\n" % \
+                " %2ld %c %4.4s %4.4s  %3lo  %7.3f %8.3f %s\n" % \
                 (variables.get("stratum", 0),
                  ptype,
-                 Ntpq.prettyinterval(0),
+                 Ntpq.prettyinterval(now if last_sync is None else int(now - lfptofloat(last_sync))),
                  Ntpq.prettyinterval(poll_sec),
                  reach, estdelay, estoffset,
-                 estjitter if have_jitter else estdisp))
+                 jd))
             return True
         else:
             return True



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/9b017e13de227919eadaf3c79149fc29143932e9...aa240f9b370202e4d46e648216f72927e116f493
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161023/735b33b2/attachment.html>


More information about the vc mailing list