Exemplo n.º 1
0
    def test_nt_helpers(self):
        # Trivial validation that the helpers do not break, and support both
        # unicode and bytes (UTF-8) paths

        drive, path = ntpath.splitdrive(sys.executable)
        drive = drive.rstrip(ntpath.sep) + ntpath.sep
        self.assertEqual(drive, nt._getvolumepathname(sys.executable))
        self.assertEqual(drive.encode(),
                         nt._getvolumepathname(sys.executable.encode()))

        cap, free = nt._getdiskusage(sys.exec_prefix)
        self.assertGreater(cap, 0)
        self.assertGreater(free, 0)
        b_cap, b_free = nt._getdiskusage(sys.exec_prefix.encode())
        # Free space may change, so only test the capacity is equal
        self.assertEqual(b_cap, cap)
        self.assertGreater(b_free, 0)

        for path in [sys.prefix, sys.executable]:
            final_path = nt._getfinalpathname(path)
            self.assertIsInstance(final_path, str)
            self.assertGreater(len(final_path), 0)

            b_final_path = nt._getfinalpathname(path.encode())
            self.assertIsInstance(b_final_path, bytes)
            self.assertGreater(len(b_final_path), 0)
Exemplo n.º 2
0
    def disk_usage(path):
        """Return disk usage statistics about the given path.

        Returned values is a named tuple with attributes 'total', 'used' and
        'free', which are the amount of total, used and free space, in bytes.
        """
        total, free = nt._getdiskusage(path)
        used = total - free
        return _ntuple_diskusage(total, used, free)
Exemplo n.º 3
0
    def disk_usage(path):
        """Return disk usage statistics about the given path.

        Returned values is a named tuple with attributes 'total', 'used' and
        'free', which are the amount of total, used and free space, in bytes.
        """
        total, free = nt._getdiskusage(path)
        used = total - free
        return _ntuple_diskusage(total, used, free)
Exemplo n.º 4
0
    def disk_usage(path):
        """Return disk usage statistics about the given path.

        Returned value is a dict with keys 'total', 'used' and 'free',
        which are the amount of total, used and free space, in bytes.

        Modified from Python 3.3's shutil.disk_usage.
        """
        total, free = nt._getdiskusage(path)
        used = total - free
        return {'total': total, 'used': used, 'free': free}
Exemplo n.º 5
0
    def disk_usage(path):
        """Return disk usage statistics about the given path.

        Returned value is a dict with keys 'total', 'used' and 'free',
        which are the amount of total, used and free space, in bytes.

        Modified from Python 3.3's shutil.disk_usage.
        """
        total, free = nt._getdiskusage(path)
        used = total - free
        return {'total': total, 'used': used, 'free': free}
Exemplo n.º 6
0
 def disk_usage(path):
     (total, free) = nt._getdiskusage(path)
     used = total - free
     return _ntuple_diskusage(total, used, free)
Exemplo n.º 7
0
    def usage_percentage(path):
        total, free = _getdiskusage(path)

        return (total - free) * 100 / total