diff options
author | Carlo Landmeter <clandmeter@gmail.com> | 2015-03-20 09:52:33 +0000 |
---|---|---|
committer | Carlo Landmeter <clandmeter@gmail.com> | 2015-03-20 09:52:33 +0000 |
commit | ab052376dcd97c573bb5fff03c19c76f07305b09 (patch) | |
tree | 0bddcda6b82dc988e9980c6fc514597ec3a89e9a | |
parent | c9ebb179277f4af04087be7c71fdac91d3a7f42c (diff) | |
download | aports-turbo-ab052376dcd97c573bb5fff03c19c76f07305b09.tar.bz2 aports-turbo-ab052376dcd97c573bb5fff03c19c76f07305b09.tar.xz |
add human filesize
filesize idea is inspired by:
http://stackoverflow.com/a/23888858
-rwxr-xr-x | aports.lua | 10 | ||||
-rw-r--r-- | tpl/package.tpl | 4 |
2 files changed, 12 insertions, 2 deletions
@@ -9,6 +9,14 @@ function string.begins(str, prefix) return str:sub(1,#prefix)==prefix end +function human_bytes(bytes) + local mult = 10^(2) + local size = { 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' } + local factor = math.floor((string.len(bytes) -1) /3) + local result = bytes/math.pow(1024, factor) + return math.floor(result * mult + 0.5) / mult.." "..size[factor+1] +end + local tpl = turbo.web.Mustache.TemplateHelper("./tpl") local ContentsRenderer = class("ContentsRenderer", turbo.web.RequestHandler) @@ -71,6 +79,8 @@ local PackageRenderer = class("PackageRenderer", turbo.web.RequestHandler) function PackageRenderer:get(arch, name) local table = QueryPackage(name, arch) if table ~= nil then + table.install_size = human_bytes(table.install_size) + table.size = human_bytes(table.size) table.deps = QueryDeps(table.deps) table.deps_qty = (table.deps ~= nil) and #table.deps or "0" table.reqbys = QueryRequiredBy(table.provides) diff --git a/tpl/package.tpl b/tpl/package.tpl index cdccaee..9114555 100644 --- a/tpl/package.tpl +++ b/tpl/package.tpl @@ -41,11 +41,11 @@ </tr> <tr> <th>Size:</th> - <td>{{{size}}} Bytes</td> + <td>{{{size}}}</td> </tr>{{#install_size}} <tr> <th>Installed size:</th> - <td>{{{install_size}}} Bytes</td> + <td>{{{install_size}}}</td> </tr>{{/install_size}}{{#provides}} <tr> <th>Provides:</th> |