Python module for detecting Linux distro version

Is there an existing python module that can be used to determine which Linux distribution and which version of the distribution is currently installed.

For instance:

  • RedHat Enterprise 5
  • Fedora 11
  • Suse enterprise 11
  • etc....

I can create my own module by analyzing various files such as / etc / redhat -release, but I was wondering if the module already exists?

Cheers, Ivan

+3
source share
3 answers

Check out the docs for the platform module: http://docs.python.org/library/platform.html

Example:

>>> platform.uname ()
('Linux', 'localhost', '2.6.31.5-desktop-1mnb', '#1 SMP Fri Oct 23 00:05:22 EDT 2009', 'x86_64', 'AMD Athlon(tm) 64 X2 Dual Core Processor 3600+')
>>> platform.linux_distribution()
('Mandriva Linux', '2010.0', 'Official')
+14

RHEL 5.x. Redhat- - /etc/redhat -release. , , .

$ python
>>> open('/etc/redhat-release','r').read().split(' ')[6].split('.')
['5', '5']

, . , , , , .

+2

distro ( pip), distro.linux_distribution. , platform.

https://github.com/nir0s/distro ( distro, on pypi)

It provides a much more sophisticated API for retrieving distribution related information.

$ python
Python 2.7.12 (default, Nov  7 2016, 11:55:55) 
[GCC 6.2.1 20160830] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import distro
>>> distro.linux_distribution()
(u'Antergos Linux', '', u'ARCHCODE')

By the way, platform.linux_distributionit should be removed in Python 3.7.

+1
source

Source: https://habr.com/ru/post/1726836/


All Articles