Try to find kreadconfig5 in PATH, otherwise fall back to kreadconfig
Only kreadconfig5 exists on my Arch Linux installation. Arch Linux is known for not patching upstream, so I assume this is how it is shipped by the latest KDE Plasma version. Some distros might decide to symlink kreadconfig to kreadconfig5 -- this code should support both cases.
Use universal_newlines=True in subprocess calls instead of decoding with UTF-8 always
If encoding or errors are specified, or text is true, file objects for stdin, stdout and stderr are opened in text mode using the specified encoding and errors or the io.TextIOWrapper default. The universal_newlines argument is equivalent to text and is provided for backwards compatibility. By default, file objects are opened in binary mode.
And the default encoding for io.TextIOWrapper is described here:
encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getpreferredencoding(False).
Which can be found here. So we can assume this makes the best choice using what can be inferred from the running system, instead of just assuming "UTF-8". I decided to use "universal_newlines" instead of the more-modern "text" keyword-argument, because that was only introduced relatively recently (Python 3.7).
kreadconfig5
in PATH, otherwise fall back tokreadconfig
Only
kreadconfig5
exists on my Arch Linux installation. Arch Linux is known for not patching upstream, so I assume this is how it is shipped by the latest KDE Plasma version. Some distros might decide to symlinkkreadconfig
tokreadconfig5
-- this code should support both cases.universal_newlines=True
in subprocess calls instead of decoding with UTF-8 alwaysSee the paragraph about
universal_newlines
here:And the default encoding for
io.TextIOWrapper
is described here:Which can be found here. So we can assume this makes the best choice using what can be inferred from the running system, instead of just assuming "UTF-8". I decided to use "universal_newlines" instead of the more-modern "text" keyword-argument, because that was only introduced relatively recently (Python 3.7).