mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 01:58:41 -05:00
add copyright info for filesize.py, update homepage link in control
This commit is contained in:
parent
454d5e6d9f
commit
8715233259
4 changed files with 117 additions and 20 deletions
|
|
@ -1 +1,50 @@
|
|||
http://pypi.python.org/pypi/hurry.filesize
|
||||
hurry.filesize
|
||||
==============
|
||||
|
||||
hurry.filesize a simple Python library that can take a number of bytes and
|
||||
returns a human-readable string with the size in it, in kilobytes (K),
|
||||
megabytes (M), etc.
|
||||
|
||||
The default system it uses is "traditional", where multipliers of 1024
|
||||
increase the unit size::
|
||||
|
||||
>>> from hurry.filesize import size
|
||||
>>> size(1024)
|
||||
'1K'
|
||||
|
||||
An alternative, slightly more verbose system::
|
||||
|
||||
>>> from hurry.filesize import alternative
|
||||
>>> size(1, system=alternative)
|
||||
'1 byte'
|
||||
>>> size(10, system=alternative)
|
||||
'10 bytes'
|
||||
>>> size(1024, system=alternative)
|
||||
'1 KB'
|
||||
|
||||
A verbose system::
|
||||
|
||||
>>> from hurry.filesize import verbose
|
||||
>>> size(10, system=verbose)
|
||||
'10 bytes'
|
||||
>>> size(1024, system=verbose)
|
||||
'1 kilobyte'
|
||||
>>> size(2000, system=verbose)
|
||||
'1 kilobyte'
|
||||
>>> size(3000, system=verbose)
|
||||
'2 kilobytes'
|
||||
>>> size(1024 * 1024, system=verbose)
|
||||
'1 megabyte'
|
||||
>>> size(1024 * 1024 * 3, system=verbose)
|
||||
'3 megabytes'
|
||||
|
||||
You can also use the SI system, where multipliers of 1000 increase the unit
|
||||
size::
|
||||
|
||||
>>> from hurry.filesize import si
|
||||
>>> size(1000, system=si)
|
||||
'1K'
|
||||
|
||||
|
||||
http://pypi.python.org/pypi/hurry.filesize
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +1,33 @@
|
|||
'''
|
||||
hurry.filesize
|
||||
|
||||
@author: Martijn Faassen, Startifact
|
||||
@license: ZPL 2.1
|
||||
'''
|
||||
|
||||
traditional = [
|
||||
(1024 ** 5, 'P'),
|
||||
(1024 ** 4, 'T'),
|
||||
(1024 ** 3, 'G'),
|
||||
(1024 ** 2, 'M'),
|
||||
(1024 ** 4, 'T'),
|
||||
(1024 ** 3, 'G'),
|
||||
(1024 ** 2, 'M'),
|
||||
(1024 ** 1, 'K'),
|
||||
(1024 ** 0, 'B'),
|
||||
]
|
||||
|
||||
alternative = [
|
||||
(1024 ** 5, ' PB'),
|
||||
(1024 ** 4, ' TB'),
|
||||
(1024 ** 3, ' GB'),
|
||||
(1024 ** 2, ' MB'),
|
||||
(1024 ** 4, ' TB'),
|
||||
(1024 ** 3, ' GB'),
|
||||
(1024 ** 2, ' MB'),
|
||||
(1024 ** 1, ' KB'),
|
||||
(1024 ** 0, (' byte', ' bytes')),
|
||||
]
|
||||
|
||||
verbose = [
|
||||
(1024 ** 5, (' petabyte', ' petabytes')),
|
||||
(1024 ** 4, (' terabyte', ' terabytes')),
|
||||
(1024 ** 3, (' gigabyte', ' gigabytes')),
|
||||
(1024 ** 2, (' megabyte', ' megabytes')),
|
||||
(1024 ** 4, (' terabyte', ' terabytes')),
|
||||
(1024 ** 3, (' gigabyte', ' gigabytes')),
|
||||
(1024 ** 2, (' megabyte', ' megabytes')),
|
||||
(1024 ** 1, (' kilobyte', ' kilobytes')),
|
||||
(1024 ** 0, (' byte', ' bytes')),
|
||||
]
|
||||
|
|
@ -29,17 +35,17 @@ verbose = [
|
|||
iec = [
|
||||
(1024 ** 5, 'Pi'),
|
||||
(1024 ** 4, 'Ti'),
|
||||
(1024 ** 3, 'Gi'),
|
||||
(1024 ** 2, 'Mi'),
|
||||
(1024 ** 3, 'Gi'),
|
||||
(1024 ** 2, 'Mi'),
|
||||
(1024 ** 1, 'Ki'),
|
||||
(1024 ** 0, ''),
|
||||
]
|
||||
|
||||
si = [
|
||||
(1000 ** 5, 'P'),
|
||||
(1000 ** 4, 'T'),
|
||||
(1000 ** 3, 'G'),
|
||||
(1000 ** 2, 'M'),
|
||||
(1000 ** 4, 'T'),
|
||||
(1000 ** 3, 'G'),
|
||||
(1000 ** 2, 'M'),
|
||||
(1000 ** 1, 'K'),
|
||||
(1000 ** 0, 'B'),
|
||||
]
|
||||
|
|
@ -50,7 +56,7 @@ def size(bytes, system=traditional):
|
|||
"""Human-readable file size.
|
||||
|
||||
Using the traditional system, where a factor of 1024 is used::
|
||||
|
||||
|
||||
>>> size(10)
|
||||
'10B'
|
||||
>>> size(100)
|
||||
|
|
@ -71,7 +77,7 @@ def size(bytes, system=traditional):
|
|||
'976K'
|
||||
>>> size(2000000)
|
||||
'1M'
|
||||
|
||||
|
||||
Using the SI system, with a factor 1000::
|
||||
|
||||
>>> size(10, system=si)
|
||||
|
|
@ -94,7 +100,7 @@ def size(bytes, system=traditional):
|
|||
'1M'
|
||||
>>> size(2000000, system=si)
|
||||
'2M'
|
||||
|
||||
|
||||
"""
|
||||
for factor, suffix in system:
|
||||
if bytes >= factor:
|
||||
|
|
@ -107,4 +113,3 @@ def size(bytes, system=traditional):
|
|||
else:
|
||||
suffix = multiple
|
||||
return str(amount) + suffix
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue