How to check if a FreeBSD system is in a python script?

I would like to add validation in a python 2.7.x script as

 if __check_freebsd__(): # run actions which would only work on FreeBSD (eg create a jail) elif __check_debian__(): # run an alternative that runs on Debian-based systems else: raise Error("unsupported OS") 

What would the __check_freebsd__ function look like?

I already have the following code for __check_debian__ :

 try: lsb_release_id_short = sp.check_output([lsb_release, "-d", "-s"]).strip().decode("utf-8") ret_value = "Debian" in lsb_release_id_short return ret_value except Exception: return False 

So you don’t have to worry about this (suggestions for improvement are welcome, of course).

+5
source share
3 answers

As stated in the documentation ,

 platform.system() 

returns the platform OS name, so you can use this. In this topic, you can also see various approaches to checking the underlying OS.

+2
source

Take a look at os.uname .

I'm not 100% sure, but it will probably be something like os.uname()[0] == "FreeBSD" .

+1
source

Try the following:

 >>> from sys import platform >>> platform() # on my system I get 'linux' # check string for freebsd 

also:

 # below are my results >>> import platform >>> platform.system() 'Linux' # would be 'FreeBSD' if I was using that >>> platform.platform() 'Linux-3.19.0-15-generic-x86_64-with-Ubuntu-15.04-vivid' 
+1
source

All Articles