當前位置: 首頁>>代碼示例>>Python>>正文


Python psutil.disk_partitions方法代碼示例

本文整理匯總了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
                } 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:21,代碼來源:system_status.py

示例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 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:27,代碼來源:system_status.py

示例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 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:26,代碼來源:system_status.py

示例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 "" 
開發者ID:adwuard,項目名稱:OP_Manager,代碼行數:22,代碼來源:OP_1_Connection.py

示例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 
開發者ID:Mebus,項目名稱:restatic,代碼行數:25,代碼來源:umount.py

示例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 
開發者ID:cloudviz,項目名稱:agentless-system-crawler,代碼行數:18,代碼來源:disk_utils.py

示例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()) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:24,代碼來源:test_misc.py

示例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)) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:test_linux.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:20,代碼來源:test_linux.py

示例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) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:24,代碼來源:test_linux.py

示例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" 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:20,代碼來源:test_linux.py

示例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)) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:22,代碼來源:disk_usage.py

示例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 
開發者ID:510908220,項目名稱:heartbeats,代碼行數:22,代碼來源:script.py

示例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)) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:19,代碼來源:_blockdevice.py

示例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 
開發者ID:turingsec,項目名稱:marsnake,代碼行數:19,代碼來源:disk_status.py


注:本文中的psutil.disk_partitions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。