如何在python脚本中检查系统是否是FreeBSD?

时间:2015-05-03 15:31:43

标签: python python-2.7 freebsd

我想以

的形式在python 2.7.x脚本中添加一个检查
if __check_freebsd__():
    # run actions which would only work on FreeBSD (e.g. create a jail)
elif __check_debian__():
    # run an alternative that runs on Debian-based systems
else:
    raise Error("unsupported OS")

__check_freebsd__函数如何显示?

我已经为__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

所以你不必为此烦恼(当然,欢迎提出改进建议)。

3 个答案:

答案 0 :(得分:3)

如上所述in documentation

<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="onPageLoaded">
  <StackLayout>
    <DatePicker day="15" month="5" year="2015" verticalAlignment="center" id="date"/> 
    <Label text="Saisissez une heure : " verticalAlignment="center"/>
    <TextField verticalAlignment="center" width="300" hint="Enter text..."/>
    <Button text="Valider" tap="see"></Button>
  </StackLayout>
</Page>

返回平台操作系统名称,因此您可以使用它。在this thread中,您还可以看到检查底层操作系统的不同方法。

答案 1 :(得分:1)

请看os.uname

我不是100%肯定,但它可能类似于os.uname()[0] == "FreeBSD"

答案 2 :(得分:1)

试试这个:

# 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'

此外:

AESBlockCipher