[Git][NTPsec/ntpsec][master] Add prettydate to Python extension to use it in pyntpq.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Oct 20 20:37:43 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
24c9f583 by Eric S. Raymond at 2016-10-20T16:37:34-04:00
Add prettydate to Python extension to use it in pyntpq.
- - - - -
4 changed files:
- libntp/prettydate.c
- libntp/pymodule.c
- libntp/wscript
- ntpq/pyntpq
Changes:
=====================================
libntp/prettydate.c
=====================================
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -8,7 +8,6 @@
#include "ntp_fp.h"
#include "lib_strbuf.h"
#include "ntp_stdlib.h"
-#include "ntp_assert.h"
#include "ntp_calendar.h"
#if SIZEOF_TIME_T < 4
@@ -106,7 +105,6 @@ get_struct_tm(
return NULL; /* That's truly pathological! */
/* 'tm' surely not NULL here! */
- NTP_INSIST(tm != NULL);
if (folds != 0) {
tm->tm_year += folds * SOLAR_CYCLE_YEARS;
if (tm->tm_year <= 0 || tm->tm_year >= 200)
=====================================
libntp/pymodule.c
=====================================
--- a/libntp/pymodule.c
+++ b/libntp/pymodule.c
@@ -1,6 +1,6 @@
/*
- * This file is Copyright (c) 2010 by the GPSD project
- * BSD terms apply: see the file COPYING in the distribution root for details.
+ * This file is Copyright (c) 2016 by the NTPsec project
+ * SPDX-License-Identifier: BSD-2-clause
*
* Python binding for selected libntp library functions
*/
@@ -11,6 +11,7 @@
#include "ntp_machine.h"
#include "ntpd.h"
#include "ntp_io.h"
+#include "ntp_fp.h"
#include "ntp_stdlib.h"
#include "ntp_random.h"
@@ -40,11 +41,30 @@ libntpc_statustoa(PyObject *self, PyObject *args)
return Py_BuildValue("s", gs);
}
+static PyObject *
+libntpc_prettydate(PyObject *self, PyObject *args)
+{
+ char *s;
+ l_fp ts;
+
+ UNUSED_ARG(self);
+ if (!PyArg_ParseTuple(args, "s", &s))
+ return NULL;
+ if (hextolfp(s+2, &ts))
+ return Py_BuildValue("s", prettydate(&ts));
+ else {
+ PyErr_SetString(PyExc_ValueError, "ill-formed hex date");
+ return NULL;
+ }
+}
+
/* List of functions defined in the module */
static PyMethodDef libntpc_methods[] = {
{"statustoa", libntpc_statustoa, METH_VARARGS,
PyDoc_STR("Status string display from peer status word.")},
+ {"prettydate", libntpc_prettydate, METH_VARARGS,
+ PyDoc_STR("Status string display from peer status word.")},
{NULL, NULL, 0, NULL} /* sentinel */
};
=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -16,7 +16,6 @@ def build(ctx):
"dolfptoa.c",
"emalloc.c",
"getopt.c",
- "hextolfp.c",
"humandate.c",
"initnetwork.c",
"lib_strbuf.c",
@@ -25,7 +24,6 @@ def build(ctx):
"mstolfp.c",
"msyslog.c",
"netof.c",
- "ntp_calendar.c",
"ntp_endian.c",
"ntp_intres.c",
"ntp_lineedit.c",
@@ -33,7 +31,6 @@ def build(ctx):
"ntp_worker.c",
"numtoa.c",
"numtohost.c",
- "prettydate.c",
"recvbuff.c",
"refidsmear.c",
"socket.c",
@@ -49,7 +46,10 @@ def build(ctx):
]
libntp_source_sharable = [
+ "hextolfp.c",
"lib_strbuf.c",
+ "ntp_calendar.c",
+ "prettydate.c",
"statestr.c",
]
=====================================
ntpq/pyntpq
=====================================
--- a/ntpq/pyntpq
+++ b/ntpq/pyntpq
@@ -182,10 +182,6 @@ tstflagnames = (
"peer_unreach" # BOGON13
)
-def prettydate(d):
- # FIXME: we need to unpack this date.
- return d[2:]
-
class Ntpq(cmd.Cmd):
"ntpq command interpreter"
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/24c9f583a93abe2ee6d32b679e2dc2f4c2c5bda2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161020/d6309d7a/attachment.html>
More information about the vc
mailing list