summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
50a279f)
The behaviour wrt. seconds vs. microseconds was inconsistent.
Now _Reader always uses native units (us), while Reader always
uses seconds and accepts both floats and ints. This way the
conversion is always done in the Python layer, and the lower
level API allows access to the journal API without the potentially
lossy conversion between double and uint64_t.
PyDoc_STRVAR(Reader_seek_realtime__doc__,
"seek_realtime(realtime) -> None\n\n"
"Seek to nearest matching journal entry to `realtime`. Argument\n"
PyDoc_STRVAR(Reader_seek_realtime__doc__,
"seek_realtime(realtime) -> None\n\n"
"Seek to nearest matching journal entry to `realtime`. Argument\n"
- "`realtime` can must be an integer unix timestamp.");
+ "`realtime` in specified in seconds.");
static PyObject* Reader_seek_realtime(Reader *self, PyObject *args)
{
static PyObject* Reader_seek_realtime(Reader *self, PyObject *args)
{
uint64_t timestamp;
int r;
uint64_t timestamp;
int r;
- if (!PyArg_ParseTuple(args, "d:_Reader.seek_realtime", &timedouble))
+ if (!PyArg_ParseTuple(args, "K:seek_realtime", ×tamp))
- timestamp = (uint64_t) (timedouble * 1.0E6);
- if ((int64_t) timestamp < 0LL) {
- PyErr_SetString(PyExc_ValueError, "Time must be a positive integer");
- return NULL;
- }
-
Py_BEGIN_ALLOW_THREADS
r = sd_journal_seek_realtime_usec(self->j, timestamp);
Py_END_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
r = sd_journal_seek_realtime_usec(self->j, timestamp);
Py_END_ALLOW_THREADS
PyDoc_STRVAR(Reader_seek_monotonic__doc__,
"seek_monotonic(monotonic[, bootid]) -> None\n\n"
"Seek to nearest matching journal entry to `monotonic`. Argument\n"
PyDoc_STRVAR(Reader_seek_monotonic__doc__,
"seek_monotonic(monotonic[, bootid]) -> None\n\n"
"Seek to nearest matching journal entry to `monotonic`. Argument\n"
- "`monotonic` is an timestamp from boot in seconds.\n"
+ "`monotonic` is an timestamp from boot in microseconds.\n"
"Argument `bootid` is a string representing which boot the\n"
"monotonic time is reference to. Defaults to current bootid.");
static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args)
{
"Argument `bootid` is a string representing which boot the\n"
"monotonic time is reference to. Defaults to current bootid.");
static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args)
{
char *bootid = NULL;
uint64_t timestamp;
sd_id128_t id;
int r;
char *bootid = NULL;
uint64_t timestamp;
sd_id128_t id;
int r;
- if (!PyArg_ParseTuple(args, "d|z:_Reader.seek_monotonic", &timedouble, &bootid))
- return NULL;
-
- timestamp = (uint64_t) (timedouble * 1.0E6);
-
- if ((int64_t) timestamp < 0LL) {
- PyErr_SetString(PyExc_ValueError, "Time must be positive number");
+ if (!PyArg_ParseTuple(args, "K|z:seek_monotonic", ×tamp, &bootid))
if (bootid) {
r = sd_id128_from_string(bootid, &id);
if (bootid) {
r = sd_id128_from_string(bootid, &id);
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL))
return NULL;
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL))
return NULL;
PyDoc_STRVAR(Reader_wait__doc__,
"wait([timeout]) -> state change (integer)\n\n"
"Wait for a change in the journal. Argument `timeout` specifies\n"
PyDoc_STRVAR(Reader_wait__doc__,
"wait([timeout]) -> state change (integer)\n\n"
"Wait for a change in the journal. Argument `timeout` specifies\n"
- "the maximum number of seconds to wait before returning\n"
- "regardless of wheter the journal has changed. If `timeout` is not given\n"
- "or is 0, then block forever.\n"
+ "the maximum number of microseconds to wait before returning\n"
+ "regardless of wheter the journal has changed. If `timeout` is -1,\n"
+ "then block forever.\n\n"
"Will return constants: NOP if no change; APPEND if new\n"
"entries have been added to the end of the journal; and\n"
"INVALIDATE if journal files have been added or removed.");
"Will return constants: NOP if no change; APPEND if new\n"
"entries have been added to the end of the journal; and\n"
"INVALIDATE if journal files have been added or removed.");
-static PyObject* Reader_wait(Reader *self, PyObject *args, PyObject *keywds)
+static PyObject* Reader_wait(Reader *self, PyObject *args)
- if (!PyArg_ParseTuple(args, "|L:_Reader.wait", &timeout))
+ if (!PyArg_ParseTuple(args, "|L:wait", &timeout))
return NULL;
Py_BEGIN_ALLOW_THREADS
return NULL;
Py_BEGIN_ALLOW_THREADS
- r = sd_journal_wait(self->j,
- timeout == 0 ? (uint64_t) -1 : timeout * 1E6);
+ r = sd_journal_wait(self->j, timeout);
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL) < 0)
return NULL;
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL) < 0)
return NULL;
return _datetime.timedelta(microseconds=int(s))
def _convert_realtime(t):
return _datetime.timedelta(microseconds=int(s))
def _convert_realtime(t):
- return _datetime.datetime.fromtimestamp(t / 1E6)
+ return _datetime.datetime.fromtimestamp(t / 1000000)
def _convert_timestamp(s):
def _convert_timestamp(s):
- return _datetime.datetime.fromtimestamp(int(s) / 1E6)
+ return _datetime.datetime.fromtimestamp(int(s) / 1000000)
if _sys.version_info >= (3,):
def _convert_uuid(s):
if _sys.version_info >= (3,):
def _convert_uuid(s):
return set(self._convert_field(field, value)
for value in super(Reader, self).query_unique(field))
return set(self._convert_field(field, value)
for value in super(Reader, self).query_unique(field))
+ def wait(self, timeout=None):
+ """Wait for a change in the journal. `timeout` is the maximum
+ time in seconds to wait, or None, to wait forever.
+
+ Returns one of NOP (no change), APPEND (new entries have been
+ added to the end of the journal), or INVALIDATE (journal files
+ have been added or removed).
+ """
+ us = -1 if timeout is None else int(timeout * 1000000)
+ return super(Reader, self).wait(timeout)
+
def seek_realtime(self, realtime):
"""Seek to a matching journal entry nearest to `realtime` time.
def seek_realtime(self, realtime):
"""Seek to a matching journal entry nearest to `realtime` time.
or datetime.datetime instance.
"""
if isinstance(realtime, _datetime.datetime):
or datetime.datetime instance.
"""
if isinstance(realtime, _datetime.datetime):
- realtime = float(realtime.strftime("%s.%f"))
- return super(Reader, self).seek_realtime(realtime)
+ realtime = float(realtime.strftime("%s.%f")) * 1000000
+ return super(Reader, self).seek_realtime(int(realtime))
def seek_monotonic(self, monotonic, bootid=None):
"""Seek to a matching journal entry nearest to `monotonic` time.
def seek_monotonic(self, monotonic, bootid=None):
"""Seek to a matching journal entry nearest to `monotonic` time.
"""
if isinstance(monotonic, _datetime.timedelta):
monotonic = monotonic.totalseconds()
"""
if isinstance(monotonic, _datetime.timedelta):
monotonic = monotonic.totalseconds()
+ monotonic = int(monotonic * 1000000)
if isinstance(bootid, _uuid.UUID):
bootid = bootid.get_hex()
return super(Reader, self).seek_monotonic(monotonic, bootid)
if isinstance(bootid, _uuid.UUID):
bootid = bootid.get_hex()
return super(Reader, self).seek_monotonic(monotonic, bootid)