Esempio n. 1
0
    def write_t_rec(self,
                    t,
                    autoAnchor=None,
                    align='left',
                    parent=None,
                    level=0):
        """ Recursively writes a <t> element

            If no parent is specified, a dummy div will be treated as the parent
            and any text will go in a <p> element.  Otherwise text and
            child elements will be insert directly into the parent -- meaning
            we are in a list
        """
        if parent is None:
            parent = self.temp_div  # Dummy div
            current = E.P()
            parent.append(current)
        else:
            current = parent
        if t.text:
            if "anchor" in t.attrib:
                a = E.A(name=t.attrib["anchor"])
                a.tail = t.text
                current.append(a)
            else:
                current.text = t.text
            if autoAnchor:
                current.attrib['id'] = autoAnchor
        for child in t:
            if child.tag in ['xref', 'eref', 'iref', 'cref', 'spanx']:
                for element in self._expand_ref(child):
                    current.append(element)
            elif child.tag == 'u':
                for element in self._expand_u(child):
                    current.append(element)
            elif child.tag == 'vspace':
                br = E.BR()
                current.append(br)
                blankLines = int(
                    child.attrib.get('blankLines',
                                     self.defaults['vspace_blanklines']))
                for i in range(blankLines):
                    br = E.BR()
                    current.append(br)
                if child.tail:
                    br.tail = child.tail
            elif child.tag == 'list':
                self.write_list(child, parent, level=level)
                if child.tail:
                    parent.append(E.P(child.tail))
            elif child.tag == 'figure':
                # Callback to base writer method
                self.write_figure(child)
            elif child.tag == 'texttable':
                # Callback to base writer method
                self.write_table(child)
        # If we are back at top level, serialize the whole temporary structure
        # Add to body buffer
        if parent == self.temp_div:
            self.buf.append(self._flush_temp_div())
Esempio n. 2
0
    def render_html(results: Dict[str, Any]) -> str:
        heading = E.H2(
            E.A("Locust", href="https://github.com/simiotics/locust"),
            " summary")
        body_elements = [heading]

        refs = results.get("refs")
        if refs is not None:
            body_elements.extend([E.H3("Git references")])
            body_elements.extend(
                [E.B("Initial: "),
                 E.SPAN(refs["initial"]),
                 E.BR()])
            if refs["terminal"] is not None:
                body_elements.extend(
                    [E.B("Terminal: "),
                     E.SPAN(refs["terminal"]),
                     E.BR()])

        body_elements.append(E.HR())

        changes_by_file = results["locust"]
        for item in changes_by_file:
            item_element = file_section_handler(item)
            body_elements.append(item_element)

        html = E.HTML(E.BODY(*body_elements))
        results_string = lxml.html.tostring(html).decode()
        return results_string
Esempio n. 3
0
def change_representation_full(change: Dict[str, Any], link: str,
                               filepath: str, current_depth: int,
                               max_depth: int) -> Optional[Any]:
    """
    Generator of uncompressed html markdown.
    """
    change_elements: List[Any] = [
        E.B("Name: "),
        E.A(change["name"], href=link),
        E.BR(),
        E.B("Type: "),
        E.SPAN(change["type"]),
        E.BR(),
        E.B("Changed lines: "),
        E.SPAN(str(change["changed_lines"])),
    ]

    if change["total_lines"]:
        change_elements.extend(
            [E.BR(),
             E.B("Total lines: "),
             E.SPAN(str(change["total_lines"]))])

    if change["children"]:
        change_elements.extend([E.BR(), E.B("Changes:")])
    child_elements = []
    for child in change["children"]:
        child_element = render_change_as_html(child, filepath,
                                              current_depth + 1, max_depth)
        if child_element is not None:
            child_elements.append(child_element)
    change_elements.append(E.UL(*child_elements))

    return change_elements
