def links(self, request, tag): ds = self.root.edits(self.ob) therange = range(len(ds)) rev = therange[self.rev] ul = tags.ul() for i in therange: li = tags.li() if i: u = URLPath.fromRequest(request) u = u.sibling('diff') u.query = urllib.urlencode({ 'ob': self.ob.fullName(), 'revA': i-1, 'revB': i, }) li(tags.a(href=str(u))("(diff)")) else: li("(diff)") li(" - ") if i == len(ds) - 1: label = "Latest" else: label = str(i) if i == rev: li(label) else: u = URLPath.fromRequest(request) u.query = urllib.urlencode({ 'rev': str(i), 'ob': self.ob.fullName(), }) li(tags.a(href=str(u))(label)) li(' - ' + ds[i].user + '/' + ds[i].time) ul(li) return tag(ul)
def generateTabsAndContent(results): """ results is a dictionary whose keys are normalized ASCII chars and whose values are the original (possible unicode) chars that map to the ASCII ones. """ tabs = [] contents = [] for asciiLetter in sorted(results.keys()): if not asciiLetter: continue for letter in sorted(results[asciiLetter]): tab = tags.li( tags.a(letter.upper(), href="#l%s" % letter, **{"data-toggle": "tab"})) tabs.append(tab) content = tags.div(tags.p("holding content"), class_="tab-pane", id="l%s" % letter) contents.append(content) return tags.div(tags.ul(tabs, class_="nav nav-tabs"), tags.div(contents, class_="tab-content"), class_="tabbable tabs-left")
def names(self, request, tag): def link(obj: model.Documentable) -> Tag: # The "data-type" attribute helps doc2dash figure out what # category (class, method, etc.) an object belongs to. attributes = {} if obj.kind: attributes["data-type"] = epydoc2stan.format_kind(obj.kind) tag: Tag = tags.code( epydoc2stan.taglink(obj, NameIndexPage.filename), **attributes) return tag name2obs = {} for obj in self.initials[self.my_letter]: name2obs.setdefault(obj.name, []).append(obj) r = [] for name in sorted(name2obs, key=lambda x: (x.lower(), x)): item = tag.clone()(name) obs = name2obs[name] if all(isPrivate(ob) for ob in obs): item(class_='private') if len(obs) == 1: item(' - ', link(obs[0])) else: ul = tags.ul() for ob in sorted(obs, key=_lckey): subitem = tags.li(link(ob)) if isPrivate(ob): subitem(class_='private') ul(subitem) item(ul) r.append(item) return r
def generateTabsAndContent(results): """ results is a dictionary whose keys are normalized ASCII chars and whose values are the original (possible unicode) chars that map to the ASCII ones. """ tabs = [] contents = [] for asciiLetter in sorted(results.keys()): if not asciiLetter: continue for letter in sorted(results[asciiLetter]): tab = tags.li( tags.a( letter.upper(), href="#l%s" % letter, **{"data-toggle": "tab"}) ) tabs.append(tab) content = tags.div( tags.p("holding content"), class_="tab-pane", id="l%s" % letter) contents.append(content) return tags.div( tags.ul(tabs, class_="nav nav-tabs"), tags.div(contents, class_="tab-content"), class_="tabbable tabs-left")
def _showDirectory(self, request, dirinfo): children = dirinfo[1]['children'] body = tags.ul(*[ tags.li(tags.a(name + ('/' if info[0] == 'dirnode' else ''), href='/' + info[1]['ro_uri'])) for name, info in children.iteritems() ]) renderElement(request, body)
def plugin(self, request, tag): plugins = [] for name in self.plugins.keys(): plugins.append( tags.li( tags.a(name.title(), href='%s/%s' % (self.factory.name, name)))) return tag(tags.h2("Plugins"), tags.ul(*plugins))
def problems(self, req, tag): problems = self._retrieve_status.get_problems() if not problems: return "" ul = tags.ul() for peerid in sorted(problems.keys()): peerid_s = idlib.shortnodeid_b2a(peerid) ul(tags.li("[%s]: %s" % (peerid_s, problems[peerid]))) return tag("Server Problems:", ul)
def problems(self, req, tag): problems = self._update_status.problems if not problems: return tag l = tags.ul() for peerid in sorted(problems.keys()): peerid_s = idlib.shortnodeid_b2a(peerid) l(tags.li("[%s]: %s" % (peerid_s, problems[peerid]))) return tag("Server Problems:", l)
def _showDirectory(self, request, dirinfo): children = dirinfo[1]['children'] body = tags.ul(*[ tags.li( tags.a(name + ('/' if info[0] == 'dirnode' else ''), href='/' + info[1]['ro_uri'])) for name, info in children.iteritems() ]) renderElement(request, body)
def _describe_connection_status(self, cs): """Return a dict containing some connection stats.""" others = cs.non_connected_statuses if cs.connected: summary = cs.summary if others: hints = "\n".join([ "* %s: %s\n" % (which, others[which]) for which in sorted(others) ]) details = "Other hints:\n" + hints else: details = "(no other hints)" else: details = tags.ul() for which in sorted(others): details(tags.li("%s: %s" % (which, others[which]))) summary = [cs.summary, details] connected = "yes" if cs.connected else "no" connected_alt = self._connectedalts[connected] since = cs.last_connection_time if since is not None: service_connection_status_rel_time = render_time_delta( since, self._now_fn()) service_connection_status_abs_time = render_time_attr(since) else: service_connection_status_rel_time = "N/A" service_connection_status_abs_time = "N/A" last_received_data_time = cs.last_received_time if last_received_data_time is not None: last_received_data_abs_time = render_time_attr( last_received_data_time) last_received_data_rel_time = render_time_delta( last_received_data_time, self._now_fn()) else: last_received_data_abs_time = "N/A" last_received_data_rel_time = "N/A" return { "summary": summary, "details": details, "service_connection_status": connected, "service_connection_status_alt": connected_alt, "service_connection_status_abs_time": service_connection_status_abs_time, "service_connection_status_rel_time": service_connection_status_rel_time, "last_received_data_abs_time": last_received_data_abs_time, "last_received_data_rel_time": last_received_data_rel_time, }
def server_timings(self, req, tag): per_server = self._publish_status.timings.get("send_per_server") if not per_server: return tag() l = tags.ul() for server in sorted(per_server.keys(), key=lambda s: s.get_name()): times_s = ", ".join( [abbreviate_time(t) for t in per_server[server]]) l(tags.li("[%s]: %s" % (server.get_name(), times_s))) return tags.li("Per-Server Response Times: ", l)
def problems(self, req, tag): problems = self._publish_status.get_problems() if not problems: return tag() l = tags.ul() # XXX: is this exercised? I don't think PublishStatus.problems is # ever populated for peerid in sorted(problems.keys()): peerid_s = idlib.shortnodeid_b2a(peerid) l(tags.li("[%s]: %s" % (peerid_s, problems[peerid]))) return tag(tags.li("Server Problems:", l))
def render_GET(self, request): applications = [] for app in self.registry.applications.values(): link = tags.a(tags.tt(app.name), ' at ', tags.tt(app.path.path), href=app.name) applications.append(tags.li(link)) body = tags.body( tags.p('Here are your applications:'), tags.ul(*applications)) return renderElement(request, body)
def moduleSummary(modorpack): r = tags.li(util.taglink(modorpack), ' - ', epydoc2stan.doc2stan(modorpack, summary=True)[0]) if not isinstance(modorpack, model.Package): return r contents = [m for m in modorpack.orderedcontents if m.isVisible and m.name != '__init__'] if not contents: return r ul = tags.ul() for m in sorted(contents, key=lambda m:m.fullName()): ul(moduleSummary(m)) return r(ul)
def moduleSummary(modorpack): r = tags.li(taglink(modorpack), ' - ', epydoc2stan.doc2stan(modorpack, summary=True)[0]) if not isinstance(modorpack, model.Package): return r contents = [m for m in modorpack.orderedcontents if m.isVisible and m.name != '__init__'] if not contents: return r ul = tags.ul() for m in sorted(contents, key=lambda m:m.fullName()): ul(moduleSummary(m)) return r(ul)
def render_GET(self, request): applications = [] for app in self.registry.applications.values(): link = tags.a(tags.tt(app.name), ' at ', tags.tt(app.path.path), href=app.name) applications.append(tags.li(link)) body = tags.body(tags.p('Here are your applications:'), tags.ul(*applications)) return renderElement(request, body)
def service(self, request, tag): l = [] services = [] for name, service in self.services.iteritems(): factory = service.args[1] if isinstance(factory, BravoFactory): services.append(self.bravofactory(request, tags.div, factory)) else: l.append( tags.li("%s (%s)" % (name, self.services[name].__class__))) ul = tags.ul(*l) div = tags.div(*services) return tag(ul, div)
def test_render_list(self): """ The C{:list} renderer suffix will render the slot named by the renderer as a list, filling each slot. """ @page.routed(self.app.route("/"), tags.ul(tags.li(slot("item"), render="subplating:list"))) def rsrc(request): return {"subplating": [1, 2, 3]} request, written = self.get(b"/") self.assertIn(b'<ul><li>1</li><li>2</li><li>3</li></ul>', written) self.assertIn(b'<title>default title unchanged</title>', written)
def service(self, request, tag): l = [] services = [] for name, service in self.services.iteritems(): factory = service.args[1] if isinstance(factory, BravoFactory): services.append(self.bravofactory(request, tags.div, factory)) else: l.append(tags.li("%s (%s)" % (name, self.services[name].__class__))) ul = tags.ul(*l) div = tags.div(*services) return tag(ul, div)
def lease_last_cycle_results(self, req, tag): lc = self._storage.lease_checker h = lc.get_state()["history"] if not h: return "" biggest = str(max(int(k) for k in h.keys())) last = h[biggest] start, end = last["cycle-start-finish-times"] tag( "Last complete cycle (which took %s and finished %s ago)" " recovered: " % (abbreviate_time(end - start), abbreviate_time(time.time() - end)), self.format_recovered(last["space-recovered"], "actual")) p = T.ul() def add(*pieces): p(T.li(pieces)) saw = self.format_recovered(last["space-recovered"], "examined") add("and saw a total of ", saw) if not last["expiration-enabled"]: rec = self.format_recovered(last["space-recovered"], "configured") add( "but expiration was not enabled. If it had been, " "it would have recovered: ", rec) if last["corrupt-shares"]: add( "Corrupt shares:", T.ul((T.li([ "SI %s shnum %d" % (si, shnum) for si, shnum in last["corrupt-shares"] ])))) return tag(p)
def sharemap(self, req, tag): servermap = self._publish_status.get_servermap() if servermap is None: return tag("None") l = tags.ul() sharemap = servermap.make_sharemap() for shnum in sorted(sharemap.keys()): l( tags.li( "%d -> Placed on " % shnum, ", ".join([ "[%s]" % server.get_name() for server in sharemap[shnum] ]))) return tag("Sharemap:", l)
def names(self, request, tag): name2obs = {} for obj in self.initials[self.my_letter]: name2obs.setdefault(obj.name, []).append(obj) r = [] for name in sorted(name2obs, key=lambda x:(x.lower(), x)): obs = name2obs[name] if len(obs) == 1: r.append(tag.clone()(name, ' - ', taglink(obs[0]))) else: ul = tags.ul() for ob in sorted(obs, key=_lckey): ul(tags.li(taglink(ob))) r.append(tag.clone()(name, ul)) return r
def stuff(self, request, tag): t = tag anchors = set() for b, o in findRootClasses(self.system): if isinstance(o, model.Class): t(subclassesFrom(self.system, o, anchors)) else: item = tags.li(tags.code(b)) if o: ul = tags.ul() for sc in sorted(o, key=_lckey): ul(subclassesFrom(self.system, sc, anchors)) item(ul) t(item) return t
def subclassesFrom(hostsystem, cls, anchors): r = tags.li() name = cls.fullName() if name not in anchors: r(tags.a(name=name)) anchors.add(name) r(taglink(cls), ' - ', epydoc2stan.doc2stan(cls, summary=True)[0]) scs = [sc for sc in cls.subclasses if sc.system is hostsystem and ' ' not in sc.fullName() and sc.isVisible] if len(scs) > 0: ul = tags.ul() for sc in sorted(scs, key=_lckey): ul(subclassesFrom(hostsystem, sc, anchors)) r(ul) return r
def subclassesFrom(hostsystem, cls, anchors): r = tags.li() name = cls.fullName() if name not in anchors: r(tags.a(name=name)) anchors.add(name) r(util.taglink(cls), ' - ', epydoc2stan.doc2stan(cls, summary=True)[0]) scs = [sc for sc in cls.subclasses if sc.system is hostsystem and ' ' not in sc.fullName() and sc.isVisible] if len(scs) > 0: ul = tags.ul() for sc in sorted(scs, key=_lckey): ul(subclassesFrom(hostsystem, sc, anchors)) r(ul) return r
def names(self, request, tag): name2obs = {} for obj in self.initials[self.my_letter]: name2obs.setdefault(obj.name, []).append(obj) r = [] for name in sorted(name2obs, key=lambda x: (x.lower(), x)): obs = name2obs[name] if len(obs) == 1: r.append(tag.clone()(name, ' - ', util.taglink(obs[0]))) else: ul = tags.ul() for ob in sorted(obs, key=_lckey): ul(tags.li(util.taglink(ob))) r.append(tag.clone()(name, ul)) return r
def status(self, request, tag): world = self.factory.world l = [] total = 0 + len(world._cache._dirty) + len(world._pending_chunks) l.append(tags.li("Total chunks: %d" % total)) l.append(tags.li("Clean chunks: %d" % 0)) l.append(tags.li("Dirty chunks: %d" % len(world._cache._dirty))) l.append(tags.li("Chunks being generated: %d" % len(world._pending_chunks))) if world._cache._perm: l.append(tags.li("Permanent cache: enabled, %d chunks" % len(world._cache._perm))) else: l.append(tags.li("Permanent cache: disabled")) status = tags.ul(*l) return tag(tags.h2("Status"), status)
def world(self, request, tag, world): l = [] total = (len(world.chunk_cache) + len(world.dirty_chunk_cache) + len(world._pending_chunks)) l.append(tags.li("Total chunks: %d" % total)) l.append(tags.li("Clean chunks: %d" % len(world.chunk_cache))) l.append(tags.li("Dirty chunks: %d" % len(world.dirty_chunk_cache))) l.append(tags.li("Chunks being generated: %d" % len(world._pending_chunks))) if world.permanent_cache: l.append(tags.li("Permanent cache: enabled, %d chunks" % len(world.permanent_cache))) else: l.append(tags.li("Permanent cache: disabled")) status = tags.ul(*l) return tag(tags.h3("World status"), status)
def moduleSummary(modorpack, page_url): r = tags.li(tags.code(epydoc2stan.taglink(modorpack, page_url)), ' - ', epydoc2stan.format_summary(modorpack)) if modorpack.isPrivate: r(class_='private') if not isinstance(modorpack, model.Package): return r contents = [ m for m in modorpack.contents.values() if m.isVisible and m.name != '__init__' ] if not contents: return r ul = tags.ul() for m in sorted(contents, key=lambda m: m.fullName()): ul(moduleSummary(m, page_url)) return r(ul)
def status(self, request, tag): world = self.factory.world l = [] total = (len(world.chunk_cache) + len(world.dirty_chunk_cache) + len(world._pending_chunks)) l.append(tags.li("Total chunks: %d" % total)) l.append(tags.li("Clean chunks: %d" % len(world.chunk_cache))) l.append(tags.li("Dirty chunks: %d" % len(world.dirty_chunk_cache))) l.append(tags.li("Chunks being generated: %d" % len(world._pending_chunks))) if world.permanent_cache: l.append(tags.li("Permanent cache: enabled, %d chunks" % len(world.permanent_cache))) else: l.append(tags.li("Permanent cache: disabled")) status = tags.ul(*l) return tag(tags.h2("Status"), status)
def subclassesFrom(hostsystem, cls, anchors, page_url): r = tags.li() if isClassNodePrivate(cls): r(class_='private') name = cls.fullName() if name not in anchors: r(tags.a(name=name)) anchors.add(name) r(tags.code(epydoc2stan.taglink(cls, page_url)), ' - ', epydoc2stan.format_summary(cls)) scs = [sc for sc in cls.subclasses if sc.system is hostsystem and ' ' not in sc.fullName() and sc.isVisible] if len(scs) > 0: ul = tags.ul() for sc in sorted(scs, key=_lckey): ul(subclassesFrom(hostsystem, sc, anchors, page_url)) r(ul) return r
def getDropdown(self, title, url, cssClass): elements = [] if title == "About": links = urls.aboutDropDown for text, url, type in links: if type == const.DIVIDER: element = tags.li(class_="divider") elif type == const.HEADER: element = tags.li(text, class_="nav-header") else: element = tags.li(tags.a(text, href=url)) elements.append(element) return tags.li( tags.a( title, tags.b(class_="caret"), href="#", class_="dropdown-toggle", **{"data-toggle": "dropdown"}), tags.ul(elements, class_="dropdown-menu"), class_=cssClass)
def stuff(self, request: object, tag: Tag) -> Tag: t = tag anchors: MutableSet[str] = set() for b, o in findRootClasses(self.system): if isinstance(o, model.Class): t(subclassesFrom(self.system, o, anchors, self.filename)) else: item = tags.li(tags.code(b)) if all(isClassNodePrivate(sc) for sc in o): # This is an external class used only by private API; # mark the whole node private. item(class_='private') if o: ul = tags.ul() for sc in sorted(o, key=_lckey): ul(subclassesFrom(self.system, sc, anchors, self.filename)) item(ul) t(item) return t
def getDropdown(self, title, url, cssClass): elements = [] if title == "About": links = urls.aboutDropDown for text, url, type in links: if type == const.DIVIDER: element = tags.li(class_="divider") elif type == const.HEADER: element = tags.li(text, class_="nav-header") else: element = tags.li(tags.a(text, href=url)) elements.append(element) return tags.li(tags.a(title, tags.b(class_="caret"), href="#", class_="dropdown-toggle", **{"data-toggle": "dropdown"}), tags.ul(elements, class_="dropdown-menu"), class_=cssClass)
def moduleSummary(module: model.Module, page_url: str) -> Tag: r: Tag = tags.li( tags.code(epydoc2stan.taglink(module, page_url)), ' - ', epydoc2stan.format_summary(module) ) if module.isPrivate: r(class_='private') if not isinstance(module, model.Package): return r contents = [m for m in module.contents.values() if isinstance(m, model.Module) and m.isVisible] if not contents: return r ul = tags.ul() def fullName(obj: model.Documentable) -> str: return obj.fullName() for m in sorted(contents, key=fullName): ul(moduleSummary(m, page_url)) r(ul) return r
def main(self, request, tag): retval = [] for automaton in factory.automatons: title = tags.h2(automaton.name) stats = [] # Discover tracked information. if hasattr(automaton, "tracked"): t = automaton.tracked if isinstance(t, dict): l = sum(len(i) for i in t.values()) else: l = len(t) stats.append(tags.li("Currently tracking %d blocks" % l)) if hasattr(automaton, "step"): stats.append(tags.li("Currently processing every %f seconds" % automaton.step)) retval.append(tags.div(title, tags.ul(stats))) return tags.div(*retval)
def server_timings(self, req, tag): per_server = self._update_status.timings.get("per_server") if not per_server: return tag("") l = tags.ul() for server in sorted(per_server.keys(), key=lambda s: s.get_name()): times = [] for op, started, t in per_server[server]: #times.append("%s/%.4fs/%s/%s" % (op, # started, # self.render_time(None, started - self.update_status.get_started()), # self.render_time(None,t))) if op == "query": times.append(abbreviate_time(t)) elif op == "late": times.append("late(" + abbreviate_time(t) + ")") else: times.append("privkey(" + abbreviate_time(t) + ")") times_s = ", ".join(times) l(tags.li("[%s]: %s" % (server.get_name(), times_s))) return tags.li("Per-Server Response Times: ", l)
def names(self, request, tag): name2obs = {} for obj in self.initials[self.my_letter]: name2obs.setdefault(obj.name, []).append(obj) r = [] for name in sorted(name2obs, key=lambda x: (x.lower(), x)): item = tag.clone()(name) obs = name2obs[name] if all(isPrivate(ob) for ob in obs): item(class_='private') if len(obs) == 1: item(' - ', util.taglink(obs[0])) else: ul = tags.ul() for ob in sorted(obs, key=_lckey): subitem = tags.li(util.taglink(ob)) if isPrivate(ob): subitem(class_='private') ul(subitem) item(ul) r.append(item) return r
def preview(self, request, tag): docstring = parse_str(self.docstring) stan, errors = epydoc2stan.doc2stan( self.ob, docstring=docstring) if self.isPreview or errors: if errors: #print stan, errors #assert isinstance(stan, tags.pre) [text] = stan.children lines = text.replace('\r\n', '\n').split('\n') line2err = {} for err in errors: if isinstance(err, str): ln = None else: ln = err.linenum() line2err.setdefault(ln, []).append(err) w = len(str(len(lines))) for i, line in enumerate(lines): i += 1 cls = "preview" if i in line2err: cls += " error" tag(tags.pre(class_=cls)("%*s"%(w, i), ' ', line)) for err in line2err.get(i, []): tag(tags.p(class_="errormessage")(err.descr())) i += 1 for err in line2err.get(i, []): tag(tags.p(class_="errormessage")(err.descr())) items = [] for err in line2err.get(None, []): items.append(tags.li(str(err))) if items: tag(tags.ul(items)) else: tag = tag(stan) return tag(tags.h2("Edit")) else: return ()
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 bravofactory(self, request, tag, factory): g = (tags.li(username) for username in factory.protocols) users = tags.div(tags.h3("Users"), tags.ul(*g)) world = self.world(request, tags.div, factory.world) return tag(tags.h2("Bravo world %s" % factory.name), users, world)
def boards(self, request, tag): boards = self.store.query(Board) l = tags.ul(board.tags(tags.li) for board in boards) return tag(l)
app = Klein() myStyle = Plating( tags=tags.html( tags.head(tags.title(slot("pageTitle"))), tags.body(tags.h1(slot("pageTitle"), Class="titleHeading"), tags.div(slot(Plating.CONTENT))) ), defaults={"pageTitle": "Places & Foods"} ) @myStyle.routed( app.route("/"), tags.div( tags.h2("Sample Places:"), tags.ul([tags.li(tags.a(href=["/places/", place])(place)) for place in ["new york", "san francisco", "shanghai"]]), tags.h2("Sample Foods:"), tags.ul([tags.li(tags.a(href=["/foods/", food])(food)) for food in ["hamburgers", "cheeseburgers", "hot dogs"]]), )) def root(request): return {} @myStyle.routed(app.route("/foods/<food>"), tags.table(border="2", style="color: blue")( tags.tr(tags.td("Name:"), tags.td(slot("name"))), tags.tr(tags.td("Deliciousness:"), tags.td(slot("rating"), " stars")), tags.tr(tags.td("Carbs:"), tags.td(slot("carbohydrates"))))) def one_food(request, food):
def user(self, request, tag): users = (tags.li(username) for username in self.factory.protocols) return tag(tags.h2("Users"), tags.ul(*users))
def world(self, request, tag): worlds = [] for name in self.worlds.keys(): worlds.append(tags.li(tags.a(name.title(), href=name))) return tag(tags.h2("Worlds"), tags.ul(*worlds))
def service(self, request, tag): services = [] for name, factory in self.services.iteritems(): services.append(tags.li("%s (%s)" % (name, factory.__class__))) return tag(tags.h2("Services"), tags.ul(*services))
def plugin(self, request, tag): plugins = [] for name in self.plugins.keys(): plugins.append(tags.li(tags.a(name.title(), href='%s/%s' % (self.factory.name, name)))) return tag(tags.h2("Plugins"), tags.ul(*plugins))