本文整理汇总了Python中psutil.disk_partitions方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.disk_partitions方法的具体用法?Python psutil.disk_partitions怎么用?Python psutil.disk_partitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.disk_partitions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def __init__(self):
self.timestamp = time.time()
self.cpu_load = []
self.mem = dict(total = 0,
available = 0,
free = 0,
cached = 0,
buffers = 0)
self.disk_partitions = {}
self.network = {}
partitions = psutil.disk_partitions()
for p in partitions:
if p.mountpoint in self.INCLUDED_PARTITIONS:
usage = psutil.disk_usage(p.mountpoint)
self.disk_partitions[p.mountpoint] = {
'total': usage.total,
'used': usage.used
}
示例2: getStatus
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def getStatus(self, max_age=0.8):
"""
Get current system status.
max_age: maximum tolerable age of cached status information. Set to
None to force a refresh regardless of cache age.
Returns a dictionary with fields 'cpu_load', 'mem', 'disk', and
'network'.
"""
timestamp = time.time()
if (max_age is None or timestamp > self.timestamp + max_age):
self.timestamp = timestamp
self.refreshCpuLoad()
self.refreshMemoryInfo()
self.refreshDiskInfo()
self.refreshNetworkTraffic()
result = {
'cpu_load': self.cpu_load,
'mem': self.mem,
'disk': self.disk_partitions,
'network': self.network
}
return result
示例3: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def getSystemInfo(cls):
system = {
'boot_time': psutil.boot_time(),
'cpu_count': psutil.cpu_count(),
'cpu_stats': psutil.cpu_stats().__dict__,
'cpu_times': [k.__dict__ for k in psutil.cpu_times(percpu=True)],
'disk_io_counters': psutil.disk_io_counters().__dict__,
'disk_usage': [],
'net_io_counters': psutil.net_io_counters().__dict__,
'swap_memory': psutil.swap_memory().__dict__,
'virtual_memory': psutil.virtual_memory().__dict__
}
partitions = psutil.disk_partitions()
for p in partitions:
if p.mountpoint in cls.INCLUDED_PARTITIONS:
usage = psutil.disk_usage(p.mountpoint)
system['disk_usage'].append({
'mountpoint': p.mountpoint,
'total': usage.total,
'used': usage.used
})
return system
示例4: getMountPath
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def getMountPath(device):
"""
Checks if the partition is mounted if not it return ""
:param device: Target device being string "OP1" or "OPZ"
:return: "" is not found
"""
mountpath = getmountpath(device)
# mountPoint = ""
for i, disk in enumerate(disk_partitions()):
print(disk)
if disk.device == mountpath:
mountPoint = disk.mountpoint
if device == "OP1":
config["OP_1_Mounted_Dir"] = mountPoint
print(config["OP_1_Mounted_Dir"])
elif device == "OPZ":
config["OP_Z_Mounted_Dir"] = mountPoint
print(config["OP_Z_Mounted_Dir"])
return mountPoint
return ""
示例5: prepare
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def prepare(cls, profile):
ret = super().prepare(profile)
if not ret["ok"]:
return ret
else:
ret["ok"] = False # Set back to false, so we can do our own checks here.
ret["active_mount_points"] = []
partitions = psutil.disk_partitions(all=True)
for p in partitions:
if p.device == "resticfs":
ret["active_mount_points"].append(p.mountpoint)
if len(ret["active_mount_points"]) == 0:
ret["message"] = "No active Restic mounts found."
return ret
cmd = ["restic", "umount", "--log-json"]
ret["ok"] = True
ret["cmd"] = cmd
return ret
示例6: crawl_disk_partitions
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def crawl_disk_partitions():
partitions = []
for partition in psutil.disk_partitions(all=True):
try:
pdiskusage = psutil.disk_usage(partition.mountpoint)
partitions.append((partition.mountpoint, DiskFeature(
partition.device,
100.0 - pdiskusage.percent,
partition.fstype,
partition.mountpoint,
partition.opts,
pdiskusage.total,
), 'disk'))
except OSError:
continue
return partitions
示例7: test_serialization
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def test_serialization(self):
def check(ret):
if json is not None:
json.loads(json.dumps(ret))
a = pickle.dumps(ret)
b = pickle.loads(a)
self.assertEqual(ret, b)
check(psutil.Process().as_dict())
check(psutil.virtual_memory())
check(psutil.swap_memory())
check(psutil.cpu_times())
check(psutil.cpu_times_percent(interval=0))
check(psutil.net_io_counters())
if LINUX and not os.path.exists('/proc/diskstats'):
pass
else:
if not APPVEYOR:
check(psutil.disk_io_counters())
check(psutil.disk_partitions())
check(psutil.disk_usage(os.getcwd()))
check(psutil.users())
示例8: test_disk_partitions_and_usage
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def test_disk_partitions_and_usage(self):
# test psutil.disk_usage() and psutil.disk_partitions()
# against "df -a"
def df(path):
out = sh('df -P -B 1 "%s"' % path).strip()
lines = out.split('\n')
lines.pop(0)
line = lines.pop(0)
dev, total, used, free = line.split()[:4]
if dev == 'none':
dev = ''
total, used, free = int(total), int(used), int(free)
return dev, total, used, free
for part in psutil.disk_partitions(all=False):
usage = psutil.disk_usage(part.mountpoint)
dev, total, used, free = df(part.mountpoint)
self.assertEqual(usage.total, total)
# 10 MB tollerance
if abs(usage.free - free) > 10 * 1024 * 1024:
self.fail("psutil=%s, df=%s" % (usage.free, free))
if abs(usage.used - used) > 10 * 1024 * 1024:
self.fail("psutil=%s, df=%s" % (usage.used, used))
示例9: test_procfs_path
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def test_procfs_path(self):
tdir = tempfile.mkdtemp()
try:
psutil.PROCFS_PATH = tdir
self.assertRaises(IOError, psutil.virtual_memory)
self.assertRaises(IOError, psutil.cpu_times)
self.assertRaises(IOError, psutil.cpu_times, percpu=True)
self.assertRaises(IOError, psutil.boot_time)
# self.assertRaises(IOError, psutil.pids)
self.assertRaises(IOError, psutil.net_connections)
self.assertRaises(IOError, psutil.net_io_counters)
self.assertRaises(IOError, psutil.net_if_stats)
self.assertRaises(IOError, psutil.disk_io_counters)
self.assertRaises(IOError, psutil.disk_partitions)
self.assertRaises(psutil.NoSuchProcess, psutil.Process)
finally:
psutil.PROCFS_PATH = "/proc"
os.rmdir(tdir)
示例10: test_against_df
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def test_against_df(self):
# test psutil.disk_usage() and psutil.disk_partitions()
# against "df -a"
def df(path):
out = sh('df -P -B 1 "%s"' % path).strip()
lines = out.split('\n')
lines.pop(0)
line = lines.pop(0)
dev, total, used, free = line.split()[:4]
if dev == 'none':
dev = ''
total, used, free = int(total), int(used), int(free)
return dev, total, used, free
for part in psutil.disk_partitions(all=False):
usage = psutil.disk_usage(part.mountpoint)
dev, total, used, free = df(part.mountpoint)
self.assertEqual(usage.total, total)
self.assertAlmostEqual(usage.free, free,
delta=TOLERANCE_DISK_USAGE)
self.assertAlmostEqual(usage.used, used,
delta=TOLERANCE_DISK_USAGE)
示例11: test_procfs_path
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def test_procfs_path(self):
tdir = self.get_testfn()
os.mkdir(tdir)
try:
psutil.PROCFS_PATH = tdir
self.assertRaises(IOError, psutil.virtual_memory)
self.assertRaises(IOError, psutil.cpu_times)
self.assertRaises(IOError, psutil.cpu_times, percpu=True)
self.assertRaises(IOError, psutil.boot_time)
# self.assertRaises(IOError, psutil.pids)
self.assertRaises(IOError, psutil.net_connections)
self.assertRaises(IOError, psutil.net_io_counters)
self.assertRaises(IOError, psutil.net_if_stats)
# self.assertRaises(IOError, psutil.disk_io_counters)
self.assertRaises(IOError, psutil.disk_partitions)
self.assertRaises(psutil.NoSuchProcess, psutil.Process)
finally:
psutil.PROCFS_PATH = "/proc"
示例12: main
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def main():
templ = "%-17s %8s %8s %8s %5s%% %9s %s"
print(templ % ("Device", "Total", "Used", "Free", "Use ", "Type",
"Mount"))
for part in psutil.disk_partitions(all=False):
if os.name == 'nt':
if 'cdrom' in part.opts or part.fstype == '':
# skip cd-rom drives with no disk in it; they may raise
# ENOENT, pop-up a Windows GUI error for a non-ready
# partition or just hang.
continue
usage = psutil.disk_usage(part.mountpoint)
print(templ % (
part.device,
bytes2human(usage.total),
bytes2human(usage.used),
bytes2human(usage.free),
int(usage.percent),
part.fstype,
part.mountpoint))
示例13: get_disk_info
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def get_disk_info():
disk_info = []
for part in psutil.disk_partitions(all=False):
if os.name == 'nt':
if 'cdrom' in part.opts or part.fstype == '':
# skip cd-rom drives with no disk in it; they may raise
# ENOENT, pop-up a Windows GUI error for a non-ready
# partition or just hang.
continue
usage = psutil.disk_usage(part.mountpoint)
disk_info.append({
'device': part.device,
'total': usage.total,
'used': usage.used,
'free': usage.free,
'percent': usage.percent,
'fstype': part.fstype,
'mountpoint': part.mountpoint
})
return disk_info
示例14: umount_all
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def umount_all(root_path):
"""
Unmount all devices with mount points contained in ``root_path``.
:param FilePath root_path: A directory in which to search for mount points.
"""
def is_under_root(path):
try:
FilePath(path).segmentsFrom(root_path)
except ValueError:
return False
return True
partitions_under_root = list(p for p in psutil.disk_partitions()
if is_under_root(p.mountpoint))
for partition in partitions_under_root:
umount(FilePath(partition.mountpoint))
示例15: disk_status
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_partitions [as 别名]
def disk_status(response):
#name STATS USED MOUNT FILESYSTEM
for item in psutil.disk_partitions():
device, mountpoint, fstype, opts = item
try:
total, used, free, percent = psutil.disk_usage(mountpoint)
response["disk"][device] = {
"fstype" : fstype,
"total" : common.size_human_readable(total),
"percent" : percent,
"mountpoint" : mountpoint,
"opts" : opts
}
except Exception:
pass