Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update python-systemd to 235-1 #2

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
PYTHON = python
SED = sed
SPHINX_BUILD = sphinx-build
ETAGS = etags
INCLUDE_DIR := $(shell pkg-config --variable=includedir libsystemd)
INCLUDE_FLAGS := $(shell pkg-config --cflags libsystemd)
VERSION := $(shell $(PYTHON) setup.py --version)
TESTFLAGS = -v

define buildscript
import sys,sysconfig
print("build/lib.{}-{}.{}".format(sysconfig.get_platform(), *sys.version_info[:2]))
import sys, sysconfig, setuptools
sversion = int(setuptools.__version__.split(".")[0])
end = sys.implementation.cache_tag if sversion >= 61 else "{}.{}".format(*sys.version_info[:2])
print("build/lib.{}-{}".format(sysconfig.get_platform(), end))
endef

builddir := $(shell $(PYTHON) -c '$(buildscript)')
Expand Down Expand Up @@ -49,9 +50,10 @@ clean:
distclean: clean
rm -rf dist MANIFEST

SPHINXOPTS = -D version=$(VERSION) -D release=$(VERSION)
SPHINXOPTS += -D version=$(VERSION) -D release=$(VERSION)
sphinx-%: build
PYTHONPATH=$(builddir) $(SPHINX_BUILD) -b $* $(SPHINXOPTS) docs build/$*
cd build && \
PYTHONPATH=../$(builddir) $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $*
@echo Output has been generated in build/$*

doc: sphinx-html
Expand Down
31 changes: 31 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
Python wrappers for libsystemd API

CHANGES WITH 235:

* Adapt the rename of systemd-activate to systemd-socket-activate
performed in systemd 230.

* Support for sd_listen_fds_with_names added in systemd 227.

* Support for sd_journal_get_cutoff_realtime_usec added in systemd
186.

* Make the Reader PY_SSIZE_T_CLEAN for py3.10 compatibility.

* id128: update for systemd-243 compatibility and other fixes.

* C syntax modernization. A minimum of C99 is assumed.

* Fix seek_realtime to work with timezone aware date on Python 3.

* journal: add namespace support.

* Fixes for memory leaks and documentation.

* Support for Python 2 will be removed after this release.

Contributions from: Alexander Olekhnovich, Andrew Stone,
Architector #4, Chris Mullins, Dan Bungert, Dominik Prien,
Federico Ceratto, Frantisek Sumsal, Glandos, Hendrikto, Khem
Raj, Léonard Gérard, Marcel Waldvogel, Marco Paolini, Samuel
BF, Tamaki Nishino, Tim Orling, Tomasz Meresiński, Zbigniew
Jędrzejewski-Szmek, ytyt-yt

CHANGES WITH 234:

* Support for the new sd_is_socket_sockaddr added in systemd 233
Expand Down
150 changes: 125 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,57 @@ python-systemd

Python module for native access to the systemd facilities. Functionality
is separated into a number of modules:
- systemd.journal supports sending of structured messages to the journal
- `systemd.journal` supports sending of structured messages to the journal
and reading journal files,
- systemd.daemon wraps parts of libsystemd useful for writing daemons
- `systemd.daemon` wraps parts of `libsystemd` useful for writing daemons
and socket activation,
- systemd.id128 provides functions for querying machine and boot identifiers
- `systemd.id128` provides functions for querying machine and boot identifiers
and a lists of message identifiers provided by systemd,
- systemd.login wraps parts of libsystemd used to query logged in users
- `systemd.login` wraps parts of `libsystemd` used to query logged in users
and available seats and machines.

Installation
============

This module should be packaged for almost all Linux distributions. Use

On Fedora/RHEL/CentOS
On Fedora:

dnf install python-systemd python3-systemd
dnf install python3-systemd

On Debian/Ubuntu/Mint
On Debian/Ubuntu/Mint:

apt-get install python-systemd python3-systemd
apt update
apt install python3-systemd

On openSUSE and SLE
On openSUSE and SLE:

zypper in python-systemd
zypper in python3-systemd

On Arch:

pacman -Sy python-systemd

To build from source
--------------------

On Fedora 21+ with Python 2:
On CentOS, RHEL, and Fedora with Python 2:

dnf install git python-pip gcc python-devel systemd-devel
pip install git+https://github.com/systemd/python-systemd.git#egg=systemd
pip install 'git+https://github.com/systemd/python-systemd.git#egg=systemd-python'

On Fedora 21+ with Python 3:
On Fedora with Python 3:

dnf install git python3-pip gcc python3-devel systemd-devel
pip3 install git+https://github.com/systemd/python-systemd.git#egg=systemd
pip3 install 'git+https://github.com/systemd/python-systemd.git#egg=systemd-python'

On Debian or Ubuntu with Python 2:

apt-get install libsystemd-{journal,daemon,login,id128}-dev gcc python-dev pkg-config
apt install libsystemd-{journal,daemon,login,id128}-dev gcc python-dev pkg-config

On Debian or Ubuntu with Python 3:

apt-get install libsystemd-{journal,daemon,login,id128}-dev gcc python3-dev pkg-config
apt install libsystemd-{journal,daemon,login,id128}-dev gcc python3-dev pkg-config

The project is also available on pypi as `systemd-python`.

Expand All @@ -61,7 +67,7 @@ Quick example:
journal.send('Hello, again, world', FIELD2='Greetings!', FIELD3='Guten tag')
journal.send('Binary message', BINARY=b'\xde\xad\xbe\xef')

