2 new commits in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/dc10eb44ed3d/ Changeset: dc10eb44ed3d Branch: reports_nice_disksize User: lance_parsons Date: 2013-04-26 18:40:59 Summary: Improved total disk usage display for message on Reports app Disk space maintenance page Affected #: 1 file
diff -r b16126d45099c38563e4372b4a7f781d30e44bde -r dc10eb44ed3d946c96e656098ee37cbe2c82ba07 lib/galaxy/webapps/reports/controllers/system.py --- a/lib/galaxy/webapps/reports/controllers/system.py +++ b/lib/galaxy/webapps/reports/controllers/system.py @@ -1,5 +1,6 @@ import operator, os from datetime import datetime, timedelta +from decimal import Decimal from galaxy.web.base.controller import * from galaxy import model from galaxy.model.orm import * @@ -89,7 +90,8 @@ except: pass history_count += 1 - message = "%d histories ( including a total of %d datasets ) were deleted more than %d days ago, but have not yet been purged. Disk space: " %( history_count, dataset_count, deleted_histories_days ) + str( disk_space ) + message = "%d histories ( including a total of %d datasets ) were deleted more than %d days ago, but have not yet been purged, " \ + "disk space: %s (%d bytes)." % ( history_count, dataset_count, deleted_histories_days, nice_size( disk_space ), disk_space ) else: message = "Enter the number of days." return str( deleted_histories_days ), message @@ -111,8 +113,8 @@ disk_space += dataset.file_size except: pass - message = str( dataset_count ) + " datasets were deleted more than " + str( deleted_datasets_days ) + \ - " days ago, but have not yet been purged, disk space: " + nice_size( disk_space ) + "." + message = "%d datasets were deleted more than %d days ago, but have not yet been purged," \ + " disk space: %s (%d bytes)." % ( dataset_count, deleted_datasets_days, nice_size( disk_space ), disk_space ) else: message = "Enter the number of days." return str( deleted_datasets_days ), message @@ -178,17 +180,14 @@ .order_by( desc( model.Dataset.table.c.file_size ) ) return file_path, disk_usage, datasets, file_size_str
-def nice_size( size ): +def nice_size(size): """Returns a readably formatted string with the size""" - words = [ 'bytes', 'Kb', 'Mb', 'Gb' ] try: - size = float( size ) + nsize = size + for x in ['bytes','KB','MB','GB']: + if nsize < 1024.0: + return "%3.1f%s" % (size, x) + nsize /= Decimal("1024.0") + return "%.1f%s" % (nsize, 'TB') except: - return '??? bytes' - for ind, word in enumerate( words ): - step = 1024 ** ( ind + 1 ) - if step > size: - size = size / float( 1024 ** ind ) - out = "%.1f %s" % ( size, word ) - return out - return '??? bytes' + return "%s bytes" % size
https://bitbucket.org/galaxy/galaxy-central/commits/fc2063ba6d99/ Changeset: fc2063ba6d99 Branch: reports_nice_disksize User: lance_parsons Date: 2013-04-26 21:38:34 Summary: Fixed nice display on reports, esp when size in bytes Affected #: 1 file
diff -r dc10eb44ed3d946c96e656098ee37cbe2c82ba07 -r fc2063ba6d992e1c088e6a06f99a6cae2bf86cd5 lib/galaxy/webapps/reports/controllers/system.py --- a/lib/galaxy/webapps/reports/controllers/system.py +++ b/lib/galaxy/webapps/reports/controllers/system.py @@ -91,7 +91,7 @@ pass history_count += 1 message = "%d histories ( including a total of %d datasets ) were deleted more than %d days ago, but have not yet been purged, " \ - "disk space: %s (%d bytes)." % ( history_count, dataset_count, deleted_histories_days, nice_size( disk_space ), disk_space ) + "disk space: %s." % ( history_count, dataset_count, deleted_histories_days, nice_size( disk_space, True ) ) else: message = "Enter the number of days." return str( deleted_histories_days ), message @@ -114,7 +114,7 @@ except: pass message = "%d datasets were deleted more than %d days ago, but have not yet been purged," \ - " disk space: %s (%d bytes)." % ( dataset_count, deleted_datasets_days, nice_size( disk_space ), disk_space ) + " disk space: %s." % ( dataset_count, deleted_datasets_days, nice_size( disk_space, True )) else: message = "Enter the number of days." return str( deleted_datasets_days ), message @@ -180,14 +180,23 @@ .order_by( desc( model.Dataset.table.c.file_size ) ) return file_path, disk_usage, datasets, file_size_str
-def nice_size(size): +def nice_size(size, include_bytes=False): """Returns a readably formatted string with the size""" + niced = False + nice_string = "%s bytes" % size try: - nsize = size + nsize = Decimal(size) for x in ['bytes','KB','MB','GB']: - if nsize < 1024.0: - return "%3.1f%s" % (size, x) + if nsize.compare(Decimal("1024.0")) == Decimal("-1"): + nice_string = "%3.1f %s" % (nsize, x) + niced = True + break nsize /= Decimal("1024.0") - return "%.1f%s" % (nsize, 'TB') + if not niced: + nice_string = "%3.1f %s" % (nsize, 'TB') + niced = True + if include_bytes and x != 'bytes': + nice_string = "%s (%s bytes)" % (nice_string, size) except: - return "%s bytes" % size + pass + return nice_string
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
galaxy-commits@lists.galaxyproject.org