From 74209e643e2ba35ec84823a003ec4878825b7af9 Mon Sep 17 00:00:00 2001 From: meejah Date: Fri, 9 Dec 2016 13:17:15 -0700 Subject: [PATCH 1/3] Show the connection-status of all hints until we're connected to one --- src/allmydata/util/connection_status.py | 5 +-- src/allmydata/web/root.py | 41 +++++++++++++++++++++++-- src/allmydata/web/welcome.xhtml | 10 ++++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/allmydata/util/connection_status.py b/src/allmydata/util/connection_status.py index a4f425746..4b2fb0185 100644 --- a/src/allmydata/util/connection_status.py +++ b/src/allmydata/util/connection_status.py @@ -6,12 +6,13 @@ from ..interfaces import IConnectionStatus class ConnectionStatus: def __init__(self, connected, summary, last_connection_description, last_connection_time, - last_received_time): + last_received_time, statuses): self.connected = connected self.last_connection_summary = summary self.last_connection_description = last_connection_description self.last_connection_time = last_connection_time self.last_received_time = last_received_time + self.statuses = statuses def _describe_statuses(hints, handlers, statuses): descriptions = [] @@ -77,5 +78,5 @@ def from_foolscap_reconnector(rc, last_received): last_connected = None cs = ConnectionStatus(connected, summary, details, - last_connected, last_received) + last_connected, last_received, statuses) return cs diff --git a/src/allmydata/web/root.py b/src/allmydata/web/root.py index 468275a0e..1517461f8 100644 --- a/src/allmydata/web/root.py +++ b/src/allmydata/web/root.py @@ -1,11 +1,14 @@ import time, os +from datetime import datetime from twisted.web import http from nevow import rend, url, tags as T -from nevow.inevow import IRequest +from nevow.inevow import IRequest, IContainer from nevow.static import File as nevow_File # TODO: merge with static.File? from nevow.util import resource_filename +from zope.interface import implementer + import allmydata # to display import path from allmydata import get_package_versions_string from allmydata.util import log @@ -14,6 +17,7 @@ from allmydata.web import filenode, directory, unlinked, status, operations from allmydata.web import storage, magic_folder from allmydata.web.common import abbreviate_size, getxmlfile, WebError, \ get_arg, RenderMixin, get_format, get_mutable_type, render_time_delta, render_time, render_time_attr +from allmydata.util.abbreviate import abbreviate_time class URIHandler(RenderMixin, rend.Page): @@ -329,7 +333,40 @@ class Root(rend.Page): def data_services(self, ctx, data): sb = self.client.get_storage_broker() - return sorted(sb.get_known_servers(), key=lambda s: s.get_serverid()) + + @implementer(IContainer) + class Wrapper(object): + """ + This provides IContainer to Nevow so we can provide a 'child' data + at 'connections' and pass-through all the + connection-status attributes to the rest of the renderers + """ + def __init__(self, server): + self._server = server + + def child(self, context, name): + if name == 'connections': + st = self._server.get_connection_status() + if st.connected: + # we don't want the list of all possible hints + # when we're already connected; then we just + # show the one connection + return [] + return st.statuses.items() + return None # or are we supposed to raise something? + + def __getattr__(self, x): + return getattr(self._server, x) + + return [ + Wrapper(x) + for x in sorted(sb.get_known_servers(), key=lambda s: s.get_serverid()) + ] + + def render_connection_item(self, ctx, server): + ctx.tag.fillSlots('details', server[1]) + ctx.tag.fillSlots('summary', '{}: {}'.format(server[0], server[1])) + return ctx.tag def render_service_row(self, ctx, server): cs = server.get_connection_status() diff --git a/src/allmydata/web/welcome.xhtml b/src/allmydata/web/welcome.xhtml index bfb9a5547..1028cd3e4 100644 --- a/src/allmydata/web/welcome.xhtml +++ b/src/allmydata/web/welcome.xhtml @@ -72,7 +72,7 @@ -