VMM: Report quota usage/limit/percentage values formatted v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Tue, 22 Feb 2011 20:41:16 +0000
branchv0.6.x
changeset 414 ae1a8428298c
parent 413 e5b3b225bd5b
child 415 c7a963e6cf6e
VMM: Report quota usage/limit/percentage values formatted according to the current LC_ALL setting.
VirtualMailManager/cli/subcommands.py
VirtualMailManager/common.py
--- a/VirtualMailManager/cli/subcommands.py	Tue Feb 22 20:12:18 2011 +0000
+++ b/VirtualMailManager/cli/subcommands.py	Tue Feb 22 20:41:16 2011 +0000
@@ -257,13 +257,16 @@
         else:
             raise
     else:
-        q_limit = u'Storage: %(bytes)s; Messages: %(messages)u'
+        q_limit = u'Storage: %(bytes)s; Messages: %(messages)s'
         if not details:
             info['bytes'] = human_size(info['bytes'])
+            info['messages'] = locale.format('%d', info['messages'], True)
             info['quota limit'] = q_limit % info
             _print_info(ctx, info, _(u'Domain'))
         else:
             info[0]['bytes'] = human_size(info[0]['bytes'])
+            info[0]['messages'] = locale.format('%d', info[0]['messages'],
+                                                True)
             info[0]['quota limit'] = q_limit % info[0]
             _print_info(ctx, info[0], _(u'Domain'))
             if details == u'accounts':
@@ -751,14 +754,14 @@
         }
     else:
         q_usage = {
-            'used': used,
-            'limit': limit,
+            'used': locale.format('%d', used, True),
+            'limit': locale.format('%d', limit, True),
         }
     if limit:
-        q_usage['percent'] = 100. / limit * used
+        q_usage['percent'] = locale.format('%6.2f', 100. / limit * used, True)
     else:
-        q_usage['percent'] = 0.
-    return _(u'[%(percent)6.2f%%] %(used)s/%(limit)s') % q_usage
+        q_usage['percent'] = locale.format('%6.2f', 0, True)
+    return _(u'[%(percent)s%%] %(used)s/%(limit)s') % q_usage
 
 
 def _print_info(ctx, info, title):
--- a/VirtualMailManager/common.py	Tue Feb 22 20:12:18 2011 +0000
+++ b/VirtualMailManager/common.py	Tue Feb 22 20:41:16 2011 +0000
@@ -8,6 +8,7 @@
     Some common functions
 """
 
+import locale
 import os
 import re
 import stat
@@ -82,9 +83,10 @@
                        (_(u'MiB'), 1 << 20), (_(u'KiB'), 1 << 10))
     for prefix, multiply in prefix_multiply:
         if size >= multiply:
-            # TP: e.g.: '%(size).2f %(prefix)s' -> '118.30 MiB'
-            return _(u'%(size).2f %(prefix)s') % {
-                    'size': float(size) / multiply,
+            # TP: e.g.: '%(size)s %(prefix)s' -> '118.30 MiB'
+            return _(u'%(size)s %(prefix)s') % {
+                    'size': locale.format('%.2f', float(size) / multiply,
+                                          True),
                     'prefix': prefix}