for use with some new src/www/htdocs/library.cgi changes. Shows file
sizes in human readable form (i.e. 488.288 MB)



Index: html_util.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/www/html_util.py,v
retrieving revision 1.4
diff -u -r1.4 html_util.py
--- html_util.py	26 Feb 2003 01:16:43 -0000	1.4
+++ html_util.py	26 Feb 2003 14:54:36 -0000
@@ -137,4 +137,21 @@
 </center>
 """)
 
+def descfsize(size):
+    """The purpose of this function is to accept a file size in bytes,           
+    and describe it in a human readable fashion. courtesy of 
+    Michael P. Soulier <msoulier at mcss.mcmaster.ca> and google
+    for finding his post"""
+    if size < 1000:
+        return "%d bytes" % size
+    elif size < 1000000:
+        size = size / 1000.0
+        return "%.3f kB" % size
+    elif size < 1000000000:
+        size = size / 1000000.0
+        return "%.3f MB" % size
+    else:
+        size = size / 1000000000.0
+        return "%.3f GB" % size
+
 

Reply via email to