예제 #1
0
def format_field_list(singular: str, plural: str,
                      fields: Sequence[Field]) -> Iterator[Tag]:
    """
    Format list of L{Field} object. Used for notes, see also, authors, etc.

    Generates a 2-columns layout as follow::

        +------------------------------------+
        | <label>                            |
        | <desc ... >                        |
        +------------------------------------+

    @returns: Each row as iterator
    """
    if not fields:
        return

    label = singular if len(fields) == 1 else plural
    row = tags.tr(class_="fieldStart")
    row(tags.td(class_="fieldName", colspan="2")(label))
    yield row

    for field in fields:
        row = tags.tr()
        row(tags.td(colspan="2")(field.format()))
        yield row
예제 #2
0
def format_desc_list(singular, descs, plural=None):
    if plural is None:
        plural = singular + "s"
    if not descs:
        return ""
    if len(descs) > 1:
        label = plural
    else:
        label = singular
    r = []
    first = True
    for d in descs:
        if first:
            row = tags.tr(class_="fieldStart")
            row(tags.td(class_="fieldName")(label))
            first = False
        else:
            row = tags.tr()
            row(tags.td())
        if d.name is None:
            row(tags.td(colspan="2")(d.format()))
        else:
            row(tags.td(class_="fieldArg")(d.name), tags.td(d.format()))
        r.append(row)
    return r
예제 #3
0
def format_desc_list(singular, descs, plural=None):
    if plural is None:
        plural = singular + 's'
    if not descs:
        return ''
    if len(descs) > 1:
        label = plural
    else:
        label = singular
    r = []
    first = True
    for d in descs:
        if first:
            row = tags.tr(class_="fieldStart")
            row(tags.td(class_="fieldName")(label))
            first = False
        else:
            row = tags.tr()
            row(tags.td())
        if d.name is None:
            row(tags.td(colspan="2")(d.format()))
        else:
            row(tags.td(class_="fieldArg")(d.name), tags.td(d.format()))
        r.append(row)
    return r
 def render_feed(feed):
     feed_title = feed[u'feed'][u'title']
     feed_link = feed[u'feed'][u'link']
     return tags.table(
         tags.tr(tags.th(tags.a(feed_title, href=feed_link))))([
             tags.tr(
                 tags.td(tags.a(entry[u'title'], href=entry[u'link'])))
             for entry in feed[u'entries']
         ])
예제 #5
0
def format_desc_list(label: str, descs: Sequence[FieldDesc]) -> Iterator[Tag]:
    first = True
    for d in descs:
        if first:
            row = tags.tr(class_="fieldStart")
            row(tags.td(class_="fieldName")(label))
            first = False
        else:
            row = tags.tr()
            row(tags.td())
        yield row(d.format())
def format_revlist(revlist, name=None):
    table = tags.table(class_='inner')
    if name:
        table(tags.thead(tags.tr(tags.th(name, colspan="2"))))
    revs = tags.tbody()
    table(revs)
    for rev, revno in revlist:
        r = tags.tr()
        r(tags.td(str(revno)))
        r(tags.td(rev.message.splitlines()[0][:100], style="text-align: left"))
        revs(r)
    return table
def format_revlist(revlist, name=None):
    table = tags.table(class_='inner')
    if name:
        table(tags.thead(tags.tr(tags.th(name, colspan="2"))))
    revs = tags.tbody()
    table(revs)
    for rev, revno in revlist:
        r = tags.tr()
        r(tags.td(str(revno)))
        r(tags.td(rev.message.splitlines()[0][:100],
                  style="text-align: left"))
        revs(r)
    return table
예제 #8
0
def format_field_list(singular: str, plural: str,
                      fields: Sequence[Field]) -> Iterator[Tag]:
    label = singular if len(fields) == 1 else plural
    first = True
    for field in fields:
        if first:
            row = tags.tr(class_="fieldStart")
            row(tags.td(class_="fieldName")(label))
            first = False
        else:
            row = tags.tr()
            row(tags.td())
        row(tags.td(colspan="2")(field.format()))
        yield row
예제 #9
0
    def incidents_as_rows(incidents):
        attrs_incident = {"class": "incident"}
        attrs_number = {"class": "incident_number"}
        attrs_priority = {"class": "incident_priority"}
        attrs_rangers = {"class": "incident_rangers"}
        attrs_location = {"class": "incident_location"}
        attrs_types = {"class": "incident_types"}
        attrs_summary  = {"class": "incident_summary"}

        yield tags.thead(
            tags.tr(
                tags.th(u"#", **attrs_number),
                tags.th(u"Priority", **attrs_priority),
                tags.th(u"Rangers", **attrs_rangers),
                tags.th(u"Location", **attrs_location),
                tags.th(u"Types", **attrs_types),
                tags.th(u"Summary", **attrs_summary),
                **attrs_incident
            ),
            **attrs_activity
        )

        yield tags.tbody(
            tags.tr(
                tags.td(
                    u"{0}".format(incident.number), **attrs_number
                ),
                tags.td(
                    u"{0}".format(incident.priority), **attrs_priority
                ),
                tags.td(u"{0}".format(
                    u", ".join(ranger.handle for ranger in incident.rangers)
                ), **attrs_rangers),
                tags.td(u"{0}".format(
                    str(incident.location).decode("utf-8")
                ), **attrs_location),
                tags.td(u"{0}".format(
                    u", ".join(incident.incident_types)
                ), **attrs_types),
                tags.td(u"{0}".format(
                    incident.summaryFromReport()
                ), **attrs_summary),
                onclick=(
                    'window.open("/queue/incidents/{0}");'
                    .format(incident.number)
                ),
                **attrs_incident
            )
            for incident in sorted(incidents)
        )
