Commit graph

81 commits

Author SHA1 Message Date
Ville Skyttä d2bbca6855 Spelling fixes 2013-05-03 22:45:09 -04:00
Zbigniew Jędrzejewski-Szmek b5edbff035 systemd-python: attach fields to JournalHandler, add SYSLOG_IDENTIFIER
Arbitrary fields can be attached at the level of the handler,
and they'll be sent with all messages from this handler.

This facility is used to attach SYSLOG_IDENTIFIER to all messages,
since otherwise journald attaches SYSLOG_IDENTIFIER=python or
something similar, which is completely useless.
2013-04-25 21:20:27 -04:00
Zbigniew Jędrzejewski-Szmek 7f876bc428 systemd-python: wrap sd_journal_add_conjunction 2013-04-18 19:38:28 -04:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek e7ecdfc15c sd-messages.h: add new bootchart message id 2013-04-17 00:09:16 -04:00
Zbigniew Jędrzejewski-Szmek e8e581bf25 Report about syntax errors with metadata
The information about the unit for which files are being parsed
is passed all the way down. This way messages land in the journal
with proper UNIT=... or USER_UNIT=... attribution.

'systemctl status' and 'journalctl -u' not displaying those messages
has been a source of confusion for users, since the journal entry for
a misspelt setting was often logged quite a bit earlier than the
failure to start a unit.

Based-on-a-patch-by: Oleksii Shevchuk <alxchk@gmail.com>
2013-04-17 00:09:16 -04:00
Steven Hiscocks 6a58bf4135 python-systemd: Reader return special fields and _Reader changes
Changes to _Reader make it match closer to C API, by removing `get_next`
and `get_previous`. A `get_all` method added, which returns dictionary
of fields using C API SD_JOURNAL_FOREACH_DATA macro, which can be used
in conjunction with `next`.

_Reader `get`, `next`, `get_{realtime,monotonic,cursor}` and new
`previous` methods are made private. This is so the traversal and
getting of journal fields can be made transparent in the python
interface.

Reader now solely implements `get_next` and `get_previous`, returning a
standard dictionary (future: other mapping types?) with all standard and
special fields through the converters. This makes the output the same as
journalctl json/export format output.

Iterator methods also moved to Reader, as they do not function as intend
with changes to _Reader.

These changes also mean that more optimised journal interfaces can be
made more easily from _Reader, by avoiding getting of unrequired fields
by using the `_get` method, and avoiding field conversions.
2013-04-17 00:09:15 -04:00
Zbigniew Jędrzejewski-Szmek 76a80d93b5 systemd-python: export new sd_journal_{process,get_events,get_timeout}
get_timeout_ms is added as a convenience function, since
it is abysmally hard to call clock_gettime() in Python
versions lower than 3.3. And even for Python 3.3 users
it saves a few lines.
2013-04-16 20:17:40 -04:00
Zbigniew Jędrzejewski-Szmek ee6349a726 systemd-python: fix formatting in docstring 2013-04-14 18:38:32 -04:00
Steven Hiscocks 7c962c866a systemd-python: fix wait bug 2013-04-06 18:50:35 -04:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Zbigniew Jędrzejewski-Szmek 811de196b3 systemd-python: allow retrieval of single fields
This can give huge efficiency gains, e.g. if only MESSAGE
is required and all other fields can be ignored.
2013-03-21 23:05:09 -04:00
Zbigniew Jędrzejewski-Szmek 5e8ba1a460 systemd-python: split out realtime and monotonic into separate functions
This matches the C API more closely, and also enables the
user to get just partial information, should she desire to
do so.

