I'm currently writing a Python app that changes some network configuration files. The app needs to run on Ubuntu 10.04 to 13.10. The problem is, that NetworkManager is broken in different ways on different versions (though they seem to have finally fixed it in 13.04+), and this causes incompatibilities with my app.
I've figured out the problems on each version and developed workarounds for them, I'm just not sure what the best way is to detect which version of Ubuntu the user is running.
The best solution I've come up with so far is to parse the output of lsb_release -a
, but this seems to be a rather fragile solution and would probably fail with Ubuntu-derived distributions such as Mint and possibly even with some of the "official" variants (Kubuntu, Xubuntu, etc.).
Is there a good way to detect the base distribution and version for a given Linux distribution so I can base the choices my app makes on that version?
To find out which version of Windows your device is running, press the Windows logo key + R, type winver in the Open box, and then select OK. Here's how to learn more: Select Start > Settings > System > About .
To get details related to the current Ubuntu version, simply launch the terminal by pressing Ctrl + Alt + T and type lsb_release -a. The -a flag stands for All and provides you with all the details related to your system.
One thing that you can do to simplify your code is to actually know one thing about how lsb_release
is written. It's actually written in python.
So we could reduce most of your code to this:
>>> import lsb_release
>>> lsb_release.get_lsb_information()
{'RELEASE': '10.04', 'CODENAME': 'lucid', 'ID': 'Ubuntu', 'DESCRIPTION': 'Ubuntu 10.04.4 LTS'}
This won't necessarily help with all of the sub-ubuntu distributions, but I don't know of any builtin table to do that for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With