]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/helpers.py
Initial checkin.
[people/shoehn/ipfire.org.git] / www / webapp / helpers.py
1 #!/usr/bin/python
2
3 class Item(object):
4 def __init__(self, **args):
5 self.args = args
6
7 def __getattr__(self, key):
8 return self.args[key]
9
10 def __getitem__(self, key):
11 return self.args[key]
12
13 def __setitem__(self, key, val):
14 self.args[key] = val
15
16
17 def size(s):
18 suffixes = ["B", "K", "M", "G", "T",]
19
20 idx = 0
21 while s >= 1024 and idx < len(suffixes):
22 s /= 1024
23 idx += 1
24
25 return "%.2f %s" % (s, suffixes[idx])