Commit graph

386 commits

Author SHA1 Message Date
Lennart Poettering
059247a62f python: make gcc shut up 2015-07-05 14:19:14 -04:00
Lennart Poettering
da42130ac5 python: fix error handling, and allocate argument array on the stack 2015-07-05 14:19:14 -04:00
Lennart Poettering
3bb03b4e4d python: reindent to follow coding style 2015-07-05 14:19:14 -04:00
Lennart Poettering
5db22f490d python: change license to LGPL 2.1
The original license has been MIT for this code, but David Strauss (its
original author) agreed to relicense it to LGPL 2.1 for inclusion in
systemd.
2015-07-05 14:19:14 -04:00
Lennart Poettering
683fd2a640 python: integrate David Strauss' python-systemd package 2015-07-05 14:19:08 -04:00
David Strauss
5f531b971e Add Python 3 instructions. 2012-09-06 18:22:08 -07:00
David Strauss
7f96f34f10 Fix for Python 3. 2012-09-06 16:53:51 -07:00
David Strauss
7050e537b2 Doc updates 2012-09-06 16:48:51 -07:00
David Strauss
7ba24b5802 Make installable. 2012-09-06 16:45:52 -07:00
David Strauss
05bdd8ce12 Merge pull request #3 from keszybz/stream
sd_journal_stream_fd() wrapper
2012-09-03 15:46:58 -07:00
David Strauss
6f36264189 Merge pull request #2 from keszybz/master
Python 3 and UTF-8
2012-09-03 15:43:06 -07:00
Zbigniew Jędrzejewski-Szmek
a2df218d26 Add a wrapper for sd_journal_stream_fd(3)
A bare-bones wrapper is provided as _journald.stream_fd(),
and a more usable version as journald.stream().

Documentation is included. Tested under Python 2.7 and 3.2.
2012-07-13 09:10:08 -04:00
Zbigniew Jędrzejewski-Szmek
6f190657c0 Fix docstrings 2012-07-13 09:00:01 -04:00
Zbigniew Jędrzejewski-Szmek
d0ac4eaae8 Do not export traceback
This is an implementation detail only.
2012-07-13 08:49:53 -04:00
Zbyszek Jędrzejewski-Szmek
2b1a5c9ff4 Allow UTF-8 in message payload
Allow UTF-8, and force encoding as UTF-8 if the payload is known to be
text. Under Python 3, this means that bytes payload is sent as-is, and
strings are encoded to UTF-8. Under Python 2, this means that unicode
payload is encoded to UTF-8, and the rest is sent as-is, because there
we are missing the extra information to distinguish text and binary data.
IOW, under Python 2, it is the responsibility of the called to provide
properly encoded payload, and under Python 3, there is extra hand-holding
which should help catch mistakes.

Fields which are certain to be text (MESSAGE, MESSAGE_ID, CODE_FILE,
CODE_FUNC) are text-only. The names of fields are text-only too. The
payload of other fields can be binary.
2012-07-12 11:07:16 +02:00
Zbigniew Jędrzejewski-Szmek
3eb019f875 Use traceback module to specify CODE_{LINE,FUNC,FILE}
$python3 -c 'import journald; x = lambda: journald.send("tescik"); x()'

gives a message like:

MESSAGE=tescik
CODE_FILE=<string>
CODE_LINE=1
CODE_FUNC=<lambda>
_TRANSPORT=journal
...

This makes the CODE_* fields much more useful: before they would
always give the location of the sd_journald_sendv() call in the module
source, and now they specify the location of the caller of
journald.send().

When using the low-level journald.sendv() is becomes the
responsibility of the caller to specify the CODE_* fields.
2012-07-12 11:02:30 +02:00
Zbigniew Jędrzejewski-Szmek
557184bb56 Add frontend module in pure-Python and hide old module
journald.send() is renamed to journald.sendv(), and a replacement
journald.send() is added. This new function has a more pythonic API,
where one positional argument is used for the message, and keyword
arguments can be used to specify other fields.

Implementing argument parsing in C would be really painful, for little
gain, so a pure-python module is added, which provides send(), which
in turn calls sendv().
2012-07-12 11:02:30 +02:00
Zbigniew Jędrzejewski-Szmek
3c089ad48e Compatibility with Python 3
Should work with Python 3.0 - 3.2. Compatibility with Python 3.3 might
require additional changes.
2012-07-12 11:02:26 +02:00
Zbigniew Jędrzejewski-Szmek
bf05f619b0 Rework error handling in preparation for py3k changes
When the #ifdefs neccesary to support Python 2 and 3 are added,
there will be many more paths through the code. This style of error
handling makes the code easier to read.
2012-07-10 10:26:40 +02:00
Zbigniew Jędrzejewski-Szmek
7f9ebf50ad Ignore result of build_ext -i 2012-07-10 10:26:40 +02:00
Zbigniew Jędrzejewski-Szmek
48a2295bb7 Check the return value from sd_journal_sendv 2012-07-10 10:26:40 +02:00
Zbigniew Jędrzejewski-Szmek
d624e014bc Use PyString_AsStringAndSize to avoid strlen
This should make the operation microscopically faster.

A second difference is that strings with embedded NULLs will now be
allowed, although I'm not really sure what is the impact of that
change.
2012-07-10 10:26:33 +02:00
Zbyszek Jędrzejewski-Szmek
78a234c6d3 Wrap README to 80 lines 2012-07-10 10:20:31 +02:00
Zbigniew Jędrzejewski-Szmek
167f51b25c Add emacs config for indentation 2012-07-10 10:12:19 +02:00
David Strauss
bc56ace896 Proper TypeError exception handling. 2012-06-26 11:28:42 -07:00
David Strauss
e4f66cc4aa Whitespace fixes. Drop header-style guards. 2012-06-26 11:23:51 -07:00
David Strauss
63fd53fc00 Documentation updates. 2012-06-26 01:20:09 -07:00
David Strauss
ec63deb806 Code clean-up. 2012-06-26 01:07:33 -07:00
David Strauss
51189a1b46 Allow varags. 2012-06-26 01:00:46 -07:00
David Strauss
83a9513518 Use sd_journal_print() instead of send. 2012-06-25 23:21:43 -07:00
David Strauss
e6666cc638 Now works with import. 2012-06-25 23:16:30 -07:00
David Strauss
6edaadeb08 Add systemd-journal library. 2012-06-25 23:15:28 -07:00
David Strauss
b03b0ab4db Add test build instructions. 2012-06-25 23:07:03 -07:00
David Strauss
cb38f73ede Initial boilerplate work. Compiles without warnings. Untested. 2012-06-25 23:02:40 -07:00
David Strauss
a472ade603 Add MIT license. 2012-06-25 20:03:15 -07:00
David Strauss
7bcd859895 Initial commit 2012-06-25 16:58:29 -07:00