예제 #10
0
    def format(self) -> Tag:
        r: List[Tag] = []

        r += format_desc_list('Parameters', self.parameter_descs)
        if self.return_desc:
            r.append(
                tags.tr(class_="fieldStart")(
                    tags.td(class_="fieldName")('Returns'),
                    tags.td(colspan="2")(self.return_desc.format())))
        r += format_desc_list("Raises", self.raise_descs)
        for s_p_l in (('Author', 'Authors',
                       self.authors), ('See Also', 'See Also', self.seealsos),
                      ('Present Since', 'Present Since',
                       self.sinces), ('Note', 'Notes', self.notes)):
            r += format_field_list(*s_p_l)
        unknowns: Dict[str, List[FieldDesc]] = {}
        for fieldinfo in self.unknowns:
            unknowns.setdefault(fieldinfo.kind, []).append(fieldinfo)
        for kind, fieldlist in unknowns.items():
            r += format_desc_list(f"Unknown Field: {kind}", fieldlist)

        if any(r):
            return tags.table(class_='fieldTable')(
                r)  # type: ignore[no-any-return]
        else:
            return tags.transparent  # type: ignore[no-any-return]
예제 #11
0
 def settings_header(self, request, tag):
     return tag(
         html.tr(
             html.th(u"Option"),
             html.th(u"Value"),
             html.th(u"Note"),
         ), )
예제 #12
0
    def format(self):
        r = []

        r.append(format_desc_list("Parameters", self.parameter_descs, "Parameters"))
        if self.return_desc:
            r.append(
                tags.tr(class_="fieldStart")(
                    tags.td(class_="fieldName")("Returns"),
                    tags.td(colspan="2")(self.return_desc.format()),
                )
            )
        r.append(format_desc_list("Raises", self.raise_descs, "Raises"))
        for s, p, l in (
            ("Author", "Authors", self.authors),
            ("See Also", "See Also", self.seealsos),
            ("Present Since", "Present Since", self.sinces),
            ("Note", "Notes", self.notes),
        ):
            r.append(format_field_list(self.obj, s, l, p))
        unknowns = {}
        unknownsinorder = []
        for fieldinfo in self.unknowns:
            tag = fieldinfo.kind
            if tag in unknowns:
                unknowns[tag].append(fieldinfo)
            else:
                unknowns[tag] = [fieldinfo]
                unknownsinorder.append(unknowns[tag])
        for fieldlist in unknownsinorder:
            label = "Unknown Field: " + fieldlist[0].kind
            r.append(format_desc_list(label, fieldlist, label))

        return tags.table(class_="fieldTable")(r)
예제 #13
0
    def format(self):
        r = []

        r.append(
            format_desc_list('Parameters', self.parameter_descs, 'Parameters'))
        if self.return_desc:
            r.append(
                tags.tr(class_="fieldStart")(
                    tags.td(class_="fieldName")('Returns'),
                    tags.td(colspan="2")(self.return_desc.format())))
        r.append(format_desc_list("Raises", self.raise_descs, "Raises"))
        for s, p, l in (('Author', 'Authors', self.authors),
                        ('See Also', 'See Also', self.seealsos),
                        ('Present Since', 'Present Since',
                         self.sinces), ('Note', 'Notes', self.notes)):
            r.append(format_field_list(self.obj, s, l, p))
        unknowns = {}
        for fieldinfo in self.unknowns:
            unknowns.setdefault(fieldinfo.kind, []).append(fieldinfo)
        for kind, fieldlist in unknowns.items():
            label = f"Unknown Field: {kind}"
            r.append(format_desc_list(label, fieldlist, label))

        if any(r):
            return tags.table(class_='fieldTable')(r)
        else:
            return tags.transparent
예제 #14
0
    def format(self):
        r = []

        r.append(format_desc_list('Parameters', self.parameter_descs, 'Parameters'))
        if self.return_desc:
            r.append(tags.tr(class_="fieldStart")(tags.td(class_="fieldName")('Returns'),
                               tags.td(colspan="2")(self.return_desc.format())))
        r.append(format_desc_list("Raises", self.raise_descs, "Raises"))
        for s, p, l in (('Author', 'Authors', self.authors),
                        ('See Also', 'See Also', self.seealsos),
                        ('Present Since', 'Present Since', self.sinces),
                        ('Note', 'Notes', self.notes)):
            r.append(format_field_list(self.obj, s, l, p))
        unknowns = {}
        unknownsinorder = []
        for fieldinfo in self.unknowns:
            tag = fieldinfo.kind
            if tag in unknowns:
                unknowns[tag].append(fieldinfo)
            else:
                unknowns[tag] = [fieldinfo]
                unknownsinorder.append(unknowns[tag])
        for fieldlist in unknownsinorder:
            label = "Unknown Field: " + fieldlist[0].kind
            r.append(format_desc_list(label, fieldlist, label))

        return tags.table(class_='fieldTable')(r)
예제 #15
0
 def settings_header(self, request, tag):
     return tag(
         html.tr(
             html.th(u"Option"),
             html.th(u"Value"),
             html.th(u"Note"),
         ),
     )
