From 0712da0fd0ead5da89b30d3718382b8ab191835c Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sun, 21 Sep 2008 19:52:47 +0000 Subject: [PATCH] clean up free space --- deluge/common.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/deluge/common.py b/deluge/common.py index 21d0972f7..0bbb8b233 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -385,22 +385,14 @@ def get_path_size(path): dir_size += os.path.getsize(filename) return dir_size -def free_space() - """returns free space in each partition""" - """example: {PARTITION: [TOTAL, AVAIL]}""" - space = {} +def free_space(path): + """returns free space""" if windows_check(): import win32api - drive = get_default_download_dir().split(":")[0] + drive = path.split(":")[0] free = win32api.GetDiskFreeSpaceEx(drive)[0] - total = win32api.GetDiskFreeSpaceEx(drive)[1] - space[drive] = [total, free] + return fsize(free) else: - from subprocess import Popen, PIPE - import re - whitespace_spliter = re.compile("\s+") - output = Popen(["df", "-hP", "--exclude-type=iso9660", "--exclude-type=udf", \ - "--exclude-type=tmpfs", get_default_download_dir], stdout=PIPE).communicate()[0] - modified = whitespace_spliter.split(output.split("\n")[1]) - space[modified[0]] = [modified[1], modified[3]] - return space + disk_data = os.statvfs(path) + block_size = disk_data.f_bsize + return fsize(disk_data.f_bavail * block_size)