diff options
| author | Steven Hiscocks <steven@hiscocks.me.uk> | 2013-02-15 17:16:56 +0000 |
|---|---|---|
| committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-07-05 14:19:15 -0400 |
| commit | 55c89e4680e58245438c5abd6147151f3d3a4050 (patch) | |
| tree | 2b1b584db81db318b7b556d5e8dc3c2bd041cbe9 /systemd | |
| parent | 87531b51f5530583c916a645790208f5216e4089 (diff) | |
| download | python-systemd-55c89e4680e58245438c5abd6147151f3d3a4050.tar.gz | |
systemd-python: implement this_boot/this_machine in Python
Diffstat (limited to 'systemd')
| -rw-r--r-- | systemd/_reader.c | 68 | ||||
| -rw-r--r-- | systemd/journal.py | 9 |
2 files changed, 9 insertions, 68 deletions
diff --git a/systemd/_reader.c b/systemd/_reader.c index ce66317..06bdf16 100644 --- a/systemd/_reader.c +++ b/systemd/_reader.c @@ -671,70 +671,6 @@ Journal_query_unique(Journal *self, PyObject *args) } #endif //def SD_JOURNAL_FOREACH_UNIQUE -PyDoc_STRVAR(Journal_this_boot__doc__, -"this_boot() -> None\n\n" -"Sets match filter for the current _BOOT_ID."); -static PyObject * -Journal_this_boot(Journal *self, PyObject *args) -{ - sd_id128_t sd_id; - int r; - r = sd_id128_get_boot(&sd_id); - if (r == -EIO) { - PyErr_SetString(PyExc_IOError, "Error getting current boot ID"); - return NULL; - } else if (r < 0) { - PyErr_SetString(PyExc_RuntimeError, "Error getting current boot ID"); - return NULL; - } - - char bootid[33]; - sd_id128_to_string(sd_id, bootid); - - PyObject *arg, *keywds; - arg = PyTuple_New(0); - keywds = Py_BuildValue("{s:s}", "_BOOT_ID", bootid); - Journal_add_match(self, arg, keywds); - Py_DECREF(arg); - Py_DECREF(keywds); - if (PyErr_Occurred()) - return NULL; - - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Journal_this_machine__doc__, -"this_machine() -> None\n\n" -"Sets match filter for the current _MACHINE_ID."); -static PyObject * -Journal_this_machine(Journal *self, PyObject *args) -{ - sd_id128_t sd_id; - int r; - r = sd_id128_get_machine(&sd_id); - if (r == -EIO) { - PyErr_SetString(PyExc_IOError, "Error getting current boot ID"); - return NULL; - } else if (r < 0) { - PyErr_SetString(PyExc_RuntimeError, "Error getting current boot ID"); - return NULL; - } - - char machineid[33]; - sd_id128_to_string(sd_id, machineid); - - PyObject *arg, *keywds; - arg = PyTuple_New(0); - keywds = Py_BuildValue("{s:s}", "_MACHINE_ID", machineid); - Journal_add_match(self, arg, keywds); - Py_DECREF(arg); - Py_DECREF(keywds); - if (PyErr_Occurred()) - return NULL; - - Py_RETURN_NONE; -} - static PyObject * Journal_get_data_threshold(Journal *self, void *closure) { @@ -818,10 +754,6 @@ static PyMethodDef Journal_methods[] = { {"query_unique", (PyCFunction)Journal_query_unique, METH_VARARGS, Journal_query_unique__doc__}, #endif - {"this_boot", (PyCFunction)Journal_this_boot, METH_NOARGS, - Journal_this_boot__doc__}, - {"this_machine", (PyCFunction)Journal_this_machine, METH_NOARGS, - Journal_this_machine__doc__}, {NULL} /* Sentinel */ }; diff --git a/systemd/journal.py b/systemd/journal.py index 40e40c3..533a875 100644 --- a/systemd/journal.py +++ b/systemd/journal.py @@ -31,6 +31,7 @@ from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, from ._journal import sendv, stream_fd from ._reader import (_Journal, NOP, APPEND, INVALIDATE, LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY) +from . import id128 as _id128 _MONOTONIC_CONVERTER = lambda x: datetime.timedelta(microseconds=float(x)) _REALTIME_CONVERTER = lambda x: datetime.datetime.fromtimestamp(float(x)/1E6) @@ -123,6 +124,14 @@ class Journal(_Journal): else: raise ValueError("Log level must be 0 <= level <= 7") + def this_boot(self): + """Add match for _BOOT_ID equal to current boot ID.""" + self.add_match(_BOOT_ID=_id128.get_boot().hex) + + def this_machine(self): + """Add match for _MACHINE_ID equal to the ID of this machine.""" + self.add_match(_MACHINE_ID=_id128.get_machine().hex) + def _make_line(field, value): if isinstance(value, bytes): return field.encode('utf-8') + b'=' + value |
