|
38 | 38 | # define SD_JOURNAL_CURRENT_USER 8 |
39 | 39 | #endif |
40 | 40 |
|
| 41 | +#if LIBSYSTEMD_VERSION >= 229 |
| 42 | +# define HAVE_ENUMERATE_FIELDS |
| 43 | +#endif |
| 44 | + |
41 | 45 | typedef struct { |
42 | 46 | PyObject_HEAD |
43 | 47 | sd_journal *j; |
@@ -826,7 +830,8 @@ static PyObject* Reader_test_cursor(Reader *self, PyObject *args) { |
826 | 830 | PyDoc_STRVAR(Reader_query_unique__doc__, |
827 | 831 | "query_unique(field) -> a set of values\n\n" |
828 | 832 | "Return a set of unique values appearing in journal for the\n" |
829 | | - "given `field`. Note this does not respect any journal matches."); |
| 833 | + "given `field`. Note this does not respect any journal matches.\n" |
| 834 | + "See sd_journal_query_unique(3)."); |
830 | 835 | static PyObject* Reader_query_unique(Reader *self, PyObject *args) { |
831 | 836 | char *query; |
832 | 837 | int r; |
@@ -877,6 +882,48 @@ static PyObject* Reader_query_unique(Reader *self, PyObject *args) { |
877 | 882 | return value_set; |
878 | 883 | } |
879 | 884 |
|
| 885 | +PyDoc_STRVAR(Reader_enumerate_fields__doc__, |
| 886 | + "enumerate_fields(field) -> a set of values\n\n" |
| 887 | + "Return a set of field names appearing in the journal.\n" |
| 888 | + "See sd_journal_enumerate_fields(3)."); |
| 889 | +static PyObject* Reader_enumerate_fields(Reader *self, PyObject *args) { |
| 890 | +#ifdef HAVE_ENUMERATE_FIELDS |
| 891 | + _cleanup_Py_DECREF_ PyObject *_value_set = NULL; |
| 892 | + PyObject *value_set; |
| 893 | + int r; |
| 894 | + |
| 895 | + value_set = _value_set = PySet_New(0); |
| 896 | + if (!value_set) |
| 897 | + return NULL; |
| 898 | + |
| 899 | + sd_journal_restart_fields(self->j); |
| 900 | + |
| 901 | + while (true) { |
| 902 | + const char *field; |
| 903 | + _cleanup_Py_DECREF_ PyObject *value = NULL; |
| 904 | + |
| 905 | + r = sd_journal_enumerate_fields(self->j, &field); |
| 906 | + if (r == 0) |
| 907 | + break; |
| 908 | + if (set_error(r, NULL, "Field enumeration failed") < 0) |
| 909 | + return NULL; |
| 910 | + |
| 911 | + value = PyBytes_FromString(field); |
| 912 | + if (!value) |
| 913 | + return NULL; |
| 914 | + |
| 915 | + if (PySet_Add(value_set, value) < 0) |
| 916 | + return NULL; |
| 917 | + } |
| 918 | + |
| 919 | + _value_set = NULL; |
| 920 | + return value_set; |
| 921 | +#else |
| 922 | + set_error(-ENOSYS, NULL, "Not implemented"); |
| 923 | + return NULL; |
| 924 | +#endif |
| 925 | +} |
| 926 | + |
880 | 927 | PyDoc_STRVAR(Reader_get_catalog__doc__, |
881 | 928 | "get_catalog() -> str\n\n" |
882 | 929 | "Retrieve a message catalog entry for the current journal entry.\n" |
@@ -1001,36 +1048,37 @@ static PyGetSetDef Reader_getsetters[] = { |
1001 | 1048 | }; |
1002 | 1049 |
|
1003 | 1050 | static PyMethodDef Reader_methods[] = { |
1004 | | - {"fileno", (PyCFunction) Reader_fileno, METH_NOARGS, Reader_fileno__doc__}, |
1005 | | - {"reliable_fd", (PyCFunction) Reader_reliable_fd, METH_NOARGS, Reader_reliable_fd__doc__}, |
1006 | | - {"get_events", (PyCFunction) Reader_get_events, METH_NOARGS, Reader_get_events__doc__}, |
1007 | | - {"get_timeout", (PyCFunction) Reader_get_timeout, METH_NOARGS, Reader_get_timeout__doc__}, |
1008 | | - {"get_timeout_ms", (PyCFunction) Reader_get_timeout_ms, METH_NOARGS, Reader_get_timeout_ms__doc__}, |
1009 | | - {"close", (PyCFunction) Reader_close, METH_NOARGS, Reader_close__doc__}, |
1010 | | - {"get_usage", (PyCFunction) Reader_get_usage, METH_NOARGS, Reader_get_usage__doc__}, |
1011 | | - {"__enter__", (PyCFunction) Reader___enter__, METH_NOARGS, Reader___enter____doc__}, |
1012 | | - {"__exit__", (PyCFunction) Reader___exit__, METH_VARARGS, Reader___exit____doc__}, |
1013 | | - {"_next", (PyCFunction) Reader_next, METH_VARARGS, Reader_next__doc__}, |
1014 | | - {"_previous", (PyCFunction) Reader_previous, METH_VARARGS, Reader_previous__doc__}, |
1015 | | - {"_get", (PyCFunction) Reader_get, METH_VARARGS, Reader_get__doc__}, |
1016 | | - {"_get_all", (PyCFunction) Reader_get_all, METH_NOARGS, Reader_get_all__doc__}, |
1017 | | - {"_get_realtime", (PyCFunction) Reader_get_realtime, METH_NOARGS, Reader_get_realtime__doc__}, |
1018 | | - {"_get_monotonic", (PyCFunction) Reader_get_monotonic, METH_NOARGS, Reader_get_monotonic__doc__}, |
1019 | | - {"add_match", (PyCFunction) Reader_add_match, METH_VARARGS|METH_KEYWORDS, Reader_add_match__doc__}, |
1020 | | - {"add_disjunction", (PyCFunction) Reader_add_disjunction, METH_NOARGS, Reader_add_disjunction__doc__}, |
1021 | | - {"add_conjunction", (PyCFunction) Reader_add_conjunction, METH_NOARGS, Reader_add_conjunction__doc__}, |
1022 | | - {"flush_matches", (PyCFunction) Reader_flush_matches, METH_NOARGS, Reader_flush_matches__doc__}, |
1023 | | - {"seek_head", (PyCFunction) Reader_seek_head, METH_NOARGS, Reader_seek_head__doc__}, |
1024 | | - {"seek_tail", (PyCFunction) Reader_seek_tail, METH_NOARGS, Reader_seek_tail__doc__}, |
1025 | | - {"seek_realtime", (PyCFunction) Reader_seek_realtime, METH_VARARGS, Reader_seek_realtime__doc__}, |
1026 | | - {"seek_monotonic", (PyCFunction) Reader_seek_monotonic, METH_VARARGS, Reader_seek_monotonic__doc__}, |
1027 | | - {"process", (PyCFunction) Reader_process, METH_NOARGS, Reader_process__doc__}, |
1028 | | - {"wait", (PyCFunction) Reader_wait, METH_VARARGS, Reader_wait__doc__}, |
1029 | | - {"seek_cursor", (PyCFunction) Reader_seek_cursor, METH_VARARGS, Reader_seek_cursor__doc__}, |
1030 | | - {"_get_cursor", (PyCFunction) Reader_get_cursor, METH_NOARGS, Reader_get_cursor__doc__}, |
1031 | | - {"test_cursor", (PyCFunction) Reader_test_cursor, METH_VARARGS, Reader_test_cursor__doc__}, |
1032 | | - {"query_unique", (PyCFunction) Reader_query_unique, METH_VARARGS, Reader_query_unique__doc__}, |
1033 | | - {"get_catalog", (PyCFunction) Reader_get_catalog, METH_NOARGS, Reader_get_catalog__doc__}, |
| 1051 | + {"fileno", (PyCFunction) Reader_fileno, METH_NOARGS, Reader_fileno__doc__}, |
| 1052 | + {"reliable_fd", (PyCFunction) Reader_reliable_fd, METH_NOARGS, Reader_reliable_fd__doc__}, |
| 1053 | + {"get_events", (PyCFunction) Reader_get_events, METH_NOARGS, Reader_get_events__doc__}, |
| 1054 | + {"get_timeout", (PyCFunction) Reader_get_timeout, METH_NOARGS, Reader_get_timeout__doc__}, |
| 1055 | + {"get_timeout_ms", (PyCFunction) Reader_get_timeout_ms, METH_NOARGS, Reader_get_timeout_ms__doc__}, |
| 1056 | + {"close", (PyCFunction) Reader_close, METH_NOARGS, Reader_close__doc__}, |
| 1057 | + {"get_usage", (PyCFunction) Reader_get_usage, METH_NOARGS, Reader_get_usage__doc__}, |
| 1058 | + {"__enter__", (PyCFunction) Reader___enter__, METH_NOARGS, Reader___enter____doc__}, |
| 1059 | + {"__exit__", (PyCFunction) Reader___exit__, METH_VARARGS, Reader___exit____doc__}, |
| 1060 | + {"_next", (PyCFunction) Reader_next, METH_VARARGS, Reader_next__doc__}, |
| 1061 | + {"_previous", (PyCFunction) Reader_previous, METH_VARARGS, Reader_previous__doc__}, |
| 1062 | + {"_get", (PyCFunction) Reader_get, METH_VARARGS, Reader_get__doc__}, |
| 1063 | + {"_get_all", (PyCFunction) Reader_get_all, METH_NOARGS, Reader_get_all__doc__}, |
| 1064 | + {"_get_realtime", (PyCFunction) Reader_get_realtime, METH_NOARGS, Reader_get_realtime__doc__}, |
| 1065 | + {"_get_monotonic", (PyCFunction) Reader_get_monotonic, METH_NOARGS, Reader_get_monotonic__doc__}, |
| 1066 | + {"add_match", (PyCFunction) Reader_add_match, METH_VARARGS|METH_KEYWORDS, Reader_add_match__doc__}, |
| 1067 | + {"add_disjunction", (PyCFunction) Reader_add_disjunction, METH_NOARGS, Reader_add_disjunction__doc__}, |
| 1068 | + {"add_conjunction", (PyCFunction) Reader_add_conjunction, METH_NOARGS, Reader_add_conjunction__doc__}, |
| 1069 | + {"flush_matches", (PyCFunction) Reader_flush_matches, METH_NOARGS, Reader_flush_matches__doc__}, |
| 1070 | + {"seek_head", (PyCFunction) Reader_seek_head, METH_NOARGS, Reader_seek_head__doc__}, |
| 1071 | + {"seek_tail", (PyCFunction) Reader_seek_tail, METH_NOARGS, Reader_seek_tail__doc__}, |
| 1072 | + {"seek_realtime", (PyCFunction) Reader_seek_realtime, METH_VARARGS, Reader_seek_realtime__doc__}, |
| 1073 | + {"seek_monotonic", (PyCFunction) Reader_seek_monotonic, METH_VARARGS, Reader_seek_monotonic__doc__}, |
| 1074 | + {"process", (PyCFunction) Reader_process, METH_NOARGS, Reader_process__doc__}, |
| 1075 | + {"wait", (PyCFunction) Reader_wait, METH_VARARGS, Reader_wait__doc__}, |
| 1076 | + {"seek_cursor", (PyCFunction) Reader_seek_cursor, METH_VARARGS, Reader_seek_cursor__doc__}, |
| 1077 | + {"_get_cursor", (PyCFunction) Reader_get_cursor, METH_NOARGS, Reader_get_cursor__doc__}, |
| 1078 | + {"test_cursor", (PyCFunction) Reader_test_cursor, METH_VARARGS, Reader_test_cursor__doc__}, |
| 1079 | + {"query_unique", (PyCFunction) Reader_query_unique, METH_VARARGS, Reader_query_unique__doc__}, |
| 1080 | + {"enumerate_fields", (PyCFunction) Reader_enumerate_fields, METH_NOARGS, Reader_enumerate_fields__doc__}, |
| 1081 | + {"get_catalog", (PyCFunction) Reader_get_catalog, METH_NOARGS, Reader_get_catalog__doc__}, |
1034 | 1082 | {} /* Sentinel */ |
1035 | 1083 | }; |
1036 | 1084 |
|
|
0 commit comments