예제 #16
0
    def builder_row(self, bn, req, branches, num_builds):
        status = self.getStatus(req)
        builder = status.getBuilder(bn)
        state = builder.getState()[0]
        if state == 'building':
            state = 'idle'
        row = tags.tr()
        builderLink = path_to_builder(req, builder)
        row(tags.td(class_="box %s" % (state, ))(tags.a(href=builderLink)(bn)))

        builds = sorted([
            build for build in builder.getCurrentBuilds()
            if set(map_branches(branches)) & builder._getBuildBranches(build)
        ],
                        key=lambda build: build.getNumber(),
                        reverse=True)

        builds.extend(
            builder.generateFinishedBuilds(map_branches(branches),
                                           num_builds=num_builds))
        if builds:
            for b in builds:
                url = path_to_build(req, b)
                try:
                    label = b.getProperty("got_revision")
                except KeyError:
                    label = None
                # Label should never be "None", but sometimes
                # buildbot has disgusting bugs.
                if not label or label == "None" or len(str(label)) > 20:
                    label = "#%d" % b.getNumber()
                if b.isFinished():
                    text = b.getText()
                else:
                    when = b.getETA()
                    if when:
                        text = [
                            "%s" % (formatInterval(when), ),
                            "%s" % (time.strftime(
                                "%H:%M:%S",
                                time.localtime(time.time() + when)), )
                        ]
                    else:
                        text = []

                row(
                    tags.td(align="center",
                            bgcolor=_backgroundColors[b.getResults()],
                            class_=("LastBuild box ", build_get_class(b)))([
                                (element, tags.br)
                                for element in [tags.a(href=url)(label)] + text
                            ]))
        else:
            row(tags.td(class_="LastBuild box")("no build"))

        return row
예제 #17
0
    def body(self, req):
        status = self.getStatus(req)
        authz = self.getAuthz(req)

        builders = req.args.get(
            "builder", status.getBuilderNames(categories=self.categories))
        branches = [b for b in req.args.get("branch", []) if b]
        if not branches:
            branches = ["master"]
        if branches and "master" not in branches:
            defaultCount = "1"
        else:
            defaultCount = "10"
        num_builds = int(req.args.get("num_builds", [defaultCount])[0])

        tag = tags.div()

        tag(tags.script(src="hlbb.js"))
        tag(
            tags.h2(style="float:left; margin-top:0")("Latest builds: ",
                                                      ", ".join(branches)))

        form = tags.form(method="get",
                         action="",
                         style="float:right",
                         onsubmit="return checkBranch(branch.value)")
        form(
            tags.input(type="test",
                       name="branch",
                       placeholder=branches[0],
                       size="40"))
        form(tags.input(type="submit", value="View"))
        if (yield authz.actionAllowed('forceAllBuilds', req)):
            # XXX: Unsafe interpolation
            form(
                tags.button(type="button",
                            onclick="forceBranch(branch.value || %r, %r)" % (
                                branches[0],
                                self.categories,
                            ))("Force"))
        tag(form)

        table = tags.table(style="clear:both")
        tag(table)

        for bn in filter(lambda bn: bn not in self.failing_builders, builders):
            table(self.builder_row(bn, req, branches, num_builds))

        table(tags.tr()(tags.td(colspan="100")(
            tags.h3(style="float:left; margin-top:0")("Expected failures: "))))

        for bn in filter(lambda bn: bn in self.failing_builders, builders):
            table(self.builder_row(bn, req, branches, num_builds))

        defer.returnValue((yield flattenString(req, tag)))
예제 #18
0
    def builder_row(self, bn, req, branches, num_builds):
        status = self.getStatus(req)
        builder = status.getBuilder(bn)
        state = builder.getState()[0]
        if state == 'building':
            state = 'idle'
        row = tags.tr()
        builderLink = path_to_builder(req, builder)
        row(tags.td(class_="box %s" % (state,))
                   (tags.a(href=builderLink)(bn)))

        builds = sorted([
            build for build in builder.getCurrentBuilds()
            if set(map_branches(branches)) & builder._getBuildBranches(build)
            ], key=lambda build: build.getNumber(), reverse=True)

        builds.extend(builder.generateFinishedBuilds(
            map_branches(branches), num_builds=num_builds))
        if builds:
            for b in builds:
                url = path_to_build(req, b)
                try:
                    label = b.getProperty("got_revision")
                except KeyError:
                    label = None
                # Label should never be "None", but sometimes
                # buildbot has disgusting bugs.
                if not label or label == "None" or len(str(label)) > 20:
                    label = "#%d" % b.getNumber()
                if b.isFinished():
                    text = b.getText()
                else:
                    when = b.getETA()
                    if when:
                        text = [
                            "%s" % (formatInterval(when),),
                            "%s" % (time.strftime(
                                "%H:%M:%S",
                                time.localtime(time.time() + when)),)
                        ]
                    else:
                        text = []

                row(tags.td(
                    align="center",
                    bgcolor=_backgroundColors[b.getResults()],
                    class_=("LastBuild box ", build_get_class(b)))([
                        (element, tags.br)
                        for element
                        in [tags.a(href=url)(label)] + text]))
        else:
            row(tags.td(class_="LastBuild box")("no build"))

        return row
