[Checkins] SVN: hurry.filesize/trunk/ Extend documentation, add a few more systems, ready for release.
Martijn Faassen
faassen at infrae.com
Wed Mar 11 18:13:29 EDT 2009
Log message for revision 97922:
Extend documentation, add a few more systems, ready for release.
Changed:
_U hurry.filesize/trunk/
A hurry.filesize/trunk/CHANGES.txt
U hurry.filesize/trunk/setup.py
A hurry.filesize/trunk/src/hurry/filesize/README.txt
U hurry.filesize/trunk/src/hurry/filesize/__init__.py
U hurry.filesize/trunk/src/hurry/filesize/filesize.py
U hurry.filesize/trunk/src/hurry/filesize/tests.py
-=-
Property changes on: hurry.filesize/trunk
___________________________________________________________________
Added: svn:ignore
+ develop-eggs
parts
bin
.installed.cfg
Added: hurry.filesize/trunk/CHANGES.txt
===================================================================
--- hurry.filesize/trunk/CHANGES.txt (rev 0)
+++ hurry.filesize/trunk/CHANGES.txt 2009-03-11 22:13:29 UTC (rev 97922)
@@ -0,0 +1,7 @@
+Changes
+=======
+
+0.9
+---
+
+* Initial public release.
Modified: hurry.filesize/trunk/setup.py
===================================================================
--- hurry.filesize/trunk/setup.py 2009-03-11 21:47:19 UTC (rev 97921)
+++ hurry.filesize/trunk/setup.py 2009-03-11 22:13:29 UTC (rev 97922)
@@ -4,23 +4,20 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-#long_description = (
-# read('src/hurry/file/README.txt')
-# + '\n' +
-# read('src/hurry/file/browser/file.txt')
-# + '\n' +
-# read('CHANGES.txt')
-# )
+long_description = (
+ read('src', 'hurry', 'filesize', 'README.txt')
+ + '\n' +
+ read('CHANGES.txt')
+ + '\n' +
+ 'Download\n'
+ '========\n'
+ )
setup(
name="hurry.filesize",
- version="09ev",
- description="""\
-hurry.filesize is a simple Python library to make display human readable
-sizes of files (or anything that is sized in bytes), in kilobytes, megabytes,
-etc.
-""",
-# long_description=long_description,
+ version="0.9dev",
+ description="A simple Python library for human readable file sizes (or anything sized in bytes).",
+ long_description=long_description,
classifiers=[
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
Added: hurry.filesize/trunk/src/hurry/filesize/README.txt
===================================================================
--- hurry.filesize/trunk/src/hurry/filesize/README.txt (rev 0)
+++ hurry.filesize/trunk/src/hurry/filesize/README.txt 2009-03-11 22:13:29 UTC (rev 97922)
@@ -0,0 +1,47 @@
+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'
+
Modified: hurry.filesize/trunk/src/hurry/filesize/__init__.py
===================================================================
--- hurry.filesize/trunk/src/hurry/filesize/__init__.py 2009-03-11 21:47:19 UTC (rev 97921)
+++ hurry.filesize/trunk/src/hurry/filesize/__init__.py 2009-03-11 22:13:29 UTC (rev 97922)
@@ -1,3 +1,4 @@
from hurry.filesize.filesize import size
+from hurry.filesize.filesize import traditional, alternative, verbose, iec, si
Modified: hurry.filesize/trunk/src/hurry/filesize/filesize.py
===================================================================
--- hurry.filesize/trunk/src/hurry/filesize/filesize.py 2009-03-11 21:47:19 UTC (rev 97921)
+++ hurry.filesize/trunk/src/hurry/filesize/filesize.py 2009-03-11 22:13:29 UTC (rev 97922)
@@ -5,18 +5,47 @@
(1024 ** 3, 'G'),
(1024 ** 2, 'M'),
(1024 ** 1, 'K'),
- (1024 ** 0, 'B')
+ (1024 ** 0, 'B'),
]
+alternative = [
+ (1024 ** 5, ' PB'),
+ (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 ** 1, (' kilobyte', ' kilobytes')),
+ (1024 ** 0, (' byte', ' bytes')),
+ ]
+
+iec = [
+ (1024 ** 5, 'Pi'),
+ (1024 ** 4, 'Ti'),
+ (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 ** 1, 'K'),
- (1000 ** 0, 'B')
+ (1000 ** 0, 'B'),
]
+
+
def size(bytes, system=traditional):
"""Human-readable file size.
@@ -70,5 +99,12 @@
for factor, suffix in system:
if bytes >= factor:
break
- return str(int(bytes/factor)) + suffix
+ amount = int(bytes/factor)
+ if isinstance(suffix, tuple):
+ singular, multiple = suffix
+ if amount == 1:
+ suffix = singular
+ else:
+ suffix = multiple
+ return str(amount) + suffix
Modified: hurry.filesize/trunk/src/hurry/filesize/tests.py
===================================================================
--- hurry.filesize/trunk/src/hurry/filesize/tests.py 2009-03-11 21:47:19 UTC (rev 97921)
+++ hurry.filesize/trunk/src/hurry/filesize/tests.py 2009-03-11 22:13:29 UTC (rev 97922)
@@ -2,5 +2,6 @@
def test_suite():
return unittest.TestSuite((
- doctest.DocTestSuite('hurry.filesize.filesize'),
+ doctest.DocFileSuite('README.txt'),
+ doctest.DocTestSuite('hurry.filesize.filesize'),
))
More information about the Checkins
mailing list