]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/util.py
7 def parse_search_query(query
):
9 for word
in query
.split():
10 # Is this lexeme negated?
11 negated
= word
.startswith("!")
13 # Remove any special characters
14 word
= re
.sub(r
"\W+", "", word
, flags
=re
.UNICODE
)
26 def format_size(s
, max_unit
=None):
27 units
= ("B", "kB", "MB", "GB", "TB")
30 while s
>= 1024 and i
< len(units
) - 1:
34 if max_unit
and units
[i
] == max_unit
:
37 return "%.0f%s" % (s
, units
[i
])
39 def format_time(s
, shorter
=True):
40 #_ = handler.locale.translate
43 hrs
, s
= divmod(s
, 3600)
44 min, s
= divmod(s
, 60)
49 if shorter
and not hrs
:
50 return _("%(min)d min") % { "min" : min }
52 return _("%(hrs)d:%(min)02d hrs") % {"hrs" : hrs
, "min" : min}
54 def random_string(length
=8):
55 input_chars
= string
.ascii_letters
+ string
.digits
57 r
= (random
.choice(input_chars
) for i
in range(length
))