diff --git a/www/kojiweb/archiveinfo.chtml b/www/kojiweb/archiveinfo.chtml index 648a93eb..13ce2c08 100644 --- a/www/kojiweb/archiveinfo.chtml +++ b/www/kojiweb/archiveinfo.chtml @@ -42,7 +42,7 @@ #end if - Size$archive.size + Size$util.formatNatural($archive.size) Checksum$archive.checksum @@ -97,7 +97,7 @@ #for $file in $files - $file.name$file.size + $file.name$util.formatNatural($file.size) #end for diff --git a/www/kojiweb/fileinfo.chtml b/www/kojiweb/fileinfo.chtml index 07dbe320..4631c783 100644 --- a/www/kojiweb/fileinfo.chtml +++ b/www/kojiweb/fileinfo.chtml @@ -19,7 +19,7 @@ #end if - Size$file.size + Size$util.formatNatural($file.size) #if 'mtime' in $file and $file.mtime diff --git a/www/kojiweb/imageinfo.chtml b/www/kojiweb/imageinfo.chtml index 69a9e504..d4904359 100644 --- a/www/kojiweb/imageinfo.chtml +++ b/www/kojiweb/imageinfo.chtml @@ -15,7 +15,7 @@ File Name$image.filename - File Size$image.filesize + File Size$util.formatNatural($image.filesize) Arch$image.arch diff --git a/www/kojiweb/rpminfo.chtml b/www/kojiweb/rpminfo.chtml index f2313f34..ea0210eb 100644 --- a/www/kojiweb/rpminfo.chtml +++ b/www/kojiweb/rpminfo.chtml @@ -59,7 +59,7 @@ #end if - Size$util.formatThousands($rpm.size) + Size$util.formatNatural($rpm.size) $rpm.payloadhash @@ -250,7 +250,7 @@ #for $file in $files - $util.escapeHTML($file.name)$util.formatThousands($file.size) + $util.escapeHTML($file.name)$util.formatNatural($file.size) #end for diff --git a/www/lib/kojiweb/util.py b/www/lib/kojiweb/util.py index a71797e7..b9f1f559 100644 --- a/www/lib/kojiweb/util.py +++ b/www/lib/kojiweb/util.py @@ -530,7 +530,16 @@ def formatMode(mode): def formatThousands(value): - return '{:,}'.format(value) + return '{:,} B'.format(value) + + +def formatNatural(value): + suffix = ['B', 'KB', 'MB', 'GB'] + suff_index = 0 + while value >= 1024 and suff_index < 3: + suff_index += 1 # increment the index of the suffix + value = value / 1024.0 # apply the division + return '{:.2f} {}'.format(value, suffix[suff_index]) def formatLink(url):