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 getLinks(self, request): elements = [] for text, url, type in self.sidebarLinks: if type == const.DIVIDER: continue if type == const.HEADER: elements.append(tags.li(text, class_="nav-header")) continue cssClass = "" if self.isInSubSection(request, url): cssClass = "active" elements.append(tags.li(tags.a(text, href=url), class_=cssClass)) return elements
def getLinks(self, request): elements = [] for text, url, type in self.sidebarLinks: if type == const.DIVIDER: continue if type == const.HEADER: elements.append( tags.li(text, class_="nav-header")) continue cssClass = "" if self.isInSubSection(request, url): cssClass = "active" elements.append( tags.li(tags.a(text, href=url), class_=cssClass)) return elements
def stuff(self, request, tag): undoccedpublic = [o for o in self.system.orderedallobjects if o.isVisible and not hasdocstring(o)] undoccedpublic.sort(key=lambda o:o.fullName()) for o in undoccedpublic: tag(tags.li(o.kind, " - ", util.taglink(o))) return tag
def stuff(self, request, tag): undoccedpublic = [o for o in self.system.orderedallobjects if o.isVisible and not hasdocstring(o)] undoccedpublic.sort(key=lambda o:o.fullName()) for o in undoccedpublic: tag(tags.li(o.kind, " - ", taglink(o))) return tag
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 stuff(self, request, tag): undoccedpublic = [o for o in self.system.allobjects.values() if o.isVisible and not hasdocstring(o)] undoccedpublic.sort(key=lambda o:o.fullName()) for o in undoccedpublic: tag(tags.li(o.kind, " - ", tags.code(epydoc2stan.taglink(o, self.filename)))) return tag
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 _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 dictionaries(self, request, tag): """ """ elements = [] for dictionary in const.dictionaries: name = utils.getDictionaryName(dictionary) url = const.urls["dictionary"].replace( const.urlParams["dictionary"], dictionary) elements.append(tags.li(tags.a(name, href=url))) return tag(elements)
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 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 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 dictionaries(self, request, tag): """ """ elements = [] for dictionary in const.dictionaries: name = utils.getDictionaryName(dictionary) url = const.urls["dictionary"].replace( const.urlParams["dictionary"], dictionary) elements.append( tags.li(tags.a(name, href=url))) return tag(elements)
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 navLinks(self, request, tag): """ """ currentPath = request.path links = const.topNavLinks elements = [] for text, url in links: cssClass = "" if url == currentPath: cssClass = "active" elements.append(tags.li(tags.a(text, href=url), class_=cssClass), ) return tag(elements)
def stuff(self, request: object, tag: Tag) -> Tag: undoccedpublic = [o for o in self.system.allobjects.values() if o.isVisible and not hasdocstring(o)] undoccedpublic.sort(key=lambda o:o.fullName()) for o in undoccedpublic: kind = o.kind assert kind is not None # 'kind is None' makes the object invisible tag(tags.li( epydoc2stan.format_kind(kind), " - ", tags.code(epydoc2stan.taglink(o, self.filename)) )) return tag
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 raw_link(self, req, tag): node = self.original if IDirectoryNode.providedBy(node): node = node._node elif IFileNode.providedBy(node): pass else: return "" root = self.get_root(req) quoted_uri = urlquote(node.get_uri()) text_plain_url = "%s/file/%s/@@named=/raw.txt" % (root, quoted_uri) return T.li("Raw data as ", T.a("text/plain", href=text_plain_url))
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 getLinks(self, request): elements = [] for text, url, type in self.navLinks: cssClass = "" if self.isInSection(request, url): cssClass = "active" if type == const.DROPDOWN: cssClass += " dropdown" element = self.getDropdown(text, url, cssClass) else: element = tags.li(tags.a(text, href=url), class_=cssClass) elements.append(element) return elements
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 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 navLinks(self, request, tag): """ """ currentPath = request.path links = const.topNavLinks elements = [] for text, url in links: cssClass = "" if url == currentPath: cssClass = "active" elements.append( tags.li(tags.a(text, href=url), class_=cssClass), ) return tag(elements)
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 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 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 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 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 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 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 = 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 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 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 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))
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 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))