From d85657a5c60afc8c9387e830d8250dd0e950dd18 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Wed, 7 Dec 2016 21:54:13 +0100 Subject: [PATCH] [mod] style --- src/yunohost/user.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/yunohost/user.py b/src/yunohost/user.py index 348a23d3..6c73c5ba 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -399,30 +399,38 @@ def user_info(auth, username): if 'mailuserquota' in user: userquota = user['mailuserquota'][0] - if isinstance( userquota, int ): + + if isinstance(userquota, int): userquota = str(userquota) # Test if userquota is '0' or '0M' ( quota pattern is ^(\d+[bkMGT])|0$ ) is_limited = not re.match('0[bkMGT]?', userquota) storage_use = '?' + cmd = 'doveadm -f flow quota get -u %s' % user['uid'][0] + try: - cmd_result = subprocess.check_output(cmd,stderr=subprocess.STDOUT, + cmd_result = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) # Exemple of return value for cmd: # """Quota name=User quota Type=STORAGE Value=0 Limit=- %=0 # Quota name=User quota Type=MESSAGE Value=0 Limit=- %=0""" - has_value=re.search(r'Value=(\d+)', cmd_result) + has_value = re.search(r'Value=(\d+)', cmd_result) + if has_value: storage_use = int(has_value.group(1)) storage_use = _convertSize(storage_use) + if is_limited: - has_percent=re.search(r'%=(\d+)', cmd_result) + has_percent = re.search(r'%=(\d+)', cmd_result) + if has_percent: percentage = int(has_percent.group(1)) - storage_use += ' (%s%s)' % (percentage, '%') + storage_use += ' (%s%%)' % percentage + except subprocess.CalledProcessError: logger.warning(m18n.n('mailbox_used_space_dovecot_down')) + result_dict['mailbox-quota'] = { 'limit' : userquota if is_limited else m18n.n('unlimit'), 'use' : storage_use