mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] show usage quota status
This commit is contained in:
parent
a4ab551447
commit
81379e3031
2 changed files with 21 additions and 2 deletions
|
@ -30,6 +30,9 @@ import random
|
||||||
import string
|
import string
|
||||||
import json
|
import json
|
||||||
import errno
|
import errno
|
||||||
|
import subprocess
|
||||||
|
import math
|
||||||
|
import re
|
||||||
|
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
|
|
||||||
|
@ -376,9 +379,24 @@ def user_info(auth, username):
|
||||||
result_dict['mail-forward'] = user['maildrop'][1:]
|
result_dict['mail-forward'] = user['maildrop'][1:]
|
||||||
|
|
||||||
if 'mailuserquota' in user:
|
if 'mailuserquota' in user:
|
||||||
result_dict['mailbox-quota'] = user['mailuserquota'][0]
|
if user['mailuserquota'][0] != '0':
|
||||||
|
cmd = 'doveadm -f flow quota get -u %s' % user['uid'][0]
|
||||||
|
userquota = subprocess.check_output(cmd,stderr=subprocess.STDOUT,
|
||||||
|
shell=True)
|
||||||
|
quotavalue = re.findall(r'\d+', userquota)
|
||||||
|
result = '%s / %s (%s%s)' % ( _convertSize(eval(quotavalue[0])), user['mailuserquota'][0], quotavalue[2], '%')
|
||||||
|
result_dict['mailbox-quota'] = result
|
||||||
|
else:
|
||||||
|
result_dict['mailbox-quota'] = m18n.n('unlimit')
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return result_dict
|
return result_dict
|
||||||
else:
|
else:
|
||||||
raise MoulinetteError(167, m18n.n('user_info_failed'))
|
raise MoulinetteError(167, m18n.n('user_info_failed'))
|
||||||
|
|
||||||
|
def _convertSize(num, suffix=''):
|
||||||
|
for unit in ['K','M','G','T','P','E','Z']:
|
||||||
|
if abs(num) < 1024.0:
|
||||||
|
return "%3.1f%s%s" % (num, unit, suffix)
|
||||||
|
num /= 1024.0
|
||||||
|
return "%.1f%s%s" % (num, 'Yi', suffix)
|
||||||
|
|
|
@ -181,6 +181,7 @@
|
||||||
"pattern_email" : "Must be a valid email address (e.g. someone@domain.org)",
|
"pattern_email" : "Must be a valid email address (e.g. someone@domain.org)",
|
||||||
"pattern_password" : "Must be at least 3 characters long",
|
"pattern_password" : "Must be at least 3 characters long",
|
||||||
"pattern_mailbox_quota" : "Must be a size with b/k/M/G/T suffix or 0 to disable the quota",
|
"pattern_mailbox_quota" : "Must be a size with b/k/M/G/T suffix or 0 to disable the quota",
|
||||||
|
"unlimit" : "No quota",
|
||||||
"pattern_domain" : "Must be a valid domain name (e.g. my-domain.org)",
|
"pattern_domain" : "Must be a valid domain name (e.g. my-domain.org)",
|
||||||
"pattern_listname" : "Must be alphanumeric and underscore characters only",
|
"pattern_listname" : "Must be alphanumeric and underscore characters only",
|
||||||
"pattern_port" : "Must be a valid port number (i.e. 0-65535)",
|
"pattern_port" : "Must be a valid port number (i.e. 0-65535)",
|
||||||
|
|
Loading…
Add table
Reference in a new issue