Page 2 of 3

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 9:41 am
by Spark
http://docs.python.org/library/statvfs.html

Deprecated since version 2.6: The statvfs module has been deprecated for removal in Python 3.0. [-_-]' how to replace this ? visibly it doesn't work with big filesystems

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 10:08 am
by Spark
I looked the sabnzb sources and I found where freespace where used :

misc.py, line 1222 :

#------------------------------------------------------------------------------
# Diskfree
try:
os.statvfs
import statvfs
# posix diskfree
def diskfree(_dir):
""" Return amount of free diskspace in GBytes
"""
try:
s = os.statvfs(_dir)
return (s[statvfs.F_BAVAIL] * s[statvfs.F_FRSIZE]) / GIGI
except OSError:
return 0.0
def disktotal(_dir):
""" Return amount of total diskspace in GBytes
"""
try:
s = os.statvfs(_dir)
return (s[statvfs.F_BLOCKS] * s[statvfs.F_FRSIZE]) / GIGI
except OSError:
return 0.0

and after there is a specific part for windows.

Since os.statvfs is deprecated, why don't use a specific system call for unix/linux to replace this ? Something like system("df -kP") with appropriated string management ?

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 10:20 am
by shypike
Spark wrote:I looked the sabnzb sources and I found where freespace where used :
Since os.statvfs is deprecated, why don't use a specific system call for unix/linux to replace this ? Something like system("df -kP") with appropriated string management ?
Yeah sure, and taking into account the 10.000 different flavours of Linux/BSD/Whatever distributions :)
We use Python as an abstraction layer for OS quirks.
Only for Windows and OSX we use platform-specific calls.
But these OSses have shown reasonable backward-compatibility over the years.

Have you checked if all statvfs fields are off?
There are quite a few:

import os
s = os.statvfs("/volume1")
print s

Specifically, what is the value of f_ffree and f_favail ?

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 11:01 am
by Spark
Here is the result :

posix.statvfs_result(f_bsize=4096, f_frsize=4096, f_blocks=-1181073360, f_bfree=-1181318537, f_bavail=-1181344137, f_files=790888448, f_ffree=790887260, f_favail=790887260, f_flag=0, f_namemax=255)

With df , then -P is a posix standard

[ root@Synology: ~ ] $ df --help
BusyBox v1.16.1 (2011-06-29 11:52:19 CST) multi-call binary.

Usage: df [-Pkmh] [FILESYSTEM]...

Print filesystem usage statistics

Options:
-P POSIX output format
-k 1024-byte blocks (default)
-m 1M-byte blocks
-h Human readable (e.g. 1K 243M 2G)

df -kP will normally works on all Linux/BSD/Aix platforms

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 11:02 am
by Spark
[ root@Synology: ~ ] $ df -P /volume1/downloads/
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/vg1/volume_1 12455575744 980708 12454492636 0% /volume1

[ root@Synology: ~ ] $ df -Pk /volume1/downloads/
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/vg1/volume_1 12455575744 980708 12454492636 0% /volume1


I think you can use this method for linux as you use specific code for windows.

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 11:22 am
by shypike
The statvfs function on Synology's Python isn't capable of handling your disk size. Bad luck.
Please complain to Synology as well.
The os.statvfs function itself isn't deprecated, only the constants like statvfs.F_FRSIZE are.
I'll change the code accordingly, but that won't solve your problem.

BTW: I don't think it's a good idea to run a process every time the queue page is refreshed (potentially every second).
So I'm not going to use the "df" command.

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 11:24 am
by Spark
I understand. But I'm pretty sure that statvfs calls df or wathever system call backsides :p

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 11:26 am
by shypike
A system call is much cheaper than the whole enchilada of starting an external process.

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 11:31 am
by shypike
BTW: I can replace a negative number by something like "plenty".
Or leave it out altogether.
Also, I can interpret a negative number as being on the safe side of your limit.
The limit will only be effective when the free space has dropped far enough.

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 1:36 pm
by Spark
I made a dirty modification to my misc.py (and after deleted misc.pyo)

def diskfree(_dir):
""" Return amount of free diskspace in GBytes
"""
try:
proc=subprocess.Popen( "df -kP "+_dir, stdout=subprocess.PIPE, shell=True )
result=int(proc.stdout.read().split("\n")[1].split()[3]) / ( 1024 * 1024 )
proc.wait()
return result
except :
return 0.0
def disktotal(_dir):
""" Return amount of total diskspace in GBytes
"""
try:
proc=subprocess.Popen( "df -kP "+_dir, stdout=subprocess.PIPE, shell=True )
result=int(proc.stdout.read().split("\n")[1].split()[1]) / ( 1024 * 1024 )
proc.wait()
return result
except :
return 0.0

and it works perfectly :D

A better solution is to place my downloads folder in a smaller directory. I think there is a 8To limit for statvfs to work fine.

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 1:48 pm
by shypike
Spark wrote:I made a dirty modification to my misc.py (and after deleted misc.pyo)
and it works perfectly :D
I think there is a 8To limit for statvfs to work fine.
1. Just don't set the refresh rate too high :)
2. The implementer of os.statvfs clearly didn't think ahead.
The numbers are returned as short integers instead of long :(
To paraphrase Bill Gates: "8T should be enough for anyone".

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 2:27 pm
by Spark
I made a small modification. I replace int by float and return result by return round(result,2). It looks much better. I expect the return value should be a float because it was displayed with 2 digits, and in the exception code we have : except : return 0.0

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 2:30 pm
by Spark
Just another problem, the icon showing the left space seems to not working. Or it is the 8To limit which slaps again :D

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 3:51 pm
by shypike
I'm just going to limit the numbers to the highest possible values.
So in your case 8T would be shown as disk size.
BTW: whoever ported Python to the Synology platform made an error.
The amount of free/total blocks should be returned as long integers, not standard integers.
(1000L vs. 1000).
Which version of Python do you have? Python 2.6 and 2.7 do it right (at least on Ubuntu).
I don't have access to Python 2.5 for Linux.

Re: SABnzbd fails to regist correct disk space

Posted: July 17th, 2011, 3:59 pm
by Spark
[ root@Synology: ~ ] $ /usr/local/python26/bin/python -V
Python 2.6.6