There is one required argument -- the message, and additional fields
There is one required argument the message, and additional fields
can be specified as keyword arguments. Following the journald API, all
names are uppercase.

Expand All @@ -75,15 +81,109 @@ The journald sendv call can also be accessed directly:

The two examples should give the same results in the log.

Notes:
Reading from the journal is often similar to using the `journalctl` utility.

Show all entries since 20 minutes ago (`journalctl --since "20 minutes ago"`):

from systemd import journal
from datetime import datetime, timedelta
j = journal.Reader()
j.seek_realtime(datetime.now() - timedelta(minutes=20))
for entry in j:
print(entry['MESSAGE'])

Show entries between two timestamps (`journalctl --since "50 minutes ago" --until "10 minutes ago"`):

from systemd import journal
from datetime import datetime, timedelta
j = journal.Reader()
since = datetime.now() - timedelta(minutes=50)
until = datetime.now() - timedelta(minutes=10)
j.seek_realtime(since)
for entry in j:
if entry['__REALTIME_TIMESTAMP'] > until:
break
print(entry['MESSAGE'])

Show explanations of log messages alongside entries (`journalctl -x`):

from systemd import journal
j = journal.Reader()
for entry in j:
print("MESSAGE: ", entry['MESSAGE'])
try:
print("CATALOG: ", j.get_catalog())
except:
pass

Show entries by a specific executable (`journalctl /usr/bin/vim`):

from systemd import journal
j = journal.Reader()
j.add_match('_EXE=/usr/bin/vim')
for entry in j:
print(entry['MESSAGE'])

* Unlike the native C version of journald's sd_journal_send(),
printf-style substitution is not supported. Perform any
substitution using Python's % operator or .format() capabilities
first.
* A ValueError is raised if sd_journald_sendv() results in an error.
This might happen if there are no arguments or one of them is
invalid.
- Note: matches can be added from many different fields, for example
entries from a specific process ID can be matched with the `_PID`
field, and entries from a specific unit (ie. `journalctl -u
systemd-udevd.service`) can be matched with `_SYSTEMD_UNIT`.
See all fields available at the
[systemd.journal-fields docs](https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html).

Show kernel ring buffer (`journalctl -k`):

from systemd import journal
j = journal.Reader()
j.add_match('_TRANSPORT=kernel')
for entry in j:
print(entry['MESSAGE'])

Read entries in reverse (`journalctl _EXE=/usr/bin/vim -r`):

from systemd import journal
class ReverseReader(journal.Reader):
def __next__(self):
ans = self.get_previous()
if ans:
return ans
raise StopIteration()

j = ReverseReader()
j.add_match('_EXE=/usr/bin/vim')
j.seek_tail()
for entry in j:
print(entry['MESSAGE'])


Notes
-----

* Unlike the native C version of journald's `sd_journal_send()`,
printf-style substitution is not supported. Perform any substitution
using Python's f-strings first (or `.format()` or the `%` operator).
* A `ValueError` is raised if `sd_journald_sendv()` results in an
error. This might happen if there are no arguments or one of them is
invalid.

A handler class for the Python logging framework is also provided:

import logging
from systemd import journal
logger = logging.getLogger('custom_logger_name')
logger.addHandler(journal.JournalHandler(SYSLOG_IDENTIFIER='custom_unit_name'))
logger.warning("Some message: %s", 'detail')

`libsystemd` version compatibility
----------------------------------

This module may be compiled against any version of `libsystemd`. At
compilation time, any functionality that is not available in that
version is disabled, and the resulting binary module will depend on
symbols that were available at compilation time. This means that the
resulting binary module is compatible with that or any later version
of `libsystemd`. To obtain maximum possible functionality, this module
must be compile against suitably recent libsystemd.

Documentation
=============
Expand Down
10 changes: 10 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
python-systemd (235-1) unstable; urgency=medium

* New upstream version 235
* Drop patches, merged upstream
* Bump Standards-Version to 3.6.1, no further changes
* Add Build-Depends on python3-setuptools
* Enable all hardening build flags

-- Michael Biebl <[email protected]> Tue, 16 Aug 2022 17:12:47 +0200

python-systemd (234-4) unstable; urgency=medium

[ Debian Janitor ]
Expand Down
5 changes: 3 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Priority: optional
Maintainer: Debian systemd Maintainers <[email protected]>
Uploaders: Michael Biebl <[email protected]>,
Martin Pitt <[email protected]>
Standards-Version: 4.6.0
Standards-Version: 4.6.1
Rules-Requires-Root: no
Vcs-Git: https://salsa.debian.org/systemd-team/python-systemd.git
Vcs-Browser: https://salsa.debian.org/systemd-team/python-systemd
Expand All @@ -13,7 +13,8 @@ Build-Depends: debhelper-compat (= 13),
dh-python,
libsystemd-dev,
pkg-config,
python3-all-dev
python3-all-dev,
python3-setuptools,

Package: python3-systemd
Section: python
Expand Down
41 changes: 0 additions & 41 deletions debian/patches/PY_SSIZE_T_CLEAN.patch

This file was deleted.

1 change: 0 additions & 1 deletion debian/patches/series

This file was deleted.

1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#export DH_VERBOSE=1
#export DEB_BUILD_OPTIONS="nostrip"
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export PYBUILD_NAME=systemd

# Explicitly tell dh to use pybuild, otherwise it will pick the
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
# Output file base name for HTML help builder.
htmlhelp_basename = 'python-systemddoc'

manpages_url = 'https://www.freedesktop.org/software/systemd/man/{page}.html'

# -- Options for LaTeX output --------------------------------------------------

Expand Down
Loading
Loading