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
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
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'
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():
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