Esempio n. 4
0
def template(name, contents):

    cpu_class = 'active' if name == 'cpu' else ''
    wc_class = 'active' if name == 'wc' else ''
    help_class = 'active' if name == 'help' else ''

    return E.HTML(
        E.HEAD(
            E.LINK(rel='stylesheet',
                   type='text/css',
                   href='bootstrap/css/bootstrap.css'),
            E.LINK(rel='stylesheet', type='text/css', href='profile.css'),
            E.SCRIPT(src='bootstrap/js/bootstrap.min.js'),
            E.TITLE('RUM Job Profile')),
        E.BODY(
            E.DIV(E.DIV(E.DIV(E.A(E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  CLASS='btn btn-navbar'),
                              E.A('RUM Profile', CLASS='brand', href='#'),
                              E.DIV(E.UL(E.LI(E.A('CPU time', href='cpu.html'),
                                              CLASS=cpu_class),
                                         E.LI(E.A('Wallclock time',
                                                  href='wc.html'),
                                              CLASS=wc_class),
                                         E.LI(E.A('Help', href='help.html'),
                                              CLASS=help_class),
                                         CLASS='nav'),
                                    CLASS='nav-collapse collapse'),
                              CLASS='container'),
                        CLASS='navbar-inner'),
                  CLASS='navbar navbar-inverse navbar-fixed-top'), E.BR(),
            E.BR(), E.BR(), E.DIV(contents, CLASS='container')))
Esempio n. 5
0
def dim_lcov_report_extend_legend(doc):
    try:
        legend = doc.xpath("//td[@class='headerValueLeg']")[0]
        legend.text = ""

        modified_by_patch = E.SPAN(E.SPAN("Modified by patch:"), E.BR(),
                                   E.SPAN("Lines: "))
        not_modified_by_patch = E.SPAN(E.SPAN("Not modified by patch:"),
                                       E.BR(),
                                       E.SPAN("Lines: "),
                                       style=dim_style)
        for c in legend.getchildren():
            memo = {}
            modified_by_patch.append(c.__deepcopy__(memo))
            memo = {}
            not_modified_by_patch.append(c.__deepcopy__(memo))

        legend.clear()
        legend.set("class", "headerValueLeg")
        legend.append(modified_by_patch)
        legend.append(E.HR())
        legend.append(not_modified_by_patch)
    except:
        # ignore errors in case there is no legend
        pass
Esempio n. 6
0
 def fixPreserveNL(self, node, text):
     if self.preserve or True:
         text = text.splitlines(1)
         n = None
         children = list(node)
         if len(children) > 0:
             n = children[-1]
         for line in text:
             if n is None:
                 if node.text is None:
                     node.text = line
                 else:
                     node.text += line
             else:
                 if n.tail is None:
                     n.tail = line
                 else:
                     n.tail += line
             if line[-1:] == '\n':
                 n = E.BR()
                 node.append(n)
     else:
         if node.text is None:
             node.text = text
         else:
             node.text += text
Esempio n. 7
0
    def show_report(self):
        """Override base class, because we're not using the Report class.

        Loop back to the cascading form for names if we don't have an id.
        """

        if not self.id:
            self.show_form()
        buttons = (
            self.HTMLPage.button(self.SUBMENU),
            self.HTMLPage.button(self.ADMINMENU),
            self.HTMLPage.button(self.LOG_OUT),
        )
        opts = dict(
            buttons=buttons,
            session=self.session,
            action=self.script,
            banner=self.title,
            footer=self.footer,
            subtitle=self.subtitle,
        )
        report = self.HTMLPage(self.title, **opts)
        instructions = builder.DIV(
            "Click term name to view formatted term document.", builder.BR(),
            "Click document ID to navigate tree.")
        report.body.append(instructions)
        for table in self.tree.tables:
            report.body.append(table)
        report.body.append(self.footer)
        report.add_css("\n".join(self.CSS))
        report.send()
Esempio n. 8
0
 def parse(self, block):
     """"""
     lines = []
     for line in block.splitlines():
         if line.endswith("  "):
             lines.append(line[:-2])
             lines.append(E.BR())
         else:
             lines.append(line + " ")
     return E.P(*lines)