Functions names in error messages are modified to not include
the class name, because Python uses just the function name
into functions declared as METH_NOARGS, and error messages
were inconsistent.
2013-03-21 23:05:08 -04:00
Zbigniew Jędrzejewski-Szmek 1cdcd71be0 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.
2013-03-21 22:39:24 -04:00
Zbigniew Jędrzejewski-Szmek 806bc1cb61 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.
2013-03-21 22:39:24 -04:00
Zbigniew Jędrzejewski-Szmek 50a279f857 systemd-python: export sd_journal_get_usage 2013-03-21 22:39:24 -04:00
Zbigniew Jędrzejewski-Szmek 4750fade13 Remove some unused variables 2013-03-20 19:16:01 -04:00
Zbigniew Jędrzejewski-Szmek ab3a162c01 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
2013-03-19 21:50:43 -04:00
Zbigniew Jędrzejewski-Szmek 2b01924cda 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.
2013-03-19 21:50:42 -04:00
Zbigniew Jędrzejewski-Szmek 6808412dad systemd-python: add _Reader.get_catalog()
This one wraps sd_journaal_get_catalog.
2013-03-19 21:50:42 -04:00
Zbigniew Jędrzejewski-Szmek 6531dac67c systemd-python: add _Reader.closed attribute
This should make the file interface of _Reader complete.
2013-03-19 21:50:42 -04:00
Zbigniew Jędrzejewski-Szmek 85b2850ba9 systemd-python: allow Reader to be used as a context manager 2013-03-18 18:53:58 -04:00
Zbigniew Jędrzejewski-Szmek b04c8c83e8 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.
2013-03-15 22:55:24 -04:00
Zbigniew Jędrzejewski-Szmek 702f64b93c 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.
2013-03-12 23:57:46 -04:00
Zbigniew Jędrzejewski-Szmek 082cca735b 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.
2013-03-09 09:56:19 -05:00
Zbigniew Jędrzejewski-Szmek fa28d83678 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.
2013-03-09 08:47:50 -05:00
Zbigniew Jędrzejewski-Szmek 9f06e912f6 systemd-python: provide version info to sphinx 2013-03-09 08:47:50 -05:00
Zbigniew Jędrzejewski-Szmek db7f1dde30 systemd-python: fix segfault on double close 2013-03-07 15:35:50 -05:00
Zbigniew Jędrzejewski-Szmek 516424a411 systemd-python: fix typos 2013-03-07 15:35:50 -05:00
Zbigniew Jędrzejewski-Szmek 614e5fbb8b systemd-python: update documentation for new systemd-journal group 2013-03-07 11:29:08 -05:00
Zbigniew Jędrzejewski-Szmek 0eff0f3bce 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.
2013-03-07 11:29:08 -05:00
Zbigniew Jędrzejewski-Szmek f2e82cd5ad 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.
2013-03-07 00:45:56 -05:00
Zbigniew Jędrzejewski-Szmek 5c1c14b3a0 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.
2013-03-07 00:45:56 -05:00
Zbigniew Jędrzejewski-Szmek aaf0806118 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.
2013-03-07 00:45:56 -05:00
Zbigniew Jędrzejewski-Szmek 6210afbcff systemd-python: fix error check in _Reader.wait() 2013-03-05 23:23:09 -05:00
Lukas Nykryn 684ecf306a systemd-python: add missing check for return of PyDict_SetItem in _reader.c 2013-03-01 16:43:57 -05:00
Zbigniew Jędrzejewski-Szmek 7f41820b07 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.
2013-02-28 20:04:17 -05:00
Zbigniew Jędrzejewski-Szmek 86e3d32a1d 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).
2013-02-28 20:04:17 -05:00
Zbigniew Jędrzejewski-Szmek 6a6633a16a 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.
2013-02-28 20:04:17 -05:00
Zbigniew Jędrzejewski-Szmek 5c083fa815 systemd-python: hide ChainMap import 2013-02-28 20:04:17 -05:00
Zbigniew Jędrzejewski-Szmek df2795d9f9 systemd-python: document attributes
In id128 it would be better to add everything automatically, but
sphinx cannot do this right now.
2013-02-28 20:04:17 -05:00
Zbigniew Jędrzejewski-Szmek a244c095c2 systemd-python: use PyModule_AddObject in id128 2013-02-28 20:04:17 -05:00
Zbigniew Jędrzejewski-Szmek 2c07646764 systemd-python: polish the docstrings 2013-02-28 19:36:14 -05:00
Zbigniew Jędrzejewski-Szmek 33ed3769b5 systemd-python: indenation and style tweaks 2013-02-22 18:09:49 +01:00
Zbigniew Jędrzejewski-Szmek 0d92ee93dc systemd-python: downgrade _reader.c to C89 2013-02-22 16:57:45 +01:00
Zbigniew Jędrzejewski-Szmek 118bf4bad8 systemd-python: add casts and fix unused variable warnings in _reader 2013-02-22 16:57:45 +01:00
Zbigniew Jędrzejewski-Szmek ecb6dfe117 systemd-python: wrap some python differences using macros 2013-02-22 16:57:45 +01:00
Zbigniew Jędrzejewski-Szmek e82e4f4562 systemd-python: introduce error setting helper 2013-02-22 16:57:45 +01:00
Steven Hiscocks cac40fbe24 systemd-python: Added doc string for Journal 2013-02-22 16:57:45 +01:00
Steven Hiscocks eccc9e74d2 systemd-python: Journal convert_unicode exception handling change
Rather than catch all, is now limited to UnicodeDecodeError
2013-02-22 16:57:44 +01:00