From the comments above:
- I need to know if the OS is (Open) SUSE in order to use the correct package installer (zypper). If it is DEBIAN (for example), I will use apt-get ...
I suggest you directly solve the real problem. Instead of identifying the OS, define an available package manager.
import os def file_exists(fname): try: os.stat(fname) return True except OSError: return False if file_exists('/usr/bin/zypper'): ...
EDIT: Although the package manager program detection code is shown here, it is better to find the main package registry. For example, on Debian / Ubuntu systems that use dpkg
, there will be a directory /var/lib/dpkg
containing the package database; this is a sure sign that dpkg
or apt-get
are appropriate. I do not know what equivalent directories are for SUSE and Red Hat, etc., but if you support the ones you can find out.
apt-get
been ported to Red Hat systems, and through a program called alien
you can get rpm
on Debian systems and so on. Discovering the package database itself is the most reliable way to find out which package system is being used.
If you find a package manager, then your code will automatically work with all related distributions. If you find the dpkg
database, your code will run on Debian, Ubuntu, Linux Mint, and many other Debian based distributions. If you find the rpm
database, your code will run on Red Hat, Centos, Fedora, Mandriva, and all other RPM-based distributions.
source share