예제 #19
0
def format_field_list(obj, singular, fields, plural=None):
    if plural is None:
        plural = singular + 's'
    if not fields:
        return ''
    if len(fields) > 1:
        label = plural
    else:
        label = singular
    rows = []
    first = True
    for field in fields:
        if first:
            row = tags.tr(class_="fieldStart")
            row(tags.td(class_="fieldName")(label))
            first=False
        else:
            row = tags.tr()
            row(tags.td())
        row(tags.td(colspan="2")(field.body))
        rows.append(row)
    return rows
예제 #20
0
def format_field_list(obj, singular, fields, plural=None):
    if plural is None:
        plural = singular + "s"
    if not fields:
        return ""
    if len(fields) > 1:
        label = plural
    else:
        label = singular
    rows = []
    first = True
    for field in fields:
        if first:
            row = tags.tr(class_="fieldStart")
            row(tags.td(class_="fieldName")(label))
            first = False
        else:
            row = tags.tr()
            row(tags.td())
        row(tags.td(colspan="2")(field.body))
        rows.append(row)
    return rows
예제 #21
0
def format_desc_list(label: str, descs: Sequence[FieldDesc]) -> Iterator[Tag]:
    """
    Format list of L{FieldDesc}. Used for param, returns, raises, etc.

    Generates a 2-columns layout as follow::

        +------------------------------------+
        | <label>                            |
        | <name>: <type> |     <desc>        |
        | <name>: <type> |     <desc>        |
        +------------------------------------+

    If the fields don't have type or name information,
    generates the same output as L{format_field_list}::

        +------------------------------------+
        | <label>                            |
        | <desc ... >                        |
        +------------------------------------+

    @returns: Each row as iterator or None if no C{descs} id provided.
    """
    if not descs:
        return
    # <label>
    row = tags.tr(class_="fieldStart")
    row(tags.td(class_="fieldName", colspan="2")(label))
    # yield the first row.
    yield row
    # yield descriptions.
    for d in descs:
        row = tags.tr()
        # <name>: <type> |     <desc>
        # or
        # <desc ... >
        row(d.format())
        yield row
예제 #22
0
    def body(self, req):
        status = self.getStatus(req)
        authz = self.getAuthz(req)

        builders = req.args.get(
            "builder", status.getBuilderNames(categories=self.categories))
        branches = [b for b in req.args.get("branch", []) if b]
        if not branches:
            branches = ["master"]
        if branches and "master" not in branches:
            defaultCount = "1"
        else:
            defaultCount = "10"
        num_builds = int(req.args.get("num_builds", [defaultCount])[0])

        tag = tags.div()

        tag(tags.script(src="hlbb.js"))
        tag(tags.h2(style="float:left; margin-top:0")
                   ("Latest builds: ", ", ".join(branches)))

        form = tags.form(method="get", action="", style="float:right",
                         onsubmit="return checkBranch(branch.value)")
        form(tags.input(type="test", name="branch",
                        placeholder=branches[0], size="40"))
        form(tags.input(type="submit", value="View"))
        if (yield authz.actionAllowed('forceAllBuilds', req)):
            # XXX: Unsafe interpolation
            form(tags.button(
                type="button",
                onclick="forceBranch(branch.value || %r, %r)"
                        % (branches[0], self.categories,)
                )("Force"))
        tag(form)

        table = tags.table(style="clear:both")
        tag(table)

        for bn in filter(lambda bn: bn not in self.failing_builders, builders):
            table(self.builder_row(bn, req, branches, num_builds))

        table(tags.tr()(tags.td(colspan="100")(
            tags.h3(style="float:left; margin-top:0")
                   ("Expected failures: "))))

        for bn in filter(lambda bn: bn in self.failing_builders, builders):
            table(self.builder_row(bn, req, branches, num_builds))

        defer.returnValue((yield flattenString(req, tag)))
예제 #23
0
    def body(self, req):
        status = self.getStatus(req)
        authz = self.getAuthz(req)

        builders = req.args.get(
            "builder", status.getBuilderNames(categories=self.categories))
        branches = [b for b in req.args.get("branch", []) if b]
        if not branches:
            branches = ["trunk"]
        if branches and "trunk" not in branches:
            defaultCount = "1"
        else:
            defaultCount = "10"
        num_builds = int(req.args.get("num_builds", [defaultCount])[0])

        tag = tags.div()

        tag(tags.script(src="txbuildbot.js"))
        tag(
            tags.h2(style="float:left; margin-top:0")("Latest builds: ",
                                                      ", ".join(branches)))

        form = tags.form(method="get",
                         action="",
                         style="float:right",
                         onsubmit="return checkBranch(branch.value)")
        form(
            tags.input(type="test",
                       name="branch",
                       placeholder=branches[0],
                       size="40"))
        form(tags.input(type="submit", value="View"))
        if (yield authz.actionAllowed('forceAllBuilds', req)):
            # XXX: Unsafe interpolation
            form(
                tags.button(type="button",
                            onclick="forceBranch(branch.value || %r, %r)" % (
                                branches[0],
                                self.categories,
                            ))("Force"))
        tag(form)

        table = tags.table(style="clear:both")
        tag(table)

        for bn in builders:
            builder = status.getBuilder(bn)
            state = builder.getState()[0]
            if state == 'building':
                state = 'idle'
            row = tags.tr()
            table(row)
            builderLink = path_to_builder(req, builder)
            row(
                tags.td(class_="box %s" % (state, ))(
                    tags.a(href=builderLink)(bn)))

            builds = sorted([
                build for build in builder.getCurrentBuilds()
                if build.getSourceStamp().branch in map_branches(branches)
            ],
                            key=lambda build: build.getNumber(),
                            reverse=True)

            builds.extend(
                builder.generateFinishedBuilds(map_branches(branches),
                                               num_builds=num_builds))
            if builds:
                for b in builds:
                    url = path_to_build(req, b)
                    try:
                        label = b.getProperty("got_revision")
                    except KeyError:
                        label = None
                    # Label should never be "None", but sometimes
                    # buildbot has disgusting bugs.
                    if not label or label == "None" or len(str(label)) > 20:
                        label = "#%d" % b.getNumber()
                    if b.isFinished():
                        text = b.getText()
                    else:
                        when = b.getETA()
                        if when:
                            text = [
                                "%s" % (formatInterval(when), ),
                                "%s" % (time.strftime(
                                    "%H:%M:%S",
                                    time.localtime(time.time() + when)), )
                            ]
                        else:
                            text = []

                    row(
                        tags.td(
                            align="center",
                            bgcolor=_backgroundColors[b.getResults()],
                            class_=("LastBuild box ", build_get_class(b)))([
                                (element, tags.br)
                                for element in [tags.a(href=url)(label)] + text
                            ]))
            else:
                row(tags.td(class_="LastBuild box")("no build"))
        defer.returnValue((yield flattenString(req, tag)))
