Add free disk space detection on Windows (bug 468)
I'm attaching a patch against the current git tree which should fix this, based on the information here: http://mail.python.org/pipermail/python-list/2003-May/203223.html Note that the user will need to have the Python win32 extensions installed - see http://sourceforge.net/projects/pywin32/ - and I have no idea how to include these in the frozen Python binary which is included in the win32 distribution of gpodder. The patch reverts back to the old behavior if it can't find the win32api.
This commit is contained in:
parent
48c6ca8f10
commit
93f6f31c39
4
README
4
README
|
@ -63,6 +63,10 @@
|
|||
|
||||
* python-gtkhtml2
|
||||
|
||||
Additional dependencies for gPodder on Windows:
|
||||
|
||||
* PyWin32 (http://sourceforge.net/projects/pywin32/)
|
||||
|
||||
Additional dependencies if you want to install from source:
|
||||
|
||||
* help2man
|
||||
|
|
|
@ -316,6 +316,27 @@ def file_age_to_string(days):
|
|||
return ''
|
||||
|
||||
|
||||
def get_free_disk_space_win32(path):
|
||||
"""
|
||||
Win32-specific code to determine the free disk space remaining
|
||||
for a given path. Uses code from:
|
||||
|
||||
http://mail.python.org/pipermail/python-list/2003-May/203223.html
|
||||
"""
|
||||
|
||||
drive, tail = os.path.splitdrive(path)
|
||||
|
||||
try:
|
||||
import win32file
|
||||
userFree, userTotal, freeOnDisk = win32file.GetDiskFreeSpaceEx(drive)
|
||||
return userFree
|
||||
except ImportError:
|
||||
log('Warning: Running on Win32 but win32api/win32file not installed.')
|
||||
|
||||
# Cannot determine free disk space
|
||||
return 0
|
||||
|
||||
|
||||
def get_free_disk_space(path):
|
||||
"""
|
||||
Calculates the free disk space available to the current user
|
||||
|
@ -325,13 +346,12 @@ def get_free_disk_space(path):
|
|||
function returns zero.
|
||||
"""
|
||||
|
||||
if gpodder.win32:
|
||||
# FIXME: Implement for win32
|
||||
return 0
|
||||
|
||||
if not os.path.exists(path):
|
||||
return 0
|
||||
|
||||
if gpodder.win32:
|
||||
return get_free_disk_space_win32(path)
|
||||
|
||||
s = os.statvfs(path)
|
||||
|
||||
return s.f_bavail * s.f_bsize
|
||||
|
|
Loading…
Reference in New Issue