[mod] style

This commit is contained in:
Laurent Peuch 2016-12-07 21:54:13 +01:00
parent dfbfc0cfc7
commit d85657a5c6

View file

@ -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