예제 #24
0
 def as_html(self):
     header = t.th(t.a(href=self._channel.link)(self._channel.title))
     return t.table(t.tr(header))(
         [t.tr(t.td(t.a(href=item.link)(item.title)))
          for item in self._channel.items]
     )
예제 #25
0
    def _render_results(self, req, cr):
        assert ICheckResults(cr)
        c = self._client
        sb = c.get_storage_broker()
        r = []

        def add(name, value):
            r.append(tags.li(name + ": ", value))

        add("Report", tags.pre("\n".join(self._html(cr.get_report()))))

        add(
            "Share Counts", "need %d-of-%d, have %d" %
            (cr.get_encoding_needed(), cr.get_encoding_expected(),
             cr.get_share_counter_good()))
        add("Happiness Level", str(cr.get_happiness()))
        add("Hosts with good shares", str(cr.get_host_counter_good_shares()))

        if cr.get_corrupt_shares():
            badsharemap = []
            for (s, si, shnum) in cr.get_corrupt_shares():
                d = tags.tr(
                    tags.td("sh#%d" % shnum),
                    tags.td(tags.div(s.get_nickname(), class_="nickname"),
                            tags.div(tags.tt(s.get_name()), class_="nodeid")),
                )
                badsharemap.append(d)
            add(
                "Corrupt shares",
                tags.table(
                    tags.tr(
                        tags.th("Share ID"),
                        tags.th((tags.div("Nickname"),
                                 tags.div("Node ID", class_="nodeid")),
                                class_="nickname-and-peerid")), badsharemap))
        else:
            add("Corrupt shares", "none")

        add("Wrong Shares", str(cr.get_share_counter_wrong()))

        sharemap_data = []
        shares_on_server = dictutil.DictOfSets()

        # FIXME: The two tables below contain nickname-and-nodeid
        # table column markup which is duplicated with each other,
        # introducer.xhtml, and deep-check-results.xhtml. All of these
        # (and any other presentations of nickname-and-nodeid) should be combined.

        for shareid in sorted(cr.get_sharemap().keys()):
            servers = sorted(cr.get_sharemap()[shareid],
                             key=lambda s: s.get_longname())
            for i, s in enumerate(servers):
                shares_on_server.add(s, shareid)
                shareid_s = ""
                if i == 0:
                    shareid_s = str(shareid)
                d = tags.tr(
                    tags.td(shareid_s),
                    tags.td(tags.div(s.get_nickname(), class_="nickname"),
                            tags.div(tags.tt(s.get_name()), class_="nodeid")))
                sharemap_data.append(d)

        add(
            "Good Shares (sorted in share order)",
            tags.table(
                tags.tr(
                    tags.th("Share ID"),
                    tags.th(tags.div("Nickname"),
                            tags.div("Node ID", class_="nodeid"),
                            class_="nickname-and-peerid")), sharemap_data))

        add("Recoverable Versions", str(cr.get_version_counter_recoverable()))
        add("Unrecoverable Versions",
            str(cr.get_version_counter_unrecoverable()))

        # this table is sorted by permuted order
        permuted_servers = [
            s for s in sb.get_servers_for_psi(cr.get_storage_index())
        ]

        num_shares_left = sum(
            [len(shareids) for shareids in shares_on_server.values()])
        servermap = []
        for s in permuted_servers:
            shareids = list(shares_on_server.get(s, []))
            shareids.reverse()
            shareids_s = [
                tags.tt(str(shareid), " ") for shareid in sorted(shareids)
            ]

            d = tags.tr(
                tags.td(tags.div(s.get_nickname(), class_="nickname"),
                        tags.div(tags.tt(s.get_name()), class_="nodeid")),
                tags.td(shareids_s),
            )
            servermap.append(d)
            num_shares_left -= len(shareids)
            if not num_shares_left:
                break

        add(
            "Share Balancing (servers in permuted order)",
            tags.table(
                tags.tr(
                    tags.th(tags.div("Nickname"),
                            tags.div("Node ID", class_="nodeid"),
                            class_="nickname-and-peerid"),
                    tags.th("Share IDs")), servermap))

        return tags.ul(r)
