git://git.onelab.eu
/
util-vserver-pl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8813a7f
)
More convenient output of show.
author
Faiyaz Ahmed
<faiyaza@cs.princeton.edu>
Wed, 20 Aug 2008 20:50:26 +0000
(20:50 +0000)
committer
Faiyaz Ahmed
<faiyaza@cs.princeton.edu>
Wed, 20 Aug 2008 20:50:26 +0000
(20:50 +0000)
python/bwlimit.py
patch
|
blob
|
history
diff --git
a/python/bwlimit.py
b/python/bwlimit.py
index
1be3bd4
..
60b290e
100644
(file)
--- a/
python/bwlimit.py
+++ b/
python/bwlimit.py
@@
-191,6
+191,24
@@
def get_tc_rate(s):
else:
return -1
else:
return -1
+def format_bytes(bytes, si = True):
+ """
+ Formats bytes into a string
+ """
+ if si:
+ kilo = 1000.
+ else:
+ # Officially, a kibibyte
+ kilo = 1024.
+
+ if bytes >= (kilo * kilo * kilo):
+ return "%.1f GB" % (bytes / (kilo * kilo * kilo))
+ elif bytes >= 1000000:
+ return "%.1f MB" % (bytes / (kilo * kilo))
+ elif bytes >= 1000:
+ return "%.1f KB" % (bytes / kilo)
+ else:
+ return "%.0f bytes" % bytes
def format_tc_rate(rate):
"""
def format_tc_rate(rate):
"""
@@
-686,11
+704,11
@@
def main():
minexemptrate, maxexemptrate,
bytes, exemptbytes)
else:
minexemptrate, maxexemptrate,
bytes, exemptbytes)
else:
- print "%s %d %s %s %s %s %
d %d
" % \
+ print "%s %d %s %s %s %s %
s %s
" % \
(slice, share,
format_tc_rate(minrate), format_tc_rate(maxrate),
format_tc_rate(minexemptrate), format_tc_rate(maxexemptrate),
(slice, share,
format_tc_rate(minrate), format_tc_rate(maxrate),
format_tc_rate(minexemptrate), format_tc_rate(maxexemptrate),
-
bytes, exemptbytes
)
+
format_bytes(bytes), format_bytes(exemptbytes)
)
elif len(argv) >= 2:
# slice, ...
elif len(argv) >= 2:
# slice, ...