1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

systemd-python: add journal.get_catalog()

This one wraps sd_journal_get_catalog_from_message_id.
Thanks to Python namespacing, we can stick to a shorter name.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2013-03-15 18:10:51 -04:00
parent 6808412dad
commit 2b01924cda
3 changed files with 48 additions and 9 deletions

1
TODO
View File

@ -581,7 +581,6 @@ Features:
* drop cap bounding set in readahead and other services
* systemd-python:
- export sd_journal_get_catalog_for_message_id (in systemd.id128)
- allow reading of only select fields in systemd.journal._reader.Reader
- export sd_journal_test_cursor in systemd.journal._reader.Reader
- export sd_journal_get_usage in systemd.journal._reader.Reader

View File

@ -50,6 +50,11 @@ static int set_error(int r, const char* path, const char* invalid_message) {
return -1;
}
PyDoc_STRVAR(module__doc__,
"Class to reads the systemd journal similar to journalctl.");
#if PY_MAJOR_VERSION >= 3
static PyTypeObject MonotonicType;
@ -657,6 +662,37 @@ static PyObject* Reader_get_catalog(Reader *self, PyObject *args)
}
PyDoc_STRVAR(get_catalog__doc__,
"get_catalog(id128) -> str\n\n"
"Retrieve a message catalog entry for the given id.\n"
"Wraps man:sd_journal_get_catalog_for_message_id(3).");
static PyObject* get_catalog(PyObject *self, PyObject *args)
{
int r;
char *id_ = NULL;
sd_id128_t id;
char _cleanup_free_ *msg = NULL;
assert(!self);
assert(args);
if (!PyArg_ParseTuple(args, "z", &id_))
return NULL;
r = sd_id128_from_string(id_, &id);
if (set_error(r, NULL, "Invalid id128"))
return NULL;
Py_BEGIN_ALLOW_THREADS
r = sd_journal_get_catalog_for_message_id(id, &msg);
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL))
return NULL;
return unicode_FromString(msg);
}
PyDoc_STRVAR(data_threshold__doc__,
"Threshold for field size truncation in bytes.\n\n"
"Fields longer than this will be truncated to the threshold size.\n"
@ -774,16 +810,19 @@ static PyTypeObject ReaderType = {
PyType_GenericNew, /* tp_new */
};
#define SUMMARY \
"Module that reads the systemd journal similar to journalctl."
static PyMethodDef methods[] = {
{ "get_catalog", get_catalog, METH_VARARGS, get_catalog__doc__},
{ NULL, NULL, 0, NULL } /* Sentinel */
};
#if PY_MAJOR_VERSION >= 3
static PyModuleDef _reader_module = {
static PyModuleDef module = {
PyModuleDef_HEAD_INIT,
"_reader",
SUMMARY,
module__doc__,
-1,
NULL, NULL, NULL, NULL, NULL
methods,
NULL, NULL, NULL, NULL
};
#endif
@ -813,7 +852,7 @@ init_reader(void)
#endif
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&_reader_module);
m = PyModule_Create(&module);
if (m == NULL)
return NULL;
@ -822,7 +861,7 @@ init_reader(void)
initialized = true;
}
#else
m = Py_InitModule3("_reader", NULL, SUMMARY);
m = Py_InitModule3("_reader", methods, module__doc__);
if (m == NULL)
return;
#endif

View File

@ -34,7 +34,8 @@ from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
from ._journal import sendv, stream_fd
from ._reader import (_Reader, NOP, APPEND, INVALIDATE,
LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY)
LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY,
get_catalog)
from . import id128 as _id128
if _sys.version_info >= (3,):