예제 #26
0
파일: web.py 프로젝트: rodrigc/braid
    def body(self, req):
        status = self.getStatus(req)
        authz = self.getAuthz(req)

        builders = req.args.get("builder", status.getBuilderNames(categories=self.categories))
        branches = [b for b in req.args.get("branch", []) if b]
        if not branches:
            branches = ["trunk"]
        if branches and "trunk" not in branches:
            defaultCount = "1"
        else:
            defaultCount = "10"
        num_builds = int(req.args.get("num_builds", [defaultCount])[0])

        tag = tags.div()

        tag(tags.script(src="txbuildbot.js"))
        tag(tags.h2(style="float:left; margin-top:0")("Latest builds: ", ", ".join(branches)))

        form = tags.form(method="get", action="", style="float:right",
                         onsubmit="return checkBranch(branch.value)")
        form(tags.input(type="test", name="branch", placeholder=branches[0], size="40"))
        form(tags.input(type="submit", value="View"))
        if (yield authz.actionAllowed('forceAllBuilds', req)):
            # XXX: Unsafe interpolation
            form(tags.button(type="button",
                onclick="forceBranch(branch.value || %r, %r)"
                        % (branches[0], self.categories,)
                )("Force"))
        tag(form)


        table = tags.table(style="clear:both")
        tag(table)

        for bn in builders:
            builder = status.getBuilder(bn)
            state = builder.getState()[0]
            if state == 'building':
                state = 'idle'
            row = tags.tr()
            table(row)
            builderLink = path_to_builder(req, builder)
            row(tags.td(class_="box %s" % (state,))(tags.a(href=builderLink)(bn)))

            builds = sorted([
                    build for build in builder.getCurrentBuilds()
                    if build.getSourceStamps()[0].branch in map_branches(branches)
                    ], key=lambda build: build.getNumber(), reverse=True)

            builds.extend(builder.generateFinishedBuilds(map_branches(branches),
                                                         num_builds=num_builds))
            if builds:
                for b in builds:
                    url = path_to_build(req, b)
                    try:
                        label = b.getProperty("got_revision")
                    except KeyError:
                        label = None
                    # Label should never be "None", but sometimes
                    # buildbot has disgusting bugs.
                    if not label or label == "None" or len(str(label)) > 20:
                        label = "#%d" % b.getNumber()
                    if b.isFinished():
                        text = b.getText()
                    else:
                        when = b.getETA()
                        if when:
                            text = [
                                "%s" % (formatInterval(when),),
                                "%s" % (time.strftime("%H:%M:%S", time.localtime(time.time() + when)),)
                                ]
                        else:
                            text = []

                    row(tags.td(
                            align="center",
                            bgcolor=_backgroundColors[b.getResults()],
                            class_=("LastBuild box ", build_get_class(b)))([
                                (element, tags.br)
                                for element
                                in [tags.a(href=url)(label)] + text]) )
            else:
                row(tags.td(class_="LastBuild box")("no build"))
        defer.returnValue((yield flattenString(req, tag)))
예제 #27
0
파일: html.py 프로젝트: glasnt/klein
@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):
    random = random_from_string(food)
    return {"name": food,
            "pageTitle": "Food: {}".format(food),
            "rating": random.randint(1, 5),
            "carbohydrates": random.randint(0, 100)}

