本文整理汇总了Python中util.Platform.is_darwin方法的典型用法代码示例。如果您正苦于以下问题:Python Platform.is_darwin方法的具体用法?Python Platform.is_darwin怎么用?Python Platform.is_darwin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Platform
的用法示例。
在下文中一共展示了Platform.is_darwin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_system_stats
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
def get_system_stats():
systemStats = {
'machine': platform.machine(),
'platform': sys.platform,
'processor': platform.processor(),
'pythonV': platform.python_version(),
}
platf = sys.platform
if Platform.is_linux(platf):
grep = subprocess.Popen(['grep', 'model name', '/proc/cpuinfo'], stdout=subprocess.PIPE, close_fds=True)
wc = subprocess.Popen(['wc', '-l'], stdin=grep.stdout, stdout=subprocess.PIPE, close_fds=True)
systemStats['cpuCores'] = int(wc.communicate()[0])
if Platform.is_darwin(platf):
systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].split(': ')[1])
if Platform.is_freebsd(platf):
systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].split(': ')[1])
if Platform.is_linux(platf):
systemStats['nixV'] = platform.dist()
elif Platform.is_darwin(platf):
systemStats['macV'] = platform.mac_ver()
elif Platform.is_freebsd(platf):
version = platform.uname()[2]
systemStats['fbsdV'] = ('freebsd', version, '') # no codename for FreeBSD
elif Platform.is_win32(platf):
systemStats['winV'] = platform.win32_ver()
return systemStats
示例2: _host_matches_node
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
def _host_matches_node(self, primary_addrs):
""" For < 0.19, check if the current host matches the IP given in the
cluster nodes check `/_cluster/nodes`. Uses `ip addr` on Linux and
`ifconfig` on Mac
"""
if Platform.is_darwin():
ifaces = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE)
else:
ifaces = subprocess.Popen(["ip", "addr"], stdout=subprocess.PIPE)
grepper = subprocess.Popen(
["grep", "inet"], stdin=ifaces.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
ifaces.stdout.close()
out, err = grepper.communicate()
# Capture the list of interface IPs
ips = []
for iface in out.split("\n"):
iface = iface.strip()
if iface:
ips.append(iface.split(" ")[1].split("/")[0])
# Check the interface addresses against the primary address
return primary_addrs in ips
示例3: get_system_stats
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
def get_system_stats():
systemStats = {
"machine": platform.machine(),
"platform": sys.platform,
"processor": platform.processor(),
"pythonV": platform.python_version(),
}
platf = sys.platform
if Platform.is_linux(platf):
grep = subprocess.Popen(["grep", "model name", "/proc/cpuinfo"], stdout=subprocess.PIPE, close_fds=True)
wc = subprocess.Popen(["wc", "-l"], stdin=grep.stdout, stdout=subprocess.PIPE, close_fds=True)
systemStats["cpuCores"] = int(wc.communicate()[0])
if Platform.is_darwin(platf):
systemStats["cpuCores"] = int(
subprocess.Popen(["sysctl", "hw.ncpu"], stdout=subprocess.PIPE, close_fds=True)
.communicate()[0]
.split(": ")[1]
)
if Platform.is_freebsd(platf):
systemStats["cpuCores"] = int(
subprocess.Popen(["sysctl", "hw.ncpu"], stdout=subprocess.PIPE, close_fds=True)
.communicate()[0]
.split(": ")[1]
)
if Platform.is_linux(platf):
systemStats["nixV"] = platform.dist()
elif Platform.is_darwin(platf):
systemStats["macV"] = platform.mac_ver()
elif Platform.is_freebsd(platf):
version = platform.uname()[2]
systemStats["fbsdV"] = ("freebsd", version, "") # no codename for FreeBSD
elif Platform.is_win32(platf):
systemStats["winV"] = platform.win32_ver()
return systemStats
示例4: parse_df_output
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
def parse_df_output(self, df_output, platform_name, inodes=False, use_mount=False, blacklist_re=None):
"""
Parse the output of the df command. If use_volume is true the volume
is used to anchor the metric, otherwise false the mount
point is used. Returns a tuple of (disk, inode).
"""
usage_data = []
# Transform the raw output into tuples of the df data.
devices = self._transform_df_output(df_output, blacklist_re)
# If we want to use the mount point, replace the volume name on each
# line.
for parts in devices:
try:
if use_mount:
parts[0] = parts[-1]
if inodes:
if Platform.is_darwin(platform_name):
# Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted
# Inodes are in position 5, 6 and we need to compute the total
# Total
parts[1] = int(parts[5]) + int(parts[6]) # Total
parts[2] = int(parts[5]) # Used
parts[3] = int(parts[6]) # Available
elif Platform.is_freebsd(platform_name):
# Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted
# Inodes are in position 5, 6 and we need to compute the total
parts[1] = int(parts[5]) + int(parts[6]) # Total
parts[2] = int(parts[5]) # Used
parts[3] = int(parts[6]) # Available
else:
parts[1] = int(parts[1]) # Total
parts[2] = int(parts[2]) # Used
parts[3] = int(parts[3]) # Available
else:
parts[1] = int(parts[1]) # Total
parts[2] = int(parts[2]) # Used
parts[3] = int(parts[3]) # Available
except IndexError:
self.logger.exception("Cannot parse %s" % (parts,))
usage_data.append(parts)
return usage_data