VirtualMailManager/common.py
branchv0.6.x
changeset 414 ae1a8428298c
parent 399 fb22773f7a85
child 527 e09139525580
equal deleted inserted replaced
413:e5b3b225bd5b 414:ae1a8428298c
     6     ~~~~~~~~~~~~~~~~~~~~~~~~~
     6     ~~~~~~~~~~~~~~~~~~~~~~~~~
     7 
     7 
     8     Some common functions
     8     Some common functions
     9 """
     9 """
    10 
    10 
       
    11 import locale
    11 import os
    12 import os
    12 import re
    13 import re
    13 import stat
    14 import stat
    14 
    15 
    15 from VirtualMailManager import ENCODING
    16 from VirtualMailManager import ENCODING
    80         return str(size)
    81         return str(size)
    81     prefix_multiply = ((_(u'TiB'), 1 << 40), (_(u'GiB'), 1 << 30),
    82     prefix_multiply = ((_(u'TiB'), 1 << 40), (_(u'GiB'), 1 << 30),
    82                        (_(u'MiB'), 1 << 20), (_(u'KiB'), 1 << 10))
    83                        (_(u'MiB'), 1 << 20), (_(u'KiB'), 1 << 10))
    83     for prefix, multiply in prefix_multiply:
    84     for prefix, multiply in prefix_multiply:
    84         if size >= multiply:
    85         if size >= multiply:
    85             # TP: e.g.: '%(size).2f %(prefix)s' -> '118.30 MiB'
    86             # TP: e.g.: '%(size)s %(prefix)s' -> '118.30 MiB'
    86             return _(u'%(size).2f %(prefix)s') % {
    87             return _(u'%(size)s %(prefix)s') % {
    87                     'size': float(size) / multiply,
    88                     'size': locale.format('%.2f', float(size) / multiply,
       
    89                                           True),
    88                     'prefix': prefix}
    90                     'prefix': prefix}
    89 
    91 
    90 
    92 
    91 def size_in_bytes(size):
    93 def size_in_bytes(size):
    92     """Converts the string `size` to a long (size in bytes).
    94     """Converts the string `size` to a long (size in bytes).