[rhmessaging-commits] rhmessaging commits: r3870 - mgmt/trunk/cumin/python/cumin.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Mon Mar 22 10:00:07 EDT 2010
Author: eallen
Date: 2010-03-22 10:00:07 -0400 (Mon, 22 Mar 2010)
New Revision: 3870
Modified:
mgmt/trunk/cumin/python/cumin/formats.py
Log:
Added fmt_bytes(bytes) and fmt_bits(bits)
Modified: mgmt/trunk/cumin/python/cumin/formats.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/formats.py 2010-03-12 18:07:37 UTC (rev 3869)
+++ mgmt/trunk/cumin/python/cumin/formats.py 2010-03-22 14:00:07 UTC (rev 3870)
@@ -1,5 +1,6 @@
from datetime import datetime
from random import random
+from math import floor
from util import *
from wooly import Writer
@@ -158,3 +159,20 @@
writer.write(html % (show_key, str(value[key])))
writer.write("</table>")
return writer.to_string()
+
+def fmt_bytes(num, base="B"):
+ sizes = ("", "K", "M", "G", "T", "P", "Y")
+ k = 1024
+ which_size = 0
+ b = num
+
+ while b >= k:
+ b /= k
+ which_size += 1
+
+ if which_size < len(sizes):
+ return "%.0d%s%s" % (floor(b), sizes[which_size], base)
+ return str(num)
+
+def fmt_bits(bits):
+ return fmt_bytes(bits, base="b")
More information about the rhmessaging-commits
mailing list