#3276: System quota support
----------------------+-------------------------------
Reporter: alexgeek | Type: feature-request
Status: new | Priority: minor
Milestone: 1.3.16 | Component: Core
Version: 1.3.15 | Keywords: quota, free_space
----------------------+-------------------------------
Hi,
Deluge is used often by every kind of a seedbox provider and usually they
use Linux quota to restrict free disk space for each user on a shared
server. This creates a problem with showing incorrect free disk space in
Deluge on which depends plugins like AutoRemovePlus, because currently it
calculates free space on an entire volume instead of using quota.
I made some changes in common.py free_space function to support quota and
I hope you will integrate them in some way in the future. I'm not a python
developer, so sorry if my code is bad.
In the end it returns an amount of bytes left by defined quota for an
user.
Example of quota -u -w output:
{{{
Disk quotas for user alex (uid 1999):
Filesystem blocks quota limit grace files quota limit
grace
/dev/sda1 668981152 2097152000 2097152000 6509 0
0
}}}
New free_space function code:
{{{
#!python
def free_space(path):
"""
Gets the free space available at 'path'
:param path: the path to check
:type path: string
:returns: the free space at path in bytes
:rtype: int
:raises InvalidPathError: if the path is not valid
"""
if not path or not os.path.exists(path):
raise InvalidPathError("%s is not a valid path" % path)
if windows_check():
from win32file import GetDiskFreeSpaceEx
return GetDiskFreeSpaceEx(path)[0]
else:
def default_method(path):
disk_data = os.statvfs(path.encode("utf8"))
block_size = disk_data.f_frsize
return disk_data.f_bavail * block_size
quota = '/usr/bin/quota'
awk = '/usr/bin/awk'
if not os.path.isfile(quota) or not os.path.isfile(awk):
return default_method(path)
quota_cmd = ['/usr/bin/quota', '-u', '-w']
awk_cmd = ['/usr/bin/awk', 'END {printf "%.0f", ($3-$2)*1024}']
quota_process = subprocess.Popen(quota_cmd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output_q, error_q = quota_process.communicate()
if quota_process.returncode != 0 or len(error_q) > 0:
return default_method(path)
awk_process = subprocess.Popen(awk_cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output_a, error_a = awk_process.communicate(input=output_q)
if awk_process.returncode != 0 or len(error_a) > 0:
return default_method(path)
try:
return int(output_a)
except ValueError:
return default_method(path)
}}}
--
Ticket URL: <https://dev.deluge-torrent.org/ticket/3276>
Deluge <https://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups
"Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/deluge-dev.
To view this discussion on the web visit
https://groups.google.com/d/msgid/deluge-dev/047.fe1aac3637afe93d2f1b65fdb3ed3532%40deluge-torrent.org.
For more options, visit https://groups.google.com/d/optout.