当前位置: 首页>>代码示例>>Python>>正文


Python os.statvfs_result方法代码示例

本文整理汇总了Python中os.statvfs_result方法的典型用法代码示例。如果您正苦于以下问题:Python os.statvfs_result方法的具体用法?Python os.statvfs_result怎么用?Python os.statvfs_result使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.statvfs_result方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_mount_points

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def set_mount_points(self, points, read_access=True, fs='ext4'):
        """
        This method prepares a fake mounts file containing the
        mount points specified in the C{points} list of strings. This file
        can then be used by referencing C{self.mount_file}.

        If C{read_access} is set to C{False}, then all mount points will
        yield a permission denied error when inspected.
        """
        self.read_access = read_access
        content = "\n".join("/dev/sda%d %s %s rw 0 0" % (i, point, fs)
                            for i, point in enumerate(points))
        f = open(self.mount_file, "w")
        f.write(content)
        f.close()
        for point in points:
            self.stat_results[point] = os.statvfs_result(
                (4096, 0, 1000, 500, 0, 0, 0, 0, 0, 0)) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:20,代码来源:test_disk.py

示例2: test_ignore_unmounted_and_virtual_mountpoints

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def test_ignore_unmounted_and_virtual_mountpoints(self):
        """
        Make sure autofs and virtual mountpoints are ignored. This is to
        ensure non-regression on bug #1045374.
        """
        self.read_access = True
        content = "\n".join(["auto_direct /opt/whatever autofs",
                             "none /run/lock tmpfs",
                             "proc /proc proc",
                             "/dev/sda1 /home ext4"])

        f = open(self.mount_file, "w")
        f.write(content)
        f.close()

        self.stat_results["/home"] = os.statvfs_result(
            (4096, 0, 1000, 500, 0, 0, 0, 0, 0, 0))

        result = [x for x in get_mount_info(self.mount_file, self.statvfs)]
        expected = {"device": "/dev/sda1", "mount-point": "/home",
                    "filesystem": "ext4", "total-space": 3, "free-space": 1}
        self.assertEqual([expected], result) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:24,代码来源:test_disk.py

示例3: test_statvfs_result_pickle

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def test_statvfs_result_pickle(self):
        try:
            result = os.statvfs(self.fname)
        except OSError as e:
            # On AtheOS, glibc always returns ENOSYS
            if e.errno == errno.ENOSYS:
                self.skipTest('os.statvfs() failed with ENOSYS')

        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            p = pickle.dumps(result, proto)
            self.assertIn(b'statvfs_result', p)
            if proto < 4:
                self.assertIn(b'cos\nstatvfs_result\n', p)
            unpickled = pickle.loads(p)
            self.assertEqual(result, unpickled) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_os.py

示例4: add_mount

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def add_mount(self, point, block_size=4096, capacity=1000, unused=1000,
                  fs="ext3", device=None):
        if device is None:
            device = "/dev/" + point.replace("/", "_")
        self.stat_results[point] = os.statvfs_result(
            (block_size, 0, capacity, unused, 0, 0, 0, 0, 0, 0))
        f = open(self.mount_file, "a")
        f.write("/dev/%s %s %s rw 0 0\n" % (device, point, fs))
        f.close() 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:11,代码来源:test_disk.py

示例5: statvfs_result_fixture

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def statvfs_result_fixture(path):
    """Fixture for a dummy statvfs_result."""
    return os.statvfs_result((4096, 0, mb(1000), mb(100), 0, 0, 0, 0, 0, 0)) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:5,代码来源:test_mountinfo.py

