Check linux distro name


Check linux distro name



I have to get linux distro name from python script. There is dist method in platform module:

import platform platform.dist() 

But it returns

>>> platform.dist() ('', '', '') 

Under my Arch Linux. Why? How can I get the name.

p.s. I have to check whether the distro is debian-based.


Upd: I found here python site, that dist() is deprecated since 2.6

>>> platform.linux_distribution() ('', '', '') 

What C headers for directory traversal are process safe in Linux?

1:

Is there a workaround for Linux mono's refusal to acknowledge that I have resized the columns of my VirtualMode ListView?
Works for me on Ubuntu:. How to enable core PHP extension in Linux? ('Ubuntu', '10.04', 'lucid'). Programmatically insert and remove kernel modules in C I then used strace to find out what exactly the platform module is doing to find the distro and it is this part:. Consolidate multiple site files into single location
open("/etc/lsb-release", O_RDONLY|O_LARGEFILE) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=102, ...}) = 0 fstat64(3, {st_mode=S_IFREG|0644, st_size=102, ...}) = 0 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76b1000 read(3, "DISTRIB_ID=Ubuntu\nDISTRIB_RELEAS"..., 8192) = 102 read(3, "", 4096)                       = 0 read(3, "", 8192)                       = 0 close(3)                                = 0 
So, there is /etc/lsb-release containing this info, which comes from Ubuntu's Debian base-files package.. Creating a PHP web page that enables you to reboot the server in Linux?
What the best multi-thread application debugger for C++ appsBuild an Xcode project on a Linux machine

2:

Here's what I found:.
platform.linux_distrialthough ion 
Tries to determine the name of the Linux OS distrialthough ion name..
It says platform.dist is deprecated since 2.6.

3:

Works here. And no, Arch Linux is not debian based..
>>> import platform >>> platform.dist() ('SuSE', '11.2', 'x86_64') 
So python does not know how to receive archlinux release information and it has hardcoded looking for /etc/redhat-release and /etc/SuSE-release.. platform.dist() is an obsolete function. You should use platform.linux_distrialthough ion(). Actually, in my system it yields a different result:.
>>> platform.linux_distrialthough ion() ('openSUSE ', '11.2', 'x86_64') 
platform.linux_distrialthough ion() looks in /etc files containing "release" or "version" as string. It also looks in the standard LSB release file. If at the end this did not work, it resorts to a _dist_try_harder function which tries to receive the information from another places.. So it is up to Arch Linux to provide a standard LSB release information or to patch python to use their "way"..

4:

Two options for ya..
import platform platform.linux_distrialthough ion() #any thing like ('Ubuntu', '9.10', 'karmic') 
Or you could just read the contents of /etc/debian_version ("squeeze/sid") or /etc/lsb-release which would give:.
DISTRIB_ID=Ubunt DISTRIB_RELEASE=9.10 DISTRIB_CODENAME=karmic DISTRIB_DESCRIPTION="Ubuntu 9.10" 
GL!.

5:

This worked for me under Ubuntu and Manjaro:.
def receive _distro():     """     Name of your Linux distro (in lowercase).     """     with open("/etc/issue") as f:         return f.read().lower().split()[0] 

6:

You'll probably have to resort to:.
if platform.linux_distrialthough ion() == ('', '', ''):     # did  any thing specific to look for Arch 
or you could always augment lib/python2.6/platform.py and send in your changes..


64 out of 100 based on 39 user ratings 474 reviews

#