diff options
author | Steven Hiscocks <steven@hiscocks.me.uk> | 2013-02-16 17:31:18 +0000 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-02-22 16:57:44 +0100 |
commit | 7a1b9cd5e43c85a3b1f22a0151ac5b6340fb0d0f (patch) | |
tree | d74b8099de190ff6f7e98e769923fc69b4e0b19a | |
parent | 71766afa2d80ffe1b03c410f6d5ffdc140883314 (diff) |
systemd-python: Moved _reader datetime usage to python
-rw-r--r-- | src/python-systemd/_reader.c | 52 | ||||
-rw-r--r-- | src/python-systemd/journal.py | 10 |
2 files changed, 18 insertions, 44 deletions
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c index 5d743eb562..f1c3175bbf 100644 --- a/src/python-systemd/_reader.c +++ b/src/python-systemd/_reader.c @@ -426,34 +426,12 @@ PyDoc_STRVAR(Journal_seek_realtime__doc__, static PyObject * Journal_seek_realtime(Journal *self, PyObject *args) { - PyObject *arg; - if (! PyArg_ParseTuple(args, "O", &arg)) + uint64_t timestamp; + if (! PyArg_ParseTuple(args, "K", ×tamp)) return NULL; - uint64_t timestamp=-1LL; - if (PyDateTime_Check(arg)) { - PyObject *temp; - char *timestamp_str; - temp = PyObject_CallMethod(arg, "strftime", "s", "%s%f"); -#if PY_MAJOR_VERSION >=3 - PyObject *temp2; - temp2 = PyUnicode_AsUTF8String(temp); - timestamp_str = PyBytes_AsString(temp2); - Py_DECREF(temp2); -#else - timestamp_str = PyString_AsString(temp); -#endif - Py_DECREF(temp); - timestamp = strtoull(timestamp_str, NULL, 10); - }else if (PyLong_Check(arg)) { - timestamp = PyLong_AsUnsignedLongLong(arg); -#if PY_MAJOR_VERSION <3 - }else if (PyInt_Check(arg)) { - timestamp = PyInt_AsUnsignedLongLongMask(arg); -#endif - } if ((int64_t) timestamp < 0LL) { - PyErr_SetString(PyExc_ValueError, "Time must be positive integer or datetime instance"); + PyErr_SetString(PyExc_ValueError, "Time must be positive integer"); return NULL; } @@ -479,30 +457,16 @@ PyDoc_STRVAR(Journal_seek_monotonic__doc__, static PyObject * Journal_seek_monotonic(Journal *self, PyObject *args) { - PyObject *arg; + double timedouble; char *bootid=NULL; - if (! PyArg_ParseTuple(args, "O|s", &arg, &bootid)) + if (! PyArg_ParseTuple(args, "d|z", &timedouble, &bootid)) return NULL; - uint64_t timestamp=-1LL; - if PyDelta_Check(arg) { - PyObject *temp; - temp = PyObject_CallMethod(arg, "total_seconds", NULL); - timestamp = (uint64_t) (PyFloat_AsDouble(temp) * 1E6); - Py_DECREF(temp); - }else if (PyFloat_Check(arg)) { - timestamp = (uint64_t) (PyFloat_AsDouble(arg) * 1E6); - }else if (PyLong_Check(arg)) { - timestamp = PyLong_AsUnsignedLongLong(arg) * (uint64_t) 1E6; -#if PY_MAJOR_VERSION <3 - }else if (PyInt_Check(arg)) { - timestamp = PyInt_AsUnsignedLongLongMask(arg) * (uint64_t) 1E6; -#endif - - } + uint64_t timestamp; + timestamp = (uint64_t) (timedouble * 1.0E6); if ((int64_t) timestamp < 0LL) { - PyErr_SetString(PyExc_ValueError, "Time must be positive number or timedelta instance"); + PyErr_SetString(PyExc_ValueError, "Time must be positive number"); return NULL; } diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py index db35ba2005..46affcee00 100644 --- a/src/python-systemd/journal.py +++ b/src/python-systemd/journal.py @@ -123,6 +123,16 @@ class Journal(_Journal): return set(self._convert_field(key, value) for value in super(Journal, self).query_unique(key)) + def seek_realtime(self, timestamp): + if isinstance(timestamp, datetime.datetime): + timestamp = int(timestamp.strftime("%s%f")) + return super(Journal, self).seek_realtime(timestamp) + + def seek_monotonic(self, timestamp, bootid=None): + if isinstance(timestamp, datetime.timedelta): + timestamp = timestamp.totalseconds() + return super(Journal, self).seek_monotonic(timestamp, bootid) + def log_level(self, level): """Sets maximum log level by setting matches for PRIORITY.""" if 0 <= level <= 7: |