2

I am trying to create a python script to install and configure certain program automatically in linux machines.

My idea is to use the platform and multiprocessing libraries to ask for system information (platform.system, platform.linux_distribution, multiprocessing.cpu_count, etc), and then install the software and create a text file for the software configuration depending on what I get with those calls.

I am having problems determining the OS and distro: I need to know what linux distribution the script is running in so I can launch the appropriate command, and the information I am looking for is not on the python documentation.

According to that documentation ( http://docs.python.org/2/library/platform.html ), platform.system

Returns the system/OS name, e.g. 'Linux', 'Windows', or 'Java'. An empty string is returned if the value cannot be determined.

and platform.linux_distribution

Tries to determine the name of the Linux OS distribution name.

(...)

Returns a tuple (distname,version,id) which defaults to the args given as parameters. id is the item in parentheses after the version number. It is usually the version codename.

But it's not specific enough and does not mention any particular cases.

I have tried these variables on my machine (platform.system returns 'Linux' and platform.linux_distribution 'debian'), but I have no way of trying it in other systems (And I don't think it's feasible to create virtual machines for every linux distro out there and try it in each one)

I need to know exactly what distname string platform.linux_distribution outputs in different linux distributions so I can use those values in my script.

I also need confirmation about if platform.system returns the same thing in every single linux distribution. Are there any exceptions to this?

Community
  • 1
  • 1
  • possible duplicate of [Possible values from sys.platform?](http://stackoverflow.com/questions/446209/possible-values-from-sys-platform) – alko Nov 22 '13 at 13:19
  • @alko I have checked that and some other questions, but they don't answer what I am asking. –  Nov 22 '13 at 16:21

1 Answers1

1

First, consulting the code, platform.system wraps over os.uname. Latter for later *nix, is uname command call. Some possible values are provided in wiki.

Second, linux_distribution roughly speaking, do head /etc/file where file is the first file ending with release or version. That is, for debian/ubuntu, for example, head /etc/debian_version. It splits then resulting line and returns whenever tuple found.

Some examples of linux_distribution output for Linux based platforms that I have access to:

$ python -c 'import platform; print platform.linux_distribution()'
('debian', 'squeeze/sid', '')
('debian', 'wheezy/sid', '')
('SUSE Linux Enterprise Server ', '11', 'x86_64')
('Red Hat Enterprise Linux Server', '5.9', 'Tikanga')
('Red Hat Enterprise Linux Server', '6.4', 'Santiago')

I think you can get the pattern here. I personaly won't rely on linux_distribution, there are known issues when, for example, /etc/debian_version content can be mangled after upgrade.

alko
  • 46,136
  • 12
  • 94
  • 102
  • 3
    Thanks, that clears things a bit. Is there any reasonable alternative to linux_distribution for what I am trying to do? I don't have much experience in python (This is the first thing I do with it) and I don't exactly know how far I can go with it. –  Nov 23 '13 at 20:00