SF.net SVN: fclient: [96] trunk/sandbox/fcp/fcp_lib/numbers.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-01 14:41:45
|
Revision: 96
http://fclient.svn.sourceforge.net/fclient/?rev=96&view=rev
Author: jurner
Date: 2008-02-01 06:41:38 -0800 (Fri, 01 Feb 2008)
Log Message:
-----------
comb over
Modified Paths:
--------------
trunk/sandbox/fcp/fcp_lib/numbers.py
Modified: trunk/sandbox/fcp/fcp_lib/numbers.py
===================================================================
--- trunk/sandbox/fcp/fcp_lib/numbers.py 2008-01-30 17:17:10 UTC (rev 95)
+++ trunk/sandbox/fcp/fcp_lib/numbers.py 2008-02-01 14:41:38 UTC (rev 96)
@@ -14,51 +14,63 @@
@return: (str) formated number
>>> format_num_bytes(100)
- '100 b'
+ '100B'
>>> format_num_bytes(1000)
- '1.00 kb'
+ '1.00KB'
>>> format_num_bytes(1024, conform=False)
- '1.00 kb'
+ '1.00KiB'
>>> format_num_bytes(1000, short=False)
- '1.00 Kilobyte'
+ '1.00Kilobyte'
"""
-
- if short:
- names = ('b', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb', 'zb', 'yb')
- else:
- names = ('Byte',
- 'Kilobyte',
- 'Megabyte',
- 'Gigabyte',
- 'Terabyte',
- 'Petabyte',
- 'Exabyte',
- 'Zettabyte',
- 'Yottabyte'
- )
if conform:
factor = 1000
+ if short:
+ names = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
+ else:
+ names = ('Byte',
+ 'Kilobyte',
+ 'Megabyte',
+ 'Gigabyte',
+ 'Terabyte',
+ 'Petabyte',
+ 'Exabyte',
+ 'Zettabyte',
+ 'Yottabyte'
+ )
else:
factor = 1024
-
- num = float(num)
+ if short:
+ names = ('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')
+ else:
+ names = ('Byte',
+ 'Kibibyte',
+ 'Mebibyte',
+ 'Gibibyte',
+ 'Tebibyte',
+ 'Pebibyte',
+ 'Exibyte',
+ 'Zebibyte',
+ 'Yobiabyte'
+ )
+
name = names[0]
if num >= factor:
+ num = float(num)
for tmp_name in names[1: ]:
num /= factor
name = tmp_name
if num < factor:
break
else:
- return '%i %s' % (num, name)
+ return '%i%s' % (num, name)
-
-
- return '%01.2f %s' % (num, name)
+ return '%01.2f%s' % (num, name)
+
+
#***************************************************************
#
#***************************************************************
@@ -233,7 +245,6 @@
num = pat.sub('', num)
return num
-
#*****************************************************************
#
#****************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|