Commit graph

149 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
3507ff227b systemd-python: implement _Reader.test_cursor
Getting the cursor is split out from .get_next() into
.get_cursor(). This mirrors the C API more closely, and
also makes things a bit faster if the cursor is not needed.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
8057e1c7e7 systemd-python: cleanup up usec_t handling
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.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
f55e2d9049 systemd-python: export sd_journal_get_usage 2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
26b763337c Remove some unused variables 2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
9d63a706d7 systemd-python: small cleanups
- separate methods with two empty lines for clarity
- avoid malloc(0) by specyfing private data size as -1
- add method name in error messages
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
69669a975b 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.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
150dc5bde2 systemd-python: add _Reader.get_catalog()
This one wraps sd_journaal_get_catalog.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
b7010f5dbc systemd-python: add _Reader.closed attribute
This should make the file interface of _Reader complete.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
4ddd8feaa9 systemd-python: allow Reader to be used as a context manager 2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
d583bb0f53 systemd-python: add systemd.daemon wrapping sd-daemon
Please see the documentation (e.g. pydoc3 systemd.daemon) for full
description. As usual, systemd._daemon wraps the raw interface, while
systemd.daemon provides the more pythonic API. sd_listen_fds,
sd_booted, sd_is_fifo, sd_is_socket, sd_is_socket_unix,
sd_is_socket_inet, sd_is_mq, and SD_LISTEN_FDS_START are currently
wrapped.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
961f238f8f man,html: say 'systemd 198' in the header
This should help readers of the man or HTML pages know if the documentation
is out of date. An alternative to use a date generated from 'git log' was
considered, but since we try to keep user visible documentation up to date,
showing the project version should be enough.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
98d3fa4753 python/docs: use the same links on top as in man pages
I forgot to commit the layout file, because it was gitignored.
Fixed now.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
531c97c27b html: make python docs look more like the rest
The result is ugly enough, I hope, to motivate someone with
design skills to fix it.
2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
3f1377a8e1 systemd-python: provide version info to sphinx 2015-07-05 14:19:18 -04:00
Zbigniew Jędrzejewski-Szmek
df25f1d610 systemd-python: fix segfault on double close 2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
70f8e1a195 systemd-python: fix typos 2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
7b732ed75d systemd-python: update documentation for new systemd-journal group 2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
67bdb044d8 systemd-python: refuse path and flags together in __init__
It's better to explictly check, instead of just documenting it.

The return value from init is changed from 1 to -1 on error.
Python seems to ignore 1 every second time. Looks like a bug
in Python, but the return value doesn't seem to be documented
anywhere, and -1 works as expected... so let's just use that.
2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
000525db3e systemd-python: export sd_j_get_fd, sd_j_reliable_fd, sd_j_close
sd_journal_get_fd(j) is called j.fileno(), for compatiblity with
Python conventions for file-like objects.

More importantly, those new .seek_head() and .seek_tail() do not
call .get_next(). This is better, if one wants to skip before
retrieving an entry.
2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
cbbe787926 systemd-python: split .seek() into .seek_head() and .seek_tail()
This way python code follows the original interface more closely.
Also, .seek(0, journal.SEEK_END) was just to much to type.
2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
0fe854e001 systemd-python: catch only ValueErrors in conversion code
First of all, 'try: ... except: ...' (with no exception specified) is
always a no-no, since it catches all BaseExceptions, which includes ^C
and other stuff which should almost never be caught.

Now the conversion is stricter, and only one conversion is attempted,
and only a ValueEror is caught. It seems reasonable to catch ValueErrors,
since the entries in the journal are not verified, and any erroneous
application might log a field which cannot be converted. The consumer
of events must only check if a field is an instance of bytes and can
otherwise assume that the conversion was performed correctly.

Order of arguments in Reader.__init__ has been changed to match order
in _Reader.__init__.

