conga/luci site/luci/Extensions/HelperFunction ...
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-10-06 22:08:13
Modified files:
luci/site/luci/Extensions: HelperFunctions.py StorageReport.py
luci/storage : form-macros validate_html
Log message:
luci storage: display size in appropriate units (instead of bytes), taking preferred size into account
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/HelperFunctions.py.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/StorageReport.py.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/storage/form-macros.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/storage/validate_html.diff?cvsroot=cluster&r1=1.1&r2=1.2
luci/site/luci/Extensions/HelperFunctions.py +46 -0
@@ -90,3 +90,49 @@ expires='Tue, 30 Jun 2060 12:00:00 GMT') return value + + + + +# returns (str(float), units) that fits best, +# ignores prefered units +def bytes_to_value_units(bytes): + units = 'TB' + if float(convert_bytes(bytes, 'GB')) < 1024: + units = 'GB' + if float(convert_bytes(bytes, 'MB')) < 1024: + units = 'MB' + if float(convert_bytes(bytes, 'KB')) < 1024: + units = 'KB' + if float(convert_bytes(bytes, 'bytes')) < 1024: + units = 'bytes' + return (convert_bytes(bytes, units), units) + +# returns (str(float), units) that fits best, +# takes prefered units into account +def bytes_to_value_prefunits(self, bytes): + p_units = self.REQUEST.SESSION.get('preferred_size_units') + dummy, units = bytes_to_value_units(bytes) + if get_units_multiplier(units) > get_units_multiplier(p_units): + units = p_units + return (convert_bytes(bytes, units), units) + +def get_units_multiplier(units): + if units.lower() == 'bytes': + return 1.0 + elif units.lower() == 'kb': + return 1024.0 + elif units.lower() == 'mb': + return 1024*1024.0 + elif units.lower() == 'gb': + return 1024*1024*1024.0 + elif units.lower() == 'tb': + return 1024*1024*1024*1024.0 + else: + raise "invalid size unit" + +def convert_bytes(bytes, units): + c = int(bytes) / get_units_multiplier(units) + c = str(c) + c = c[:c.find('.') + 3] + return c
luci/site/luci/Extensions/StorageReport.py +148 -47
282 lines not on this page · raw message
luci/storage/form-macros +157 -26
329 lines not on this page · raw message
luci/storage/validate_html +3 -0
@@ -12,6 +12,9 @@ <span tal:omit-tag="" tal:define="global action_type request/action_type|nothing"/> +<span tal:omit-tag="" + tal:define="global preferred_size_units python:here.set_persistant_var('preferred_size_units', 'GB')"/> + <span tal:omit-tag="" tal:condition="not: access_to_host_allowed">