@myStyle.routed(
    app.route("/places/<place>"),
    tags.div(style="color: green")(
        tags.h1("Place: ", slot("name")),
예제 #28
0
            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):
    random = random_from_string(food)
    return {
        "name": food,
        "pageTitle": "Food: {}".format(food),
        "rating": random.randint(1, 5),
        "carbohydrates": random.randint(0, 100)
    }


@myStyle.routed(
def make_html(components, instances):
    table = tags.table(class_='main')
    heading_row = tags.tr()
    for heading in 'component', 'tip revno', 'unreleased revisions', 'latest release':
        heading_row(tags.th(heading))
    for instance_name in sorted(instances):
        heading_row(tags.th(instance_name, class_="instance-name"))
    table(tags.thead(heading_row))
    tbody = tags.tbody()
    for name, component in sorted(components.items()):
        row = tags.tr(class_="component")
        revs_between_ids = {}
        extra_rows = []

        def td(*args, **kwargs):
            row(tags.td(*args, **kwargs))

        td(name)
        td(str(component.tip_revno), class_='version')
        unreleased_count = len(component.unreleased_revisions)
        if unreleased_count:
            id_ = get_id()
            td(tags.a(str(unreleased_count), href='#', class_='highlight'),
               class_='version clickable',
               id=id_)
            sub_name = 'revs between %s (r%s) and tip (r%s)' % (
                component.last_release, component.released_revno,
                component.tip_revno)
            extra_rows.append(
                tags.tr(tags.td(format_revlist(component.unreleased_revisions,
                                               name=sub_name),
                                colspan=str(4 + len(instances))),
                        class_='hidden',
                        id="show-" + id_))
        elif not component.last_release:
            td(u'\N{EM DASH}', class_='version')
        else:
            td(str(unreleased_count), class_='version')
        if component.last_release:
            td(component.last_release, class_='version')
        else:
            td(u'???', class_='version')
        for instance_name, instance in sorted(instances.items()):
            ver, location = instance.get(name, (None, None))
            if ver is None:
                td(u'\N{EM DASH}', class_='version')
            elif ver == component.last_release:
                td(ver, class_='version')
            elif ver in component.release2revno:
                revno_low = component.release2revno[ver]
                sub_name = 'revs between %s (r%s) and %s (r%s)' % (
                    ver, revno_low, component.last_release,
                    component.released_revno)
                revlist = []
                for rev, revno in component.mainline_revs:
                    if revno_low < revno < component.released_revno:
                        revlist.append((rev, revno))
                if revlist:
                    id_ = get_id()
                    revs_between_ids[revno_low] = id_
                    extra_rows.append(
                        tags.tr(tags.td(format_revlist(revlist, name=sub_name),
                                        colspan=str(4 + len(instances))),
                                class_='hidden branch-diff',
                                id="show-" + id_))
                    td(tags.a(ver, href='#', class_='highlight'),
                       class_='version clickable',
                       id=id_)
                else:
                    td(tags.span(ver, class_='highlight'), class_='version')
            elif location:
                try:
                    branch = bzrlib.branch.Branch.open(location)
                except bzrlib.errors.NoSuchBranch:
                    td(tags.span(ver, class_='highlight'), class_='version')
                else:
                    branch.lock_read()
                    try:
                        # This utterly half-assed version of bzr missing
                        # doesn't take merges into account!
                        revno, revid = branch.last_revision_info()
                        ver = ver.split('dev')[0] + 'dev' + str(revno)
                        mainline_revids = dict(
                            (rev.revision_id, revno)
                            for rev, revno in component.mainline_revs)
                        in_branch_revs = []
                        while revid not in mainline_revids:
                            rev = branch.repository.get_revision(revid)
                            if rev.message != 'post release bump':
                                in_branch_revs.append((rev, revno))
                            revno -= 1
                            if not rev.parent_ids:
                                break
                            revid = rev.parent_ids[0]
                        tables = []
                        if in_branch_revs:
                            tables.append(
                                format_revlist(
                                    in_branch_revs,
                                    'in branch (with nick %s) but not tip' %
                                    branch.nick))
                        in_trunk_revs = []
                        lca_revno = revno
                        for rev, revno in component.mainline_revs:
                            if revno > lca_revno:
                                in_trunk_revs.append((rev, revno))
                        if in_trunk_revs:
                            tables.append(
                                format_revlist(in_trunk_revs,
                                               'in tip but not branch'))
                        if tables:
                            id_ = get_id()
                            td(tags.a(ver, href='#', class_='highlight'),
                               class_='version clickable',
                               id=id_)
                            extra_rows.append(
                                tags.tr(tags.td(tables,
                                                colspan=str(4 +
                                                            len(instances))),
                                        class_='hidden branch-diff',
                                        id="show-" + id_))
                        else:
                            if branch.last_revision() == component.tip_revno:
                                td(ver, class_='highlight version')
                            else:
                                td(ver, class_='version')
                    finally:
                        branch.unlock()
            else:
                td(tags.span(ver, class_='highlight'), class_='version')
        tbody(row, *extra_rows)
    table(tbody)
    html = tags.html(
        tags.head(
            tags.title("Deployment report"),
            tags.script(
                src=
                'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
                type='text/javascript'),
            tags.script(
                src=
                'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js',
                type='text/javascript'),
            tags.script(CDATA(js), type='text/javascript'),
            tags.style(CDATA(css), type="text/css"),
        ),
        tags.body(
            tags.h1("Deployment report"),
            table,
        ),
    )
    html(xmlns="http://www.w3.org/1999/xhtml")
    return DOCTYPE + flatten(html)
예제 #30
0
    def incidents_as_rows(incidents):
        attrs_incident = {"class": "incident"}
        attrs_number = {"class": "incident_number"}
        attrs_priority = {"class": "incident_priority"}
        attrs_created = {"class": "incident_created"}
        attrs_state = {"class": "incident_state"}
        attrs_rangers = {"class": "incident_rangers"}
        attrs_location = {"class": "incident_location"}
        attrs_types = {"class": "incident_types"}
        attrs_summary  = {"class": "incident_summary"}

        yield tags.thead(
            tags.tr(
                tags.th(u"#", **attrs_number),
                tags.th(u"Priority", **attrs_priority),
                tags.th(u"Created", **attrs_created),
                tags.th(u"State", **attrs_state),
                tags.th(u"Rangers", **attrs_rangers),
                tags.th(u"Location", **attrs_location),
                tags.th(u"Types", **attrs_types),
                tags.th(u"Summary", **attrs_summary),
                **attrs_incident
            ),
            **attrs_activity
        )

        yield tags.tbody(
            tags.tr(
                tags.td(
                    u"{0}".format(incident.number),
                    **attrs_number
                ),
                tags.td(
                    u"{0}".format(priority_name(incident.priority)),
                    **attrs_priority
                ),
                tags.td(
                    u"{0}".format(formatTime(
                        incident.created, tz=tz, format=u"%d/%H:%M"
                    )),
                    **attrs_number
                ),
                tags.td(
                    u"{0}".format(IncidentState.describe(incident.state)),
                    **attrs_number
                ),
                tags.td(
                    u"{0}".format(
                        u", ".join(
                            ranger.handle for ranger in incident.rangers
                        )
                    ),
                    **attrs_rangers
                ),
                tags.td(
                    u"{0}".format(str(incident.location).decode("utf-8")),
                    **attrs_location
                ),
                tags.td(
                    u"{0}".format(u", ".join(incident.incident_types)),
                    **attrs_types
                ),
                tags.td(
                    u"{0}".format(incident.summaryFromReport()),
                    **attrs_summary
                ),
                onclick=(
                    u'window.open("/queue/incidents/{0}");'
                    .format(incident.number)
                ),
                **attrs_incident
            )
            for incident in sorted(incidents)
        )
def make_html(components, instances):
    table = tags.table(class_='main')
    heading_row = tags.tr()
    for heading in  'component', 'tip revno', 'unreleased revisions', 'latest release':
        heading_row(tags.th(heading))
    for instance_name in sorted(instances):
        heading_row(tags.th(instance_name, class_="instance-name"))
    table(tags.thead(heading_row))
    tbody = tags.tbody()
    for name, component in sorted(components.items()):
        row = tags.tr(class_="component")
        revs_between_ids = {}
        extra_rows = []
        def td(*args, **kwargs):
            row(tags.td(*args, **kwargs))
        td(name)
        td(str(component.tip_revno), class_='version')
        unreleased_count = len(component.unreleased_revisions)
        if unreleased_count:
            id_ = get_id()
            td(
                tags.a(str(unreleased_count), href='#', class_='highlight'),
                class_='version clickable', id=id_)
            sub_name = 'revs between %s (r%s) and tip (r%s)' % (
                component.last_release, component.released_revno,
                component.tip_revno)
            extra_rows.append(
                tags.tr(
                    tags.td(
                        format_revlist(component.unreleased_revisions, name=sub_name),
                        colspan=str(4 + len(instances))),
                    class_='hidden',
                    id="show-" + id_))
        elif not component.last_release:
            td(u'\N{EM DASH}', class_='version')
        else:
            td(str(unreleased_count), class_='version')
        if component.last_release:
            td(component.last_release, class_='version')
        else:
            td(u'???', class_='version')
        for instance_name, instance in sorted(instances.items()):
            ver, location = instance.get(name, (None, None))
            if ver is None:
                td(u'\N{EM DASH}', class_='version')
            elif ver == component.last_release:
                td(ver, class_='version')
            elif ver in component.release2revno:
                revno_low = component.release2revno[ver]
                sub_name = 'revs between %s (r%s) and %s (r%s)' % (
                    ver, revno_low,
                    component.last_release, component.released_revno)
                revlist = []
                for rev, revno in component.mainline_revs:
                    if revno_low < revno < component.released_revno:
                        revlist.append((rev, revno))
                if revlist:
                    id_ = get_id()
                    revs_between_ids[revno_low] = id_
                    extra_rows.append(
                        tags.tr(
                            tags.td(
                                format_revlist(revlist, name=sub_name),
                                colspan=str(4 + len(instances))),
                            class_='hidden branch-diff',
                            id="show-" + id_))
                    td(
                        tags.a(ver, href='#', class_='highlight'),
                        class_='version clickable', id=id_)
                else:
                    td(tags.span(ver, class_='highlight'), class_='version')
            elif location:
                try:
                    branch = bzrlib.branch.Branch.open(location)
                except bzrlib.errors.NoSuchBranch:
                    td(tags.span(ver, class_='highlight'), class_='version')
                else:
                    branch.lock_read()
                    try:
                        # This utterly half-assed version of bzr missing
                        # doesn't take merges into account!
                        revno, revid = branch.last_revision_info()
                        ver = ver.split('dev')[0] + 'dev' + str(revno)
                        mainline_revids = dict(
                            (rev.revision_id, revno)
                            for rev, revno in component.mainline_revs)
                        in_branch_revs = []
                        while revid not in mainline_revids:
                            rev = branch.repository.get_revision(revid)
                            if rev.message != 'post release bump':
                                in_branch_revs.append((rev, revno))
                            revno -= 1
                            if not rev.parent_ids:
                                break
                            revid = rev.parent_ids[0]
                        tables = []
                        if in_branch_revs:
                            tables.append(
                                format_revlist(
                                    in_branch_revs,
                                    'in branch (with nick %s) but not tip' % branch.nick))
                        in_trunk_revs = []
                        lca_revno = revno
                        for rev, revno in component.mainline_revs:
                            if revno > lca_revno:
                                in_trunk_revs.append((rev, revno))
                        if in_trunk_revs:
                            tables.append(
                                format_revlist(
                                    in_trunk_revs,
                                    'in tip but not branch'))
                        if tables:
                            id_ = get_id()
                            td(
                                tags.a(ver, href='#', class_='highlight'),
                                class_='version clickable', id=id_)
                            extra_rows.append(
                                tags.tr(
                                    tags.td(
                                        tables,
                                        colspan=str(4 + len(instances))),
                                    class_='hidden branch-diff',
                                    id="show-" + id_))
                        else:
                            if branch.last_revision() == component.tip_revno:
                                td(ver, class_='highlight version')
                            else:
                                td(ver, class_='version')
                    finally:
                        branch.unlock()
            else:
                td(tags.span(ver, class_='highlight'), class_='version')
        tbody(row, *extra_rows)
    table(tbody)
    html = tags.html(
        tags.head(
            tags.title("Deployment report"),
            tags.script(
                src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
                type='text/javascript'),
            tags.script(
                src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js',
                type='text/javascript'),
            tags.script(CDATA(js), type='text/javascript'),
            tags.style(CDATA(css), type="text/css"),
            ),
        tags.body(
            tags.h1("Deployment report"),
            table,
            ),
        )
    html(xmlns="http://www.w3.org/1999/xhtml")
    return DOCTYPE + flatten(html)