Esempio n. 9
0
    def term_type_table(self):
        """Table showing all of the term type string for the concept."""

        args = [self.term_types[0]]
        for term_type in self.term_types[1:]:
            args += [builder.BR(), term_type]
        term_types = builder.TD(*args)
        table = builder.TABLE(builder.TR(builder.TD("Term Type"), term_types))
        table.set("class", "term-type-table")
        return table
Esempio n. 10
0
 def manifest_html(self):
     """
     This is manifest.html the human useable form of the manifest.xml
     special object to list needed criteria or return a manifest given a
     set of criteria
     """
     web_page = \
             E.HTML(
                    E.HEAD(
                           E.TITLE(_("%s A/I Webserver -- "
                                     "Maninfest Criteria Test") %
                                     _DISTRIBUTION)
                    ),
                    E.BODY(
                           E.H1(_("Welcome to the %s A/I "
                                  "webserver") % _DISTRIBUTION),
                           E.H2(_("Manifest criteria tester")),
                           E.P(_("To test a system's criteria, all "
                                 "criteria listed are necessary. The "
                                 "format used should be:"),
                               E.BR(),
                               E.TT("criteria1=value1;criteria2=value2"),
                               E.BR(), _("For example:"),
                               E.BR(),
                               E.TT("arch=sun4u;mac=EEE0C0FFEE00;"
                                    "ipv4=172020025012;"
                                    "manufacturer=sun microsystems")
                           ),
                           E.H1(_("Criteria:")),
                           E.P(str(list(AIdb.getCriteria(
                               self.AISQL.getQueue(), strip=True)))),
                           E.FORM(E.INPUT(type="text", name="postData"),
                                  E.INPUT(type="submit"),
                                  action="manifest.xml",
                                  method="POST"
                           )
                    )
             )
     return lxml.etree.tostring(web_page, pretty_print=True)
Esempio n. 11
0
        def __add_row(self, rows, name, label):
            """Helper method to create a row for the definition meta table."""

            values = getattr(self, name)
            if values:
                label = builder.TD(label)
                if not isinstance(values, list):
                    values = [values]
                args = [values[0]]
                for value in values[1:]:
                    args.append(builder.BR())
                    args.append(value)
                values = builder.TD(*args)
                rows.append(builder.TR(label, values))
Esempio n. 12
0
def render_change_as_html(change: Dict[str, Any], filepath: str,
                          current_depth: int, max_depth: int) -> Optional[Any]:
    if current_depth >= max_depth:
        return None

    link = change.get("link")
    if link is None:
        link = filepath

    change_elements: List[Any] = [
        E.B("Name: "),
        E.A(change["name"], href=link),
        E.BR(),
        E.B("Type: "),
        E.SPAN(change["type"]),
        E.BR(),
        E.B("Changed lines: "),
        E.SPAN(str(change["changed_lines"])),
    ]

    if change["total_lines"]:
        change_elements.extend(
            [E.BR(),
             E.B("Total lines: "),
             E.SPAN(str(change["total_lines"]))])

    if change["children"]:
        change_elements.extend([E.BR(), E.B("Changes:")])
    child_elements = []
    for child in change["children"]:
        child_element = render_change_as_html(child, filepath,
                                              current_depth + 1, max_depth)
        if child_element is not None:
            child_elements.append(child_element)
    change_elements.append(E.UL(*child_elements))

    return E.LI(*change_elements)
Esempio n. 13
0
    def related_info_table(self):
        """Table at the bottom of the report to links to other information."""

        if not hasattr(self, "_related_info_table"):
            self._related_info_table = None
            rows = [drug_link.row for drug_link in self.drug_links]
            rows += [summary_ref.row for summary_ref in self.summary_refs]
            rows += [external_ref.row for external_ref in self.external_refs]
            rows += [name_link.row for name_link in self.name_links]
            rows += [pdq_term.row for pdq_term in self.pdq_terms]
            if self.thesaurus_ids:
                label = "NCI Thesaurus ID"
                args = [self.thesaurus_ids[0]]
                for id in self.thesaurus_ids[1:]:
                    args += [builder.BR(), id]
                rows.append(builder.TR(builder.TD(label), builder.TD(*args)))
            if rows:
                self._related_info_table = builder.TABLE(*rows)
                self._related_info_table.set("class", "related-info-table")
        return self._related_info_table
