From 81379e3031f29a98a23ab23804bf532afbe7f0e0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Apr 2015 10:53:24 +0000 Subject: [PATCH] [fix] show usage quota status --- lib/yunohost/user.py | 22 ++++++++++++++++++++-- locales/en.json | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/yunohost/user.py b/lib/yunohost/user.py index eb9303390..513d50bf5 100644 --- a/lib/yunohost/user.py +++ b/lib/yunohost/user.py @@ -30,6 +30,9 @@ import random import string import json import errno +import subprocess +import math +import re from moulinette.core import MoulinetteError @@ -376,9 +379,24 @@ def user_info(auth, username): result_dict['mail-forward'] = user['maildrop'][1:] 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: return result_dict else: 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) diff --git a/locales/en.json b/locales/en.json index 25658b9a7..eff603015 100644 --- a/locales/en.json +++ b/locales/en.json @@ -181,6 +181,7 @@ "pattern_email" : "Must be a valid email address (e.g. someone@domain.org)", "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", + "unlimit" : "No quota", "pattern_domain" : "Must be a valid domain name (e.g. my-domain.org)", "pattern_listname" : "Must be alphanumeric and underscore characters only", "pattern_port" : "Must be a valid port number (i.e. 0-65535)",