mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
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.
This commit is contained in:
parent
ba119ffcf9
commit
ee6fd6a509
12
man/check-os-release-simple.py
Normal file
12
man/check-os-release-simple.py
Normal file
@ -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!')
|
@ -29,7 +29,7 @@ def read_os_release():
|
||||
os_release = dict(read_os_release())
|
||||
|
||||
pretty_name = os_release.get('PRETTY_NAME', 'Linux')
|
||||
print(f'Running on {pretty_name}')
|
||||
print(f'Running on {pretty_name!r}')
|
||||
|
||||
if 'debian' in [os_release.get('ID', 'linux'),
|
||||
*os_release.get('ID_LIKE', '').split()]:
|
||||
|
@ -502,9 +502,23 @@ VERSION_ID=32</programlisting>
|
||||
|
||||
<example>
|
||||
<title>Reading <filename>os-release</filename> in
|
||||
<citerefentry><refentrytitle>python</refentrytitle><manvolnum>1</manvolnum></citerefentry></title>
|
||||
<citerefentry><refentrytitle>python</refentrytitle><manvolnum>1</manvolnum></citerefentry> (versions >= 3.10)</title>
|
||||
|
||||
<programlisting><xi:include href="check-os-release-simple.py" parse="text" /></programlisting>
|
||||
|
||||
<para>See docs for <ulink url="https://docs.python.org/3/library/platform.html#platform.freedesktop_os_release">
|
||||
<function>platform.freedesktop_os_release</function></ulink> for more details.
|
||||
</para>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>Reading <filename>os-release</filename> in
|
||||
<citerefentry><refentrytitle>python</refentrytitle><manvolnum>1</manvolnum></citerefentry> (any version)</title>
|
||||
|
||||
<programlisting><xi:include href="check-os-release.py" parse="text" /></programlisting>
|
||||
|
||||
<para>Note that the above version that uses the built-in implementation is preferred
|
||||
in most cases, and the open-coded version here is provided for reference.</para>
|
||||
</example>
|
||||
|
||||
</refsect1>
|
||||
|
Loading…
Reference in New Issue
Block a user