【发布时间】:2015-07-12 23:38:19
【问题描述】:
我想在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
因此您不必为此烦恼(当然,欢迎提出改进建议)。
【问题讨论】:
标签: python python-2.7 freebsd