diff options
author | Walter Purcaro <vuolter@gmail.com> | 2013-09-19 22:12:07 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2013-10-02 00:22:23 +0200 |
commit | 693e3eb98e0376a9a8b4dd4742f9d05453d52b9f (patch) | |
tree | 4b59a648e9ab9610bbe19f5b5db824c398d84f2c /pyload | |
parent | small bug fixes (diff) | |
download | pyload-693e3eb98e0376a9a8b4dd4742f9d05453d52b9f.tar.xz |
Added fs_bsize method to utils
Diffstat (limited to 'pyload')
-rw-r--r-- | pyload/utils/fs.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/pyload/utils/fs.py b/pyload/utils/fs.py index 52bf0bd51..bffb23016 100644 --- a/pyload/utils/fs.py +++ b/pyload/utils/fs.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import ctypes import os import sys from os.path import join @@ -12,7 +13,8 @@ if sys.getfilesystemencoding().startswith('ANSI'): def fs_encode(string): if type(string) == unicode: return string.encode('utf8') - return string + else: + return string fs_decode = decode #decode utf8 @@ -65,13 +67,20 @@ def free_space(folder): folder = fs_encode(folder) if os.name == "nt": - import ctypes - free_bytes = ctypes.c_ulonglong(0) ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) return free_bytes.value else: - from os import statvfs - - s = statvfs(folder) + s = os.statvfs(folder) return s.f_frsize * s.f_bavail + +def fs_bsize(path): + path = fs_encode(path) + + if os.name == "nt": + drive = "%s\\" % os.path.splitdrive(path)[0] + cluster_sectors, sector_size = ctypes.c_longlong(0) + ctypes.windll.kernel32.GetDiskFreeSpaceW(ctypes.c_wchar_p(drive), ctypes.pointer(cluster_sectors), ctypes.pointer(sector_size), None, None) + return cluster_sectors * sector_size + else: + return os.statvfs(path).f_bsize |