示例6: get_mount_info

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def get_mount_info(self, *args, **kwargs):
        if "mounts_file" not in kwargs:
            kwargs["mounts_file"] = self.makeFile("/dev/hda1 / ext3 rw 0 0\n")
        if "mtab_file" not in kwargs:
            kwargs["mtab_file"] = self.makeFile("/dev/hda1 / ext3 rw 0 0\n")
        if "statvfs" not in kwargs:
            kwargs["statvfs"] = lambda path: os.statvfs_result(
                (0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
        plugin = MountInfo(*args, **kwargs)
        # To make sure tests are isolated from the real system by default.
        plugin.is_device_removable = lambda x: False
        return plugin 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:14,代码来源:test_mountinfo.py

示例7: test_read_changing_total_space

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def test_read_changing_total_space(self):
        """
        Total space measurements are only sent when (a) none have ever
        been sent, or (b) the value has changed since the last time
        data was collected.  The test sets the mount info plugin
        interval to the same value as the step size and advances the
        reactor such that the plugin will be run twice.  Each time it
        runs it gets a different value from our sample statvfs()
        function which should cause it to queue new messages.
        """
        counter = mock_counter(1)

        def statvfs(path, multiplier=lambda: next(counter)):
            return os.statvfs_result(
                (4096, 0, mb(multiplier() * 1000), mb(100), 0, 0, 0, 0, 0, 0))

        plugin = self.get_mount_info(
            statvfs=statvfs, create_time=self.reactor.time,
            interval=self.monitor.step_size)
        self.monitor.add(plugin)

        self.reactor.advance(self.monitor.step_size * 2)

        message = plugin.create_mount_info_message()
        mount_info = message["mount-info"]
        self.assertEqual(len(mount_info), 2)

        for i, total_space in enumerate([4096000, 8192000]):
            self.assertEqual(mount_info[i][0],
                             (i + 1) * self.monitor.step_size)
            self.assertEqual(mount_info[i][1],
                             {"device": "/dev/hda1", "filesystem": "ext3",
                              "mount-point": "/", "total-space": total_space}) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:35,代码来源:test_mountinfo.py

示例8: test_get_filesystem_subpath

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def test_get_filesystem_subpath(self):
        self.set_mount_points(["/"])
        self.stat_results["/"] = os.statvfs_result(
            (4096, 0, 1000, 500, 0, 0, 0, 0, 0, 0))
        info = get_filesystem_for_path("/home", self.mount_file, self.statvfs)
        self.assertEqual(info["mount-point"], "/") 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:8,代码来源:test_disk.py

示例9: test_statvfs_attributes

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def test_statvfs_attributes(self):
        try:
            result = os.statvfs(self.fname)
        except OSError as e:
            # On AtheOS, glibc always returns ENOSYS
            if e.errno == errno.ENOSYS:
                self.skipTest('os.statvfs() failed with ENOSYS')

        # Make sure direct access works
        self.assertEqual(result.f_bfree, result[3])

        # Make sure all the attributes are there.
        members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files',
                    'ffree', 'favail', 'flag', 'namemax')
        for value, member in enumerate(members):
            self.assertEqual(getattr(result, 'f_' + member), result[value])

        # Make sure that assignment really fails
        try:
            result.f_bfree = 1
            self.fail("No exception raised")
        except AttributeError:
            pass

        try:
            result.parrot = 1
            self.fail("No exception raised")
        except AttributeError:
            pass

        # Use the constructor with a too-short tuple.
        try:
            result2 = os.statvfs_result((10,))
            self.fail("No exception raised")
        except TypeError:
            pass

        # Use the constructor with a too-long tuple.
        try:
            result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
        except TypeError:
            pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:44,代码来源:test_os.py

示例10: test_read_disjointed_changing_total_space

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs_result [as 别名]
def test_read_disjointed_changing_total_space(self):
        """
        Total space measurements are only sent when (a) none have ever
        been sent, or (b) the value has changed since the last time
        data was collected.  This test ensures that the (b) criteria
        is checked per-mount point.  The sample statvfs() function
        only provides changing total space for /; therefore, new
        messages should only be queued for / after the first message
        is created.
        """
        counter = mock_counter(1)

        def statvfs(path, multiplier=lambda: next(counter)):
            if path == "/":
                return os.statvfs_result(
                    (4096, 0, mb(1000), mb(100), 0, 0, 0, 0, 0, 0))
            return os.statvfs_result(
                (4096, 0, mb(multiplier() * 1000), mb(100), 0, 0, 0, 0, 0, 0))

        filename = self.makeFile("""\
/dev/hda1 / ext3 rw 0 0
/dev/hde1 /mnt/hde1 ext3 rw 0 0
""")
        plugin = self.get_mount_info(mounts_file=filename, statvfs=statvfs,
                                     create_time=self.reactor.time,
                                     interval=self.monitor.step_size,
                                     mtab_file=filename)
        self.monitor.add(plugin)

        self.reactor.advance(self.monitor.step_size * 2)

        message = plugin.create_mount_info_message()
        self.assertTrue(message)

        mount_info = message.get("mount-info", ())
        self.assertEqual(len(mount_info), 3)

        self.assertEqual(mount_info[0][0], self.monitor.step_size)
        self.assertEqual(mount_info[0][1],
                         {"device": "/dev/hda1", "mount-point": "/",
                          "filesystem": "ext3", "total-space": 4096000})

        self.assertEqual(mount_info[1][0], self.monitor.step_size)
        self.assertEqual(mount_info[1][1],
                         {"device": "/dev/hde1", "mount-point": "/mnt/hde1",
                          "filesystem": "ext3", "total-space": 4096000})

        self.assertEqual(mount_info[2][0], self.monitor.step_size * 2)
        self.assertEqual(mount_info[2][1],
                         {"device": "/dev/hde1", "mount-point": "/mnt/hde1",
                          "filesystem": "ext3", "total-space": 8192000}) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:53,代码来源:test_mountinfo.py


注:本文中的os.statvfs_result方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。