def test_abbreviate_size(self): self.failUnlessReallyEqual(common.abbreviate_size(None), "") self.failUnlessReallyEqual( common.abbreviate_size(1.23 * 1000 * 1000 * 1000), "1.23GB") self.failUnlessReallyEqual(common.abbreviate_size(1.23 * 1000 * 1000), "1.23MB") self.failUnlessReallyEqual(common.abbreviate_size(1230), "1.2kB") self.failUnlessReallyEqual(common.abbreviate_size(123), "123B")
def render_service_row(self, ctx, server): nodeid = server.get_serverid() ctx.fillSlots("peerid", server.get_longname()) ctx.fillSlots("nickname", server.get_nickname()) rhost = server.get_remote_host() if server.is_connected(): if nodeid == self.client.nodeid: rhost_s = "(loopback)" elif isinstance(rhost, address.IPv4Address): rhost_s = "%s:%d" % (rhost.host, rhost.port) else: rhost_s = str(rhost) addr = rhost_s service_connection_status = "yes" last_connect_time = server.get_last_connect_time() service_connection_status_rel_time = render_time_delta( last_connect_time, self.now_fn()) service_connection_status_abs_time = render_time_attr( last_connect_time) else: addr = "N/A" service_connection_status = "no" last_loss_time = server.get_last_loss_time() service_connection_status_rel_time = render_time_delta( last_loss_time, self.now_fn()) service_connection_status_abs_time = render_time_attr( last_loss_time) last_received_data_time = server.get_last_received_data_time() last_received_data_rel_time = render_time_delta( last_received_data_time, self.now_fn()) last_received_data_abs_time = render_time_attr(last_received_data_time) announcement = server.get_announcement() version = announcement["my-version"] 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("service_connection_status", service_connection_status) ctx.fillSlots("service_connection_status_alt", self._connectedalts[service_connection_status]) ctx.fillSlots("connected-bool", bool(rhost)) 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("available_space", available_space) return ctx.tag
def render_row(self, ctx, data): s = data TIME_FORMAT = "%H:%M:%S %d-%b-%Y" started_s = time.strftime(TIME_FORMAT, time.localtime(s.get_started())) ctx.fillSlots("started", started_s) si_s = base32.b2a_or_none(s.get_storage_index()) if si_s is None: si_s = "(None)" ctx.fillSlots("si", si_s) ctx.fillSlots("helper", {True: "Yes", False: "No"}[s.using_helper()]) size = s.get_size() if size is None: size = "(unknown)" elif isinstance(size, (int, long, float)): size = abbreviate_size(size) ctx.fillSlots("total_size", size) progress = data.get_progress() if IUploadStatus.providedBy(data): link = "up-%d" % data.get_counter() ctx.fillSlots("type", "upload") # TODO: make an ascii-art bar (chk, ciphertext, encandpush) = progress progress_s = ("hash: %.1f%%, ciphertext: %.1f%%, encode: %.1f%%" % ( (100.0 * chk), (100.0 * ciphertext), (100.0 * encandpush) )) ctx.fillSlots("progress", progress_s) elif IDownloadStatus.providedBy(data): link = "down-%d" % data.get_counter() ctx.fillSlots("type", "download") ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) elif IPublishStatus.providedBy(data): link = "publish-%d" % data.get_counter() ctx.fillSlots("type", "publish") ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) elif IRetrieveStatus.providedBy(data): ctx.fillSlots("type", "retrieve") link = "retrieve-%d" % data.get_counter() ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) else: assert IServermapUpdaterStatus.providedBy(data) ctx.fillSlots("type", "mapupdate %s" % data.get_mode()) link = "mapupdate-%d" % data.get_counter() ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) ctx.fillSlots("status", T.a(href=link)[s.get_status()]) return ctx.tag
def render_row(self, ctx, data): s = data started_s = render_time(s.get_started()) ctx.fillSlots("started", started_s) si_s = base32.b2a_or_none(s.get_storage_index()) if si_s is None: si_s = "(None)" ctx.fillSlots("si", si_s) ctx.fillSlots("helper", {True: "Yes", False: "No"}[s.using_helper()]) size = s.get_size() if size is None: size = "(unknown)" elif isinstance(size, (int, long, float)): size = abbreviate_size(size) ctx.fillSlots("total_size", size) progress = data.get_progress() if IUploadStatus.providedBy(data): link = "up-%d" % data.get_counter() ctx.fillSlots("type", "upload") # TODO: make an ascii-art bar (chk, ciphertext, encandpush) = progress progress_s = ("hash: %.1f%%, ciphertext: %.1f%%, encode: %.1f%%" % ( (100.0 * chk), (100.0 * ciphertext), (100.0 * encandpush) )) ctx.fillSlots("progress", progress_s) elif IDownloadStatus.providedBy(data): link = "down-%d" % data.get_counter() ctx.fillSlots("type", "download") ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) elif IPublishStatus.providedBy(data): link = "publish-%d" % data.get_counter() ctx.fillSlots("type", "publish") ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) elif IRetrieveStatus.providedBy(data): ctx.fillSlots("type", "retrieve") link = "retrieve-%d" % data.get_counter() ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) else: assert IServermapUpdaterStatus.providedBy(data) ctx.fillSlots("type", "mapupdate %s" % data.get_mode()) link = "mapupdate-%d" % data.get_counter() ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress)) ctx.fillSlots("status", T.a(href=link)[s.get_status()]) return ctx.tag
def render_service_row(self, ctx, server): server_id = server.get_serverid() ctx.fillSlots("peerid", server.get_longname()) ctx.fillSlots("nickname", server.get_nickname()) rhost = server.get_remote_host() if server.is_connected(): if server_id == self.client.get_long_nodeid(): rhost_s = "(loopback)" elif isinstance(rhost, address.IPv4Address): rhost_s = "%s:%d" % (rhost.host, rhost.port) else: rhost_s = str(rhost) addr = rhost_s service_connection_status = "yes" last_connect_time = server.get_last_connect_time() service_connection_status_rel_time = render_time_delta(last_connect_time, self.now_fn()) service_connection_status_abs_time = render_time_attr(last_connect_time) else: addr = "N/A" service_connection_status = "no" last_loss_time = server.get_last_loss_time() service_connection_status_rel_time = render_time_delta(last_loss_time, self.now_fn()) service_connection_status_abs_time = render_time_attr(last_loss_time) last_received_data_time = server.get_last_received_data_time() last_received_data_rel_time = render_time_delta(last_received_data_time, self.now_fn()) last_received_data_abs_time = render_time_attr(last_received_data_time) announcement = server.get_announcement() version = announcement.get("my-version", "") 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("service_connection_status", service_connection_status) ctx.fillSlots("service_connection_status_alt", self._connectedalts[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("available_space", available_space) return ctx.tag
def _describe_server(server): """Return a dict containing server stats.""" peerid = server.get_longname() nickname = server.get_nickname() version = server.get_announcement().get("my-version", "") space = server.get_available_space() if space is not None: available_space = abbreviate_size(space) else: available_space = "N/A" return { "peerid": peerid, "nickname": nickname, "version": version, "available_space": available_space, }
def render_service_row(self, ctx, server): cs = server.get_connection_status() self._render_connection_status(ctx, cs) ctx.fillSlots("peerid", server.get_longname()) ctx.fillSlots("nickname", server.get_nickname()) announcement = server.get_announcement() version = announcement.get("my-version", "") available_space = server.get_available_space() if available_space is None: available_space = "N/A" else: available_space = abbreviate_size(available_space) ctx.fillSlots("version", version) ctx.fillSlots("available_space", available_space) return ctx.tag
def render_service_row(self, ctx, server): cs = server.get_connection_status() self._render_connection_status(ctx, cs) ctx.fillSlots("peerid", server.get_longname()) ctx.fillSlots("nickname", server.get_nickname()) announcement = server.get_announcement() version = announcement.get("my-version", "") available_space = server.get_available_space() if available_space is None: available_space = "N/A" else: available_space = abbreviate_size(available_space) ctx.fillSlots("version", version) ctx.fillSlots("available_space", available_space) return ctx.tag
def render_service_row(self, ctx, server): nodeid = server.get_serverid() ctx.fillSlots("peerid", server.get_longname()) ctx.fillSlots("nickname", server.get_nickname()) rhost = server.get_remote_host() if rhost: if nodeid == self.client.nodeid: rhost_s = "(loopback)" elif isinstance(rhost, address.IPv4Address): rhost_s = "%s:%d" % (rhost.host, rhost.port) else: rhost_s = str(rhost) addr = rhost_s connected = "yes" since = server.get_last_connect_time() else: addr = "N/A" connected = "no" since = server.get_last_loss_time() announced = server.get_announcement_time() 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_alt", self._connectedalts[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("version", version) ctx.fillSlots("service_name", service_name) ctx.fillSlots("available_space", available_space) return ctx.tag
def render_services(self, ctx, data): ul = T.ul() try: ss = self.client.getServiceNamed("storage") stats = ss.get_stats() if stats["storage_server.accepting_immutable_shares"]: msg = "accepting new shares" else: msg = "not accepting new shares (read-only)" available = stats.get("storage_server.disk_avail") if available is not None: msg += ", %s available" % abbreviate_size(available) ul[T.li[T.a(href="storage")["Storage Server"], ": ", msg]] except KeyError: ul[T.li["Not running storage server"]] if self.client.helper: stats = self.client.helper.get_stats() active_uploads = stats["chk_upload_helper.active_uploads"] ul[T.li["Helper: %d active uploads" % (active_uploads, )]] else: ul[T.li["Not running helper"]] return ctx.tag[ul]
def render_services(self, ctx, data): ul = T.ul() try: ss = self.client.getServiceNamed("storage") stats = ss.get_stats() if stats["storage_server.accepting_immutable_shares"]: msg = "accepting new shares" else: msg = "not accepting new shares (read-only)" available = stats.get("storage_server.disk_avail") if available is not None: msg += ", %s available" % abbreviate_size(available) ul[T.li[T.a(href="storage")["Storage Server"], ": ", msg]] except KeyError: ul[T.li["Not running storage server"]] if self.client.helper: stats = self.client.helper.get_stats() active_uploads = stats["chk_upload_helper.active_uploads"] ul[T.li["Helper: %d active uploads" % (active_uploads,)]] else: ul[T.li["Not running helper"]] return ctx.tag[ul]
def services(self, req, tag): ul = tags.ul() try: ss = self._client.getServiceNamed("storage") stats = ss.get_stats() if stats["storage_server.accepting_immutable_shares"]: msg = "accepting new shares" else: msg = "not accepting new shares (read-only)" available = stats.get("storage_server.disk_avail") if available is not None: msg += ", %s available" % abbreviate_size(available) ul(tags.li(tags.a("Storage Server", href="storage"), ": ", msg)) except KeyError: ul(tags.li("Not running storage server")) if self._client.helper: stats = self._client.helper.get_stats() active_uploads = stats["chk_upload_helper.active_uploads"] ul(tags.li("Helper: %d active uploads" % (active_uploads,))) else: ul(tags.li("Not running helper")) return tag(ul)
def render_retrieves(self, ctx, data): files = data["counters"].get("mutable.files_retrieved", 0) bytes = data["counters"].get("mutable.bytes_retrieved", 0) return "%s files / %s bytes (%s)" % (files, bytes, abbreviate_size(bytes))
def render_downloads(self, ctx, data): files = data["counters"].get("downloader.files_downloaded", 0) bytes = data["counters"].get("downloader.bytes_downloaded", 0) return ("%s files / %s bytes (%s)" % (files, bytes, abbreviate_size(bytes)))
def test_abbreviate_size(self): self.failUnlessReallyEqual(common.abbreviate_size(None), "") self.failUnlessReallyEqual(common.abbreviate_size(1.23*1000*1000*1000), "1.23GB") self.failUnlessReallyEqual(common.abbreviate_size(1.23*1000*1000), "1.23MB") self.failUnlessReallyEqual(common.abbreviate_size(1230), "1.2kB") self.failUnlessReallyEqual(common.abbreviate_size(123), "123B")
def render_downloads(self, ctx, data): files = data["counters"].get("downloader.files_downloaded", 0) bytes = data["counters"].get("downloader.bytes_downloaded", 0) return ("%s files / %s bytes (%s)" % (files, bytes, abbreviate_size(bytes)))
def retrieves(self, req, tag): files = self._stats["counters"].get("mutable.files_retrieved", 0) bytes = self._stats["counters"].get("mutable.bytes_retrieved", 0) return tag("%s files / %s bytes (%s)" % (files, bytes, abbreviate_size(bytes)))
def render_retrieves(self, ctx, data): files = data["counters"].get("mutable.files_retrieved", 0) bytes = data["counters"].get("mutable.bytes_retrieved", 0) return "%s files / %s bytes (%s)" % (files, bytes, abbreviate_size(bytes))
def downloads(self, req, tag): files = self._stats["counters"].get("downloader.files_downloaded", 0) bytes = self._stats["counters"].get("downloader.bytes_downloaded", 0) return tag("%s files / %s bytes (%s)" % (files, bytes, abbreviate_size(bytes)))