from .obj import PpBaseObjectError, PpBaseObject
-__version__ = '0.3.1'
+__version__ = '0.4.1'
LOG = logging.getLogger(__name__)
if six.PY2:
kilo = long(1024)
+ human_limit = 1.5
+
factor = {}
+ hlimits = {}
for unit in DU_UNIT_EXP.keys():
exp = DU_UNIT_EXP[unit]
factor[unit] = kilo ** exp
+ hlimits[unit] = human_limit * float(factor[unit])
locale_conv = locale.localeconv()
dp = '.'
unit_show = ''
precision = 0
else:
+ # Human readable
unit_show = 'K'
size_float = float(self.size_kb)
- prec = 0
- for u in ('T', 'G', 'M'):
- limit = 1.5 * float(self.factor[u])
- sz_f = float(self.size_kb) / float(self.factor[u])
- if sz_f >= limit:
- unit_show = u
- size_float = sz_f
- if precision < 1:
- prec = 1
- else:
- prec = precision
- break
- if unit_show == 'K':
- precision = 0
- else:
- precision = prec
-
+ precision = 0
+ if self.verbose > 2:
+ LOG.debug("Checking size_float {s} for factors\n{f}".format(
+ s=size_float, f=pp(self.hlimits)))
+
+ if size_float > self.hlimits['T']:
+ unit_show = 'T'
+ size_float = size_float / float(self.factor['T'])
+ precision = 1
+ elif size_float > self.hlimits['G']:
+ unit_show = 'G'
+ size_float = size_float / float(self.factor['G'])
+ precision = 1
+ elif size_float > self.hlimits['M']:
+ unit_show = 'M'
+ size_float = size_float / float(self.factor['M'])
+ precision = 1
+ if self.verbose > 2:
+ LOG.debug("Computed size_float: {s} {u}".format(
+ s=size_float, u=unit_show))
+
+ if unit_show != '':
+ unit_show = ' ' + unit_show
template = "{{:,.{:d}f}}".format(precision) + unit_show
size_show = template.format(size_float)
return size_show
# -------------------------------------------------------------------------
- def to_str(self, unit='K', precision=0, size_with=5):
+ def to_str(self, unit='K', precision=0, size_width=None):
+
+ width = 16
+ unit = unit.upper()
+ if size_width is None:
+ if unit == 'K':
+ width = 16
+ elif unit == 'M':
+ width = 13
+ if precision:
+ width += 1 + precision
+ elif unit == 'G':
+ width = 9
+ if precision:
+ width += 1 + precision
+ elif unit == 'T':
+ width = 5
+ if precision:
+ width += 1 + precision
+ else:
+ # Human
+ width = 9
+ else:
+ width = size_width
size_show = self.size_str(unit=unit, precision=precision)
- line = "{0:>{w}s} {1}".format(size_show, self.path, w=size_with)
+ line = "{0:>{w}s} {1}".format(size_show, self.path, w=width)
return line
except ImportError:
from .global_version import __version__ as my_version
-__version__ = '0.4.1'
+__version__ = '0.4.2'
LOG = logging.getLogger(__name__)
return
LOG.debug("Entry:\n{}".format(pp(entry.as_dict())))
- LOG.debug("Entry: {}".format(entry.to_str(unit='M', precision=1, size_with=10)))
+ print(entry.to_str(unit=self.unit, precision=self.precision))
# =============================================================================