Conversions have been updated to work under Python 2 and 3.
2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
68bdaeba7a systemd-python: fix error check in _Reader.wait() 2015-07-05 14:19:17 -04:00
Lukas Nykryn
5ed6b60c15 systemd-python: add missing check for return of PyDict_SetItem in _reader.c 2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
3223d0b21f python-systemd: rename Journal to Reader
It seems inevitable that we'll also grow a writing interface,
and then it'll be cumbersome to have a "Journal" for reading,
and a "Writer" for writing.
2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
4a3c9f4286 systemd-python: return both parts of sd_journal_get_monotonic_usec
In Python 3, a named tuple is used. In Python 2, a simple
tuple is used. In either case, the pair is (timestamp, bootid).
2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
7db007ce6c python-systemd: check all errors and use automatic cleanup
__REALTIME_TIMESTAMP and __MONOTONIC_TIMESTAMP return ints.
It doesn't make sense to convert to string, just to convert
back to a number later on.

Also try to follow systemd rules for indentation.
2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
cedd0fd249 systemd-python: hide ChainMap import 2015-07-05 14:19:17 -04:00
Zbigniew Jędrzejewski-Szmek
8d697bfd13 systemd-python: document attributes
In id128 it would be better to add everything automatically, but
sphinx cannot do this right now.
2015-07-05 14:19:16 -04:00
Zbigniew Jędrzejewski-Szmek
ec05eb1aef systemd-python: use PyModule_AddObject in id128 2015-07-05 14:19:16 -04:00
Zbigniew Jędrzejewski-Szmek
c18311bd54 systemd-python: polish the docstrings 2015-07-05 14:19:16 -04:00
Zbigniew Jędrzejewski-Szmek
2575a15b61 systemd-python: indenation and style tweaks 2015-07-05 14:19:16 -04:00
Zbigniew Jędrzejewski-Szmek
79931a5520 systemd-python: downgrade _reader.c to C89 2015-07-05 14:19:16 -04:00
Zbigniew Jędrzejewski-Szmek
b8b5706a1d systemd-python: add casts and fix unused variable warnings in _reader 2015-07-05 14:19:16 -04:00
Zbigniew Jędrzejewski-Szmek
2d3c2201a4 systemd-python: wrap some python differences using macros 2015-07-05 14:19:16 -04:00
Zbigniew Jędrzejewski-Szmek
544fbf3b3a systemd-python: introduce error setting helper 2015-07-05 14:19:16 -04:00
Steven Hiscocks
31d2aff90e systemd-python: Added doc string for Journal 2015-07-05 14:19:16 -04:00
Steven Hiscocks
7df62d3a00 systemd-python: Journal convert_unicode exception handling change
Rather than catch all, is now limited to UnicodeDecodeError
2015-07-05 14:19:16 -04:00
Steven Hiscocks
d21d05648d systemd-python: add Journal method to add MESSAGE_ID match 2015-07-05 14:19:16 -04:00
Steven Hiscocks
82ff2498de systemd-python: fix memory leak in _reader and minor bugs
iternext now checks for error from get_next, and changed a DECREF to
XDECREF rather than NULL check
2015-07-05 14:19:16 -04:00
Steven Hiscocks
3813a8ab26 systemd-python: update Journal python docstrings 2015-07-05 14:19:16 -04:00
Steven Hiscocks
8d5a8d3654 systemd-python: tidy up import names in journal 2015-07-05 14:19:16 -04:00
Steven Hiscocks
2f5a35a755 systemd-python: Journal this_boot/machine now accepts ID 2015-07-05 14:19:15 -04:00
Steven Hiscocks
9d405a0928 systemd-python: remove unneeded ifdef for query_unique 2015-07-05 14:19:15 -04:00
Steven Hiscocks
445332cb69 systemd-python: _reader now takes unix timestamp in seconds 2015-07-05 14:19:15 -04:00
Steven Hiscocks
029ac59922 systemd-python: Update _reader docstrings 2015-07-05 14:19:15 -04:00
Steven Hiscocks
097bcda6ce systemd-python: _reader add_match takes single string
python code now takes care of multiple matches
2015-07-05 14:19:15 -04:00
Steven Hiscocks
7258e1a44a systemd-python: correct data_threshold error return value 2015-07-05 14:19:15 -04:00
Steven Hiscocks
ab67680240 systemd-python: updated _reader header to standard license 2015-07-05 14:19:15 -04:00
Steven Hiscocks
716351a180 systemd-python: Moved _reader datetime usage to python 2015-07-05 14:19:15 -04:00
Steven Hiscocks
c5ba02c0a8 systemd-python: Tidy up _reader error handling 2015-07-05 14:19:15 -04:00