Esempio n. 14
0
    def convert_to_html(self, data, room_id):
        if room_id not in self.status_line_cache:
            self.status_line_cache[room_id] = {}

        data = data.rstrip('> \n\r')
        data = data.replace('</i><i>', '')
        data = data.replace('</b><b>', '')
        lines = data.split('\n')

        main_div = E.DIV()

        first_line_chunks = re.split('    +', lines[0], 1)
        if len(first_line_chunks) > 1:
            lines.pop(0)
            location, score = first_line_chunks
            location = location.strip()
            location_full = location
            score = score.strip()

            # Make It Good uses " - ..." on the second line as extension of the
            # location in the status line
            if lines:
                line = lines[0].strip()
                if line.startswith('- '):
                    lines.pop(0)
                    location_full = location + ' (' + line[2:] + ')'

            if location_full != self.status_line_cache[room_id].get(
                    'location', ''):
                main_div.append(E.DIV(E.CLASS('location'), location_full))

            if score != self.status_line_cache[room_id].get('score', ''):
                main_div.append(E.DIV(E.CLASS('score'), score))
        else:
            location = None
            location_full = None
            score = None

        self.status_line_cache[room_id]['location'] = location_full
        self.status_line_cache[room_id]['score'] = score

        base_leading_spaces = min(
            self.count_leading_spaces(s) for s in lines if s.strip(". "))

        current = main_div
        for raw_line in lines:
            line = raw_line.strip()
            if line == '.':
                line = ''

            line_without_tags = re.sub(r'</?[bi]>', '', line)
            if location and line_without_tags.startswith(location):
                continue

            if line.startswith('[') and line.endswith(']'):
                current.attrib['title'] = line
                continue

            if current.tag != 'p' and not line:
                continue

            if current.tag != 'p' or not line:
                current = E.P()
                main_div.append(current)

            fixed_line = raw_line
            if base_leading_spaces > 0 and fixed_line.startswith(
                    " " * base_leading_spaces):
                fixed_line = fixed_line[base_leading_spaces:]

            fixed_line = fixed_line.replace("  ", "\xa0 ")

            self.add_text(current, fixed_line)

            if fixed_line and len(fixed_line) < 50:
                br = E.BR()
                current.append(br)

        self.remove_trailing_brs(main_div)

        html_data = lxml.html.tostring(main_div,
                                       pretty_print=True).decode('utf-8')
        html_data = html_data.replace("&lt;i&gt;", '<i>')
        html_data = html_data.replace("&lt;/i&gt;", '</i>')
        html_data = html_data.replace("&lt;b&gt;", '<b>')
        html_data = html_data.replace("&lt;/b&gt;", '</b>')

        return html_data
Esempio n. 15
0
                style = ""
                style += "width: " + str(19 / width) + "%; "
                style += "min-width: " + str(19 / width) + "%; "
                style += "height: " + str(
                    (100 / 15) * (veranstaltung["s_termin_bis"] -
                                  veranstaltung["s_termin_von"])) + "%; "
                style += "top: " + str((100 / 15) *
                                       (veranstaltung["s_termin_von"] - 7.5) +
                                       2) + "%; "
                style += "left: " + str((19 / width) * spaltencounter +
                                        19 * wochentagcounter + 5) + "%; "
                container.append(
                    E.DIV(E.CLASS("veranstaltung " +
                                  veranstaltung["s_termin_typ"]),
                          E.B(veranstaltung["name"]),
                          E.BR(),
                          E.I(veranstaltung["modul"]),
                          E.BR(),
                          veranstaltung["s_termin_typ"],
                          E.DIV(E.CLASS("bottom"),
                                veranstaltung["s_termin_dozent"], E.BR(),
                                veranstaltung["s_termin_raum"]),
                          style=style))
            spaltencounter += 1
        wochentagcounter += 1

    document.append(container)

with open("modules.json", "w") as f:
    json.dump(tabelle,
              f,