From: Brian Warner Date: Fri, 7 Mar 2008 04:16:38 +0000 (-0700) Subject: webish: show storage sizelimit, abbreviate current usage X-Git-Tag: allmydata-tahoe-0.9.0~52 X-Git-Url: https://git.rkrishnan.org/Site/Content/Exhibitors/index.php?a=commitdiff_plain;h=8815b30b9bb958de1804a9368635e0aacb69bc5f;p=tahoe-lafs%2Ftahoe-lafs.git webish: show storage sizelimit, abbreviate current usage --- diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index 8f97dde5..000fda35 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -31,3 +31,40 @@ def get_arg(req, argname, default=None, multiple=False): if results: return results[0] return default + +def abbreviate_time(data): + # 1.23s, 790ms, 132us + if data is None: + return "" + s = float(data) + if s >= 1.0: + return "%.2fs" % s + if s >= 0.01: + return "%dms" % (1000*s) + if s >= 0.001: + return "%.1fms" % (1000*s) + return "%dus" % (1000000*s) + +def abbreviate_rate(data): + # 21.8kBps, 554.4kBps 4.37MBps + if data is None: + return "" + r = float(data) + if r > 1000000: + return "%1.2fMBps" % (r/1000000) + if r > 1000: + return "%.1fkBps" % (r/1000) + return "%dBps" % r + +def abbreviate_size(data): + # 21.8kB, 554.4kB 4.37MB + if data is None: + return "" + r = float(data) + if r > 1000000000: + return "%1.2fGB" % (r/1000000000) + if r > 1000000: + return "%1.2fMB" % (r/1000000) + if r > 1000: + return "%.1fkB" % (r/1000) + return "%dB" % r diff --git a/src/allmydata/web/status.py b/src/allmydata/web/status.py index 884fc3d2..339c1537 100644 --- a/src/allmydata/web/status.py +++ b/src/allmydata/web/status.py @@ -3,7 +3,8 @@ import time from twisted.internet import defer from nevow import rend, tags as T from allmydata.util import base32, idlib -from allmydata.web.common import IClient, getxmlfile +from allmydata.web.common import IClient, getxmlfile, abbreviate_time, \ + abbreviate_rate from allmydata.interfaces import IUploadStatus, IDownloadStatus, \ IPublishStatus, IRetrieveStatus @@ -19,28 +20,10 @@ def plural(sequence_or_length): class RateAndTimeMixin: def render_time(self, ctx, data): - # 1.23s, 790ms, 132us - if data is None: - return "" - s = float(data) - if s >= 1.0: - return "%.2fs" % s - if s >= 0.01: - return "%dms" % (1000*s) - if s >= 0.001: - return "%.1fms" % (1000*s) - return "%dus" % (1000000*s) + return abbreviate_time(data) def render_rate(self, ctx, data): - # 21.8kBps, 554.4kBps 4.37MBps - if data is None: - return "" - r = float(data) - if r > 1000000: - return "%1.2fMBps" % (r/1000000) - if r > 1000: - return "%.1fkBps" % (r/1000) - return "%dBps" % r + return abbreviate_rate(data) class UploadResultsRendererMixin(RateAndTimeMixin): # this requires a method named 'upload_results' diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index e8a9a6f0..f591cf65 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -23,7 +23,8 @@ from foolscap.eventual import fireEventually from nevow.util import resource_filename from allmydata.web import status, unlinked -from allmydata.web.common import IClient, getxmlfile, get_arg, boolean_of_arg +from allmydata.web.common import IClient, getxmlfile, get_arg, \ + boolean_of_arg, abbreviate_size class ILocalAccess(Interface): def local_access_is_allowed(): @@ -1403,8 +1404,11 @@ class Root(rend.Page): ss = client.getServiceNamed("storage") except KeyError: return "Not running" - allocated = ss.allocated_size() - return "about %d bytes allocated" % allocated + allocated = "about %s allocated" % abbreviate_size(ss.allocated_size()) + sizelimit = "no size limit" + if ss.sizelimit is not None: + sizelimit = "size limit is %s" % abbreviate_size(ss.sizelimit) + return "%s, %s" % (allocated, sizelimit) def data_introducer_furl(self, ctx, data): return IClient(ctx).introducer_furl