當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。