Ockonal Ockonal - 28 days ago 8
Linux Question

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()
('', '', '')

Answer

Works for me on Ubuntu:

('Ubuntu', '10.04', 'lucid')

I then used strace to find out what exactly the platform module is doing to find the distro and it is this part:

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.

Comments