本文整理汇总了Python中util.Util.compare_versions方法的典型用法代码示例。如果您正苦于以下问题:Python Util.compare_versions方法的具体用法?Python Util.compare_versions怎么用?Python Util.compare_versions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Util
的用法示例。
在下文中一共展示了Util.compare_versions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: kernel_version
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import compare_versions [as 别名]
def kernel_version(min=None, max=None):
"""
Return kernel version or test for a minimum and/or maximum version
min -- minimal kernel version required
max -- maximum kernel version required
"""
if not Firewall._kernelversion:
# query iptables version
kvcmd = subprocess.Popen(Firewall.kernelversioncmd,
stdout=subprocess.PIPE)
result = kvcmd.communicate()[0]
Firewall._kernelversion = result.strip()
# still no version number? - raise PyromanException(an exception)
if not Firewall._kernelversion:
raise Error("Couldn't get kernel version!")
if not min and not max:
return Firewall._kernelversion
if min:
if Util.compare_versions(Firewall._kernelversion, min) < 0:
return False
if max:
if Util.compare_versions(Firewall._kernelversion, max) > 0:
return False
return True
示例2: version
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import compare_versions [as 别名]
def version(min=None, max=None):
"""
Return iptables version or test for a minimum and/or maximum version
min -- minimal iptables version required
max -- maximum iptables version required
"""
if not Iptables._version:
# query iptables version
ivcmd = subprocess.Popen(Iptables.iptablesversion,
stdout=subprocess.PIPE)
ivstr = ivcmd.communicate()[0]
m = Iptables.match_version.match(ivstr)
if m and m.group(1):
Iptables._version = m.group(1)
# still no version number? - raise an exception
if not Iptables._version:
raise Error("Couldn't get iptables version!")
if not min and not max:
return Iptables._version
if min:
if Util.compare_versions(Iptables._version, min) < 0: return False
if max:
if Util.compare_versions(Iptables._version, max) > 0: return False
return True