summaryrefslogtreecommitdiffstats
path: root/man/check-os-release-simple.py
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-02-28 09:47:28 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2022-02-28 10:52:17 +0100
commitee6fd6a50922d2b27c97084e1c3f9872d495c273 (patch)
treed8badefd1930a2a0166b270309b3768252c567e4 /man/check-os-release-simple.py
parentMerge pull request #22627 from yuwata/network-l2tp-cleanups (diff)
downloadsystemd-ee6fd6a50922d2b27c97084e1c3f9872d495c273.tar.xz
systemd-ee6fd6a50922d2b27c97084e1c3f9872d495c273.zip
man: recommend built-in platform.freedesktop_os_release() in our page
Python gained support for reading os-release, let's advertise it a bit more. Our open-coded example is still useful, but let's not suggest it as the default implementation. I added quotes around the printed string because it looks a bit better this way.
Diffstat (limited to 'man/check-os-release-simple.py')
-rw-r--r--man/check-os-release-simple.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/man/check-os-release-simple.py b/man/check-os-release-simple.py
new file mode 100644
index 0000000000..738b1fd860
--- /dev/null
+++ b/man/check-os-release-simple.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+# SPDX-License-Identifier: CC0-1.0
+
+import platform
+os_release = platform.freedesktop_os_release()
+
+pretty_name = os_release.get('PRETTY_NAME', 'Linux')
+print(f'Running on {pretty_name!r}')
+
+if 'fedora' in [os_release.get('ID', 'linux'),
+ *os_release.get('ID_LIKE', '').split()]:
+ print('Looks like Fedora!')