]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/util.py
6 def format_size(s
, max_unit
=None):
7 units
= ("B", "kB", "MB", "GB", "TB")
10 while s
>= 1024 and i
< len(units
) - 1:
14 if max_unit
and units
[i
] == max_unit
:
17 return "%.0f%s" % (s
, units
[i
])
19 def format_time(s
, shorter
=True):
20 #_ = handler.locale.translate
23 hrs
, s
= divmod(s
, 3600)
24 min, s
= divmod(s
, 60)
29 if shorter
and not hrs
:
30 return _("%(min)d min") % { "min" : min }
32 return _("%(hrs)d:%(min)02d hrs") % {"hrs" : hrs
, "min" : min}
34 def random_string(length
=8):
35 input_chars
= string
.ascii_letters
+ string
.digits
37 r
= (random
.choice(input_chars
) for i
in range(length
))