from allmydata.web import storage
from allmydata.web.common import abbreviate_size, getxmlfile, WebError, \
get_arg, RenderMixin, get_format, get_mutable_type, TIME_FORMAT
+from allmydata.util.time_format import format_delta
class URIHandler(RenderMixin, rend.Page):
addSlash = True
docFactory = getxmlfile("welcome.xhtml")
- def __init__(self, client, clock=None):
+ def __init__(self, client, clock=None, now=None):
rend.Page.__init__(self, client)
self.client = client
# If set, clock is a twisted.internet.task.Clock that the tests
# use to test ophandle expiration.
self.child_operations = operations.OphandleTable(clock)
+ self.now = now
+ if self.now is None:
+ self.now = time.time
try:
s = client.getServiceNamed("storage")
except KeyError:
ctx.fillSlots("peerid", server.get_longname())
ctx.fillSlots("nickname", server.get_nickname())
rhost = server.get_remote_host()
- if rhost:
+ if server.is_connected():
if nodeid == self.client.nodeid:
rhost_s = "(loopback)"
elif isinstance(rhost, address.IPv4Address):
else:
rhost_s = str(rhost)
addr = rhost_s
- connected = "yes"
- since = server.get_last_connect_time()
+ service_connection_status = "Connected"
+ service_connection_status_abs_time, service_connection_status_rel_time = format_delta(server.get_last_connect_time(), self.now())
else:
addr = "N/A"
- connected = "no"
- since = server.get_last_loss_time()
- announced = server.get_announcement_time()
+ service_connection_status = "Disconnected"
+ service_connection_status_abs_time, service_connection_status_rel_time = format_delta(server.get_last_loss_time(), self.now())
+
+ last_received_data_abs_time, last_received_data_rel_time = format_delta(server.get_last_received_data_time(), self.now())
+
announcement = server.get_announcement()
version = announcement["my-version"]
- service_name = announcement["service-name"]
available_space = server.get_available_space()
if available_space is None:
available_space = "N/A"
else:
available_space = abbreviate_size(available_space)
ctx.fillSlots("address", addr)
- ctx.fillSlots("connected", connected)
- ctx.fillSlots("connected-bool", bool(rhost))
- ctx.fillSlots("since", time.strftime(TIME_FORMAT,
- time.localtime(since)))
- ctx.fillSlots("announced", time.strftime(TIME_FORMAT,
- time.localtime(announced)))
+ ctx.fillSlots("service_connection_status", service_connection_status)
+ ctx.fillSlots("service_connection_status_abs_time", service_connection_status_abs_time)
+ ctx.fillSlots("service_connection_status_rel_time", service_connection_status_rel_time)
+ ctx.fillSlots("last_received_data_abs_time", last_received_data_abs_time)
+ ctx.fillSlots("last_received_data_rel_time", last_received_data_rel_time)
ctx.fillSlots("version", version)
- ctx.fillSlots("service_name", service_name)
ctx.fillSlots("available_space", available_space)
return ctx.tag