Example #1
0
 def _get_dir_listing(self, path):
     """Build an HTML list of the directory contents."""
     all_fnames = [f for f in os.listdir(path) if not f.startswith('.')]
     suffixes = self.page_options.get('suffix_whitelist', '').split(',')
     fnames = []
     for fname in all_fnames:
         for suffix in suffixes:
             if fname.endswith(suffix):
                 fnames.append(fname)
                 break
             elif os.path.isdir(os.path.join(path, fname)):
                 fnames.append(fname + '/')
                 break
     fnames.sort()
     base = self._get_safe_base_path(path)
     links = []
     for name in fnames:
         doc = Doc()
         name = os.path.join(base, name)
         with doc.tag('a'):
             doc.attr(
                 href=url_for('RawFile:get', name=name.replace('/', '|')))
             doc.text(name)
         links.append(doc.getvalue())
     return list_to_html_list(links)
Example #2
0
 def _raw_file(self, name=None):
     """Build up a page for the Raw File view."""
     name = name if name else ''
     name = name.replace('|', '/')
     display_name = self._get_display_name(name)
     if 'path' not in self.page_options:
         body_txt = 'No directory to serve in the config file.'
     else:
         path = os.path.join(self.path, name)
         body = Doc()
         with body.tag('h1'):
             body.text('File: %s' % display_name)
         with body.tag('div'):
             body.attr(klass='navigation')
             body.asis(self._get_navigation_links(path))
         with body.tag('div'):
             body.attr(klass='files')
             if os.path.exists(path):
                 if os.path.isdir(path):
                     body.asis(self._get_dir_listing(path))
                 else:
                     body.asis(self._get_file(path))
         body_txt = body.getvalue()
     flash_messages = self.page_options.get('flash_messages', True)
     return HtmlPage(head=None,
                     body=body_txt,
                     flash_messages=flash_messages).render_template()
Example #3
0
 def get_one_sample_html(orig_sent, sys_sent, ref_sents, sort_key, print_func):
     orig_sent, sys_sent, *ref_sents = [html.escape(sent) for sent in [orig_sent, sys_sent, *ref_sents]]
     doc = Doc()
     with doc.tag('div', klass='mb-2 p-1'):
         # Sort key
         with doc.tag('div', klass='text-muted small'):
             doc.asis(print_func(sort_key(orig_sent, sys_sent, ref_sents)))
         with doc.tag('div', klass='ml-2'):
             orig_sent_bold, sys_sent_bold = make_differing_words_bold(orig_sent, sys_sent, make_text_bold_html)
             # Source
             with doc.tag('div'):
                 doc.asis(orig_sent_bold)
             # Prediction
             with doc.tag('div'):
                 doc.asis(sys_sent_bold)
             # References
             collapse_id = get_random_html_id()
             with doc.tag('div', klass='position-relative'):
                 with doc.tag('a', ('data-toggle', 'collapse'), ('href', f'#{collapse_id}'),
                              klass='stretched-link small'):
                     doc.text('References')
                 with doc.tag('div', klass='collapse', id=collapse_id):
                     for ref_sent in refs:
                         _, ref_sent_bold = make_differing_words_bold(orig_sent, ref_sent, make_text_bold_html)
                         with doc.tag('div', klass='text-muted'):
                             doc.asis(ref_sent_bold)
     return doc.getvalue()
Example #4
0
def get_multiple_systems_html_report(orig_sents, sys_sents_list, refs_sents, system_names, test_set, lowercase, tokenizer, metrics):
    doc = Doc()
    doc.asis('<!doctype html>')
    with doc.tag('html', lang='en'):
        doc.asis(get_head_html())
        with doc.tag('body', klass='container-fluid m-2 mb-5'):
            doc.line('h1', 'EASSE report', klass='mt-4')
            with doc.tag('a', klass='btn btn-link', href='https://forms.gle/J8KVkJsqYe8GvYW46'):
                doc.text('Any feedback welcome!')
            doc.stag('hr')
            doc.line('h2', 'Test set')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_test_set_description_html(
                    test_set=test_set,
                    orig_sents=orig_sents,
                    refs_sents=refs_sents,
                ))
            doc.line('h2', 'Scores')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.line('h3', 'System vs. Reference')
                doc.stag('hr')
                doc.asis(get_score_table_html_multiple_systems(orig_sents, sys_sents_list, refs_sents, system_names, lowercase, tokenizer, metrics))
            doc.line('h2', 'Qualitative evaluation')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_multiple_systems_qualitative_examples_html(orig_sents, sys_sents_list, refs_sents, system_names))
    return indent(doc.getvalue())
Example #5
0
    def get_one_sample_html(orig_sent, sys_sents, ref_sents, system_names, sort_key, print_func):
        def get_one_sentence_html(sentence, system_name):
            doc = Doc()
            with doc.tag('div', klass='row'):
                with doc.tag('div', klass='col-2'):
                    doc.text(system_name)
                with doc.tag('div', klass='col'):
                    doc.asis(sentence)
            return doc.getvalue()

        doc = Doc()
        with doc.tag('div', klass='mb-2 p-1'):
            # Sort key
            with doc.tag('div', klass='text-muted small'):
                doc.asis(print_func(sort_key(orig_sent, sys_sents, ref_sents)))
            with doc.tag('div', klass='ml-2'):
                # Source
                with doc.tag('div'):
                    doc.asis(get_one_sentence_html(orig_sent, 'Original'))
                # Predictions
                    for sys_sent, system_name in zip(sys_sents, system_names):
                        _, sys_sent_bold = make_differing_words_bold(orig_sent, sys_sent, make_text_bold_html)
                        doc.asis(get_one_sentence_html(sys_sent_bold, system_name))
                # References
                collapse_id = get_random_html_id()
                with doc.tag('div', klass='position-relative'):
                    with doc.tag('a', ('data-toggle', 'collapse'), ('href', f'#{collapse_id}'),
                                 klass='stretched-link small'):
                        doc.text('References')
                    with doc.tag('div', klass='collapse', id=collapse_id):
                        for ref_sent in refs:
                            _, ref_sent_bold = make_differing_words_bold(orig_sent, ref_sent, make_text_bold_html)
                            with doc.tag('div', klass='text-muted'):
                                doc.asis(ref_sent_bold)
        return doc.getvalue()
Example #6
0
 def _get_top_dir_link():
     """Get a link to the Top Directory of the Raw File view."""
     doc = Doc()
     with doc.tag('a'):
         doc.attr(href=url_for('RawFile:index'))
         doc.text('Top Dir')
     return doc.getvalue()
Example #7
0
    def create_body_section(articles: list, create_date: str):
        """
        create HTML Body Section

        Args:
            articles (list): Article Content
            create_date (str) Article Create Date
        Returns: HTML String
        """
        idx = 0
        nav_items = list()
        article_div = list()
        for div in articles:
            if len(div.items) <= 0:
                continue
            if div.title is None:
                div.title = 'Section %s' % str(idx)
            nav_items.append(
                CustomHtml.add_anchor(text=div.title, link=idx, on_click=True))
            article_div.append(
                CustomHtml.create_div(contents=div.items, link=idx, tab=True))
            idx += 1
        _nav_list = CustomHtml.add_unordered_list(items=nav_items)
        doc = Doc()
        with doc.tag('section'):
            doc.asis(CustomHtml.create_body_nav([_nav_list]))
            with doc.tag('article'):
                with doc.tag('i'):
                    doc.text('created on %s ' % create_date)
                for div in article_div:
                    doc.asis(div)
        return doc.getvalue()
Example #8
0
 def get_one_sentence_html(sentence, system_name):
     doc = Doc()
     with doc.tag('div', klass='row'):
         with doc.tag('div', klass='col-2'):
             doc.text(system_name)
         with doc.tag('div', klass='col'):
             doc.asis(sentence)
     return doc.getvalue()
Example #9
0
def write_html_head(doc: yattag.Doc, title: str) -> None:
    """Produces the <head> tag and its contents."""
    with doc.tag("head"):
        with doc.tag("title"):
            doc.text(_("Where to map?") + title)
        doc.stag("meta", charset="UTF-8")
        doc.stag("link", rel="stylesheet", type="text/css", href="/osm/static/osm.css")
        with doc.tag("script", src="/osm/static/sorttable.js"):
            pass
        doc.stag("meta", name="viewport", content="width=device-width, initial-scale=1")
Example #10
0
 def _get_parent_dir_link(parent_dir):
     """Get a link to the parent directory of the current page."""
     doc = Doc()
     with doc.tag('a'):
         if parent_dir == "":
             doc.attr(href=url_for('RawFile:index'))
         else:
             doc.attr(href=url_for('RawFile:get',
                                   name=parent_dir.replace('/', '|')))
         doc.text('Parent Dir')
     return doc.getvalue()
Example #11
0
def get_html_report(orig_sents: List[str], sys_sents: List[str], refs_sents: List[List[str]], test_set_name,
                    lowercase: bool = False, tokenizer: str = '13a', metrics: List[str] = DEFAULT_METRICS):
    sns.set_style('darkgrid')
    doc = Doc()
    doc.asis('<!doctype html>')
    with doc.tag('html', lang='en'):
        doc.asis(get_head_html())
        with doc.tag('body', klass='container-fluid m-2 mb-5'):
            doc.line('h1', 'EASSE report', klass='mt-4')
            with doc.tag('a', klass='btn btn-link', href='https://forms.gle/J8KVkJsqYe8GvYW46'):
                doc.text('Any feedback welcome!')
            doc.stag('hr')
            doc.line('h2', 'Test set')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_test_set_description_html(
                    test_set_name=test_set_name,
                    orig_sents=orig_sents,
                    refs_sents=refs_sents,
                ))
            doc.line('h2', 'Scores')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.line('h3', 'System vs. Reference')
                doc.stag('hr')
                sys_scores = get_all_scores(orig_sents, sys_sents, refs_sents,
                                            lowercase=lowercase, tokenizer=tokenizer, metrics=metrics)
                # TODO: The system and references should be evaluated with the same number of references
                ref_scores = get_all_scores(orig_sents, refs_sents[0], refs_sents[1:],
                                            lowercase=lowercase, tokenizer=tokenizer, metrics=metrics)
                assert sys_scores.keys() == ref_scores.keys()
                doc.asis(get_table_html(
                        header=list(sys_scores.keys()),
                        rows=[sys_scores.values(), ref_scores.values()],
                        row_names=['System output', 'Reference*'],
                        ))
                doc.line(
                    'p',
                    klass='text-muted',
                    text_content=('* The Reference row represents one of the references (picked randomly) evaluated'
                                  ' against the others.'),
                )
                doc.line('h3', 'By sentence length (characters)')
                doc.stag('hr')
                doc.asis(get_scores_by_length_html(orig_sents, sys_sents, refs_sents))
            doc.line('h2', 'Plots')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_plots_html(orig_sents, sys_sents, refs_sents[0]))
            doc.line('h2', 'Qualitative evaluation')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_qualitative_html_examples(orig_sents, sys_sents, refs_sents))
    return indent(doc.getvalue())
Example #12
0
def get_html_report(
    orig_sents: List[str],
    sys_sents: List[str],
    refs_sents: List[List[str]],
    test_set: str,
    lowercase: bool = False,
    tokenizer: str = '13a',
    metrics: List[str] = DEFAULT_METRICS,
):
    doc = Doc()
    doc.asis('<!doctype html>')
    with doc.tag('html', lang='en'):
        doc.asis(get_head_html())
        with doc.tag('body', klass='container-fluid m-2 mb-5'):
            doc.line('h1', 'EASSE report', klass='mt-4')
            with doc.tag('a',
                         klass='btn btn-link',
                         href='https://forms.gle/J8KVkJsqYe8GvYW46'):
                doc.text('Any feedback welcome!')
            doc.stag('hr')
            doc.line('h2', 'Test set')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(
                    get_test_set_description_html(
                        test_set=test_set,
                        orig_sents=orig_sents,
                        refs_sents=refs_sents,
                    ))
            doc.line('h2', 'Scores')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.line('h3', 'System vs. Reference')
                doc.stag('hr')
                doc.asis(
                    get_score_table_html_single_system(orig_sents, sys_sents,
                                                       refs_sents, lowercase,
                                                       tokenizer, metrics))
                doc.line('h3', 'By sentence length (characters)')
                doc.stag('hr')
                doc.asis(
                    get_scores_by_length_html(orig_sents, sys_sents,
                                              refs_sents))
            doc.line('h2', 'Plots')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_plots_html(orig_sents, sys_sents, refs_sents[0]))
            doc.line('h2', 'Qualitative evaluation')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(
                    get_qualitative_examples_html(orig_sents, sys_sents,
                                                  refs_sents))
    return indent(doc.getvalue())
Example #13
0
    def create_body_footer(text: str):
        """
        create HTML Body Footer

        Args:
            text (str): Footer Text
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('footer'):
            with doc.tag('i'):
                doc.text(text)
        return doc.getvalue()
Example #14
0
    def create_head(style: str):
        """
        create HTML Head

        Args:
            style (str): CSS Style
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('head'):
            with doc.tag('title'):
                doc.text('SAP Explainable AI Report')
            doc.stag('meta',
                     charset="utf-8",
                     name="viewport",
                     content="width=device-width, initial-scale=1")
            with doc.tag('style'):
                doc.asis(style)
        return doc.getvalue()
Example #15
0
    def add_header(text: str, heading: str, link=None, style=False):
        """
        add text string as header

        Args:
            text (str): text string written to pdf, with current
                        global indent level
            heading (str): heading elements of the text (h1 - h6)
            link (str): link idx created earlier for internal anchor
            style (bool): css style class
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag(heading):
            if not (link is None):
                doc.attr(id="a%s" % link)
            if style:
                doc.attr(klass='section-title')
            doc.text(text)
        return doc.getvalue()
Example #16
0
    def add_anchor(text: str, link=None, on_click=False):
        """
        add link idx as anchor

        Args:
            text (str): text string written to pdf, with current
                        global indent level
            link (str): link idx created earlier for internal anchor
            on_click (bool): indicate if the list item (menu) click-able,
                                default False
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('a'):
            if link is None and not (text is None):
                link = "%s" % text.lower().replace(" ", "-")
            doc.attr(href="#a%s" % link)
            if on_click:
                doc.attr(onclick="Section(event, 't%s')" % link)
            doc.attr(klass='tab_links')
            doc.text(text)
        return doc.getvalue()
Example #17
0
    def add_table(header: list, data: list):
        """
        add table

        Args:
            header (list): list of header
            data (list): list of rows (list)
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('table'):
            doc.attr(klass='standard_table')
            with doc.tag('tr'):
                for h in header:
                    with doc.tag('th'):
                        doc.text(h)
            for row in data:
                with doc.tag('tr'):
                    for item in range(len(data[0])):
                        with doc.tag('td'):
                            doc.text(row[item])
        return doc.getvalue()
Example #18
0
 def index(self):
     """Handle an incoming request for a route registered to this View."""
     hello_world = 'Hello World From Netify'
     debug = False
     if 'debug' in self.page_options:
         debug = self.page_options['debug']
     if debug:
         body = Doc()
         body.text(hello_world)
         body.stag('hr')
         body.text('View Functions:')
         body.stag('br')
         body.asis(build_debug_div(self.netify_app))
         body_txt = body.getvalue()
         flash('Instance Path: %s' %
               self.netify_app.flask_app.instance_path)
     else:
         body_txt = hello_world
     flash('This is what a flashed message looks like: %s' % hello_world)
     flash_messages = self.page_options.get('flash_messages', False)
     return HtmlPage(head=make_header(),
                     body=body_txt,
                     flash_messages=flash_messages).render_template()
Example #19
0
def build_html(data):
    doc, tag, text, line = Doc().ttl()
    doc.asis('<!DOCTYPE html>')
    with tag('html'):
        with tag('head'):
            doc.asis('<meta charset="utf-8"/>')
            doc.asis('<link href="../css/default.css" rel="stylesheet">')
        with tag('body'):
            for id, card in data['cards'].items():
                with tag('div', klass='card'):
                    with tag('div', klass='card-text'):
                        doc.text(card['text'])
                    if 'details' in card:
                        with tag('div', klass='card-details'):
                            doc.text(card['details'])
                    if 'image' in card:
                        with tag('div', klass='card-image'):
                            doc.stag('img', src='../img/' + card['image'])
            for empty_id in range(0, 8 - (len(data['cards'].items()) % 8)):
                with tag('div', klass='card card-empty'):
                    with tag('div', klass='card-image card-image-empty'):
                        pass

    return doc.getvalue()
Example #20
0
def write_report(history, cols, top_level_labels, grid_pos, row_counts, result_ranges, row_deltas):
    if not os.path.exists(REPORT_ROOT):
        os.makedirs(REPORT_ROOT, exist_ok=True)

    for i in os.listdir(REPORT_ROOT):
        os.remove(os.path.join(REPORT_ROOT, i))

    i_to_label_index = {
        i: top_level_labels[label[0]]
        for (label, _, _, _, _), (i, _) in grid_pos.items()
    }

    label_indices = {i: [] for i in range(len(top_level_labels))}
    for i, label_index in i_to_label_index.items():
        label_indices[label_index].append(i)

    doc, tag, text, line = Doc().ttl()
    def add_source(source):
        shutil.copy(os.path.join(ARTIFACT_ROOT, source), os.path.join(REPORT_ROOT, source))
        if source.endswith(".css"):
            doc.stag("link", rel="stylesheet", href=source)

        elif source.endswith(".js"):
            with tag("script", type="text/javascript", src=source):
                pass

        else:
            raise ValueError(f"Invalid file: {source}")

    doc.asis("<!DOCTYPE html>")
    with tag("html"):
        with tag("head"):
            add_source("tabs.css")
            add_source("style.css")
            table_data = gen_data(doc, tag, label_indices, history, cols, row_counts, row_deltas, result_ranges, i_to_label_index)
            add_source("style.js")

        with tag("body", klass="page_style", onload="initPage();"):
            gen_controls(doc, tag, top_level_labels, cols, label_indices, row_counts)
            doc.asis("<br><br>")

            with tag("div", klass="tabcontent", id="summary"):
                body = textwrap.dedent("""
                    <h1>Note: This is still WIP. More documentation is coming.</h1>

                    <h2>Welcome to the Wall of Serotonin (TM) v2.</h2>

                    <h1>The checkboxes hide various aspects of the data:</h1>
                    &nbsp;- Levels of significance. (high, moderate, and low)
                    &nbsp;- Python or C++ (Table only)
                    &nbsp;- High level groupings of benchmarks

                    Data can be viewed in either table or graph form.

                    On the table tab deltas are shown using the formula:
                    diff = (b - a) / low_water_mark

                    On the graph tab, absolute instruction counts are shown.

                    Shift + arrow key (left / right) moves between tabs.
                """)

                doc.asis("\n<br>".join(body.splitlines()))

            with tag("div", klass="tabcontent", id="table"):
                with tag("table", klass="data-table"):
                    with tag("thead", id=f"dynamic-thead"):
                        pass
                    for i in range(10):
                        with tag("tbody", id=f"dynamic-row-{i}"):
                            pass

            with tag("div", klass="tabcontent", id="graphs"):
                with tag("table"):
                    with tag("tr"):
                        with tag("td", style="min-width:450px;max-width:450px", valign="top"):
                            with tag("font", size=6):
                                doc.text("Controls:")
                                doc.stag("br")
                            with tag("font", size=4):
                                doc.asis("&nbsp;&nbsp;Arrow keys move selection left / right.")
                                doc.stag("br")
                                doc.asis("&nbsp;&nbsp;(Or click on the buttons to select.)")
                                doc.stag("br")
                                doc.stag("br")
                                doc.asis("&nbsp;&nbsp;Drag to zoom in. Right click to reset.")
                                doc.stag("br")
                                doc.stag("br")
                                doc.asis("&nbsp;&nbsp;Click on points to get the commit.")

                            for _ in range(4):
                                doc.stag("br")

                            with tag("font", size=5):
                                with tag("div", id="graph-selection-author"):
                                    pass

                                doc.stag("br")
                                with tag("div", id="graph-selection-commit"):
                                    pass

                            with tag("font", size=4):
                                doc.stag("br")
                                with tag("div", id="graph-selection-msg"):
                                    pass

                        with tag("td", valign="top"):
                            with tag("div", id="curve_chart"):
                                pass

            with tag("div", klass="tabcontent", id="static-table"):
                write_static_table(
                    doc,
                    tag,
                    table_data,
                    cols,
                    top_level_labels,
                    i_to_label_index,
                    label_indices,
                    result_ranges,
                    row_deltas,
                )

    with open(REPORT_FILE, "wt") as f:
        f.write(indent(doc.getvalue()))

    print("Done.")
Example #21
0
    def export(self):
        doc, tag, text = Doc().tagtext()
        with open("result.json") as f:
            data = json.dumps(f.readlines())
            items = json.loads(data)
        with tag('html'):
            with tag('head'):
                doc.stag('meta', charset='utf-8')

                doc.stag('meta', name="viewport",
                         content='width=device-width, initial-scale=1')
                doc.stag('link', rel="stylesheet",
                         href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css")
                with tag(
                        'script', src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'):
                    pass

                with tag(
                        'script', src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js'):
                    pass
                with tag(
                        'script', src='https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js'):
                    pass

            with tag('body'):
                doc.attr(klass="container normal-style")
                with tag('h3', klass='breaking-news'):
                    text(f'Report With {len(items)} item(s) - ZIPCODE: 33131')
                with tag('table', klass='table table-striped'):
                    with tag('thead'):
                        with tag('tr'):
                            with tag('th', scope="col"):
                                doc.text('TITLE')
                            with tag('th', scope="col"):
                                doc.text('STOCK')
                            with tag('th', scope="col"):
                                doc.text('PRICE')
                            with tag('th', scope="col"):
                                doc.text('PRODUCT_ID')
                            with tag('th', scope="col"):
                                doc.text('SKU_ID')
                            with tag('th', scope="col"):
                                doc.text('SHIPPING_DATE')
                            with tag('th', scope="col"):
                                doc.text('SHIPPING_PRICE')

                    with tag('tbody'):
                        with tag('div'):
                            for item in items:
                                item = json.loads(item)
                                with tag('tr'):

                                    with tag('td'):
                                        doc.text(item['title'])
                                    with tag('td'):
                                        doc.text(item['status'])
                                    with tag('td'):
                                        doc.text(item['price'])
                                    with tag('td'):
                                        doc.text(item['product_id'])
                                    with tag('td'):
                                        doc.text(item['sku_id'])
                                    with tag('td'):
                                        for each_date in item['arrives']:
                                            if len(each_date) > 1:
                                                with tag('li'):
                                                    doc.text(each_date)
                                    with tag('td'):
                                        for each_cost in item['cost']:
                                            if len(each_cost) > 1:
                                                with tag('li'):
                                                    doc.text(each_cost)

        return indent(doc.getvalue(),
                      indentation='    ',
                      newline='\r\n',
                      indent_text=True)
Example #22
0
 def to_html(self):
   """Method for producing and html string document from presentation object."""
   doc, tag, text = Doc().tagtext()
   doc.asis('<!DOCTYPE html>')
   with tag('html'):
     doc.attr(title = self.metadata.data.data['title'][0])
     with tag('head'):
       doc.stag('meta',charset='utf-8')
       doc.stag('meta',author=' and '.join(self.metadata.data.data['authors'][0]))
       with tag('title'):
         text(self.metadata.data.data['title'][0])
       doc.stag('meta',subtitle=self.metadata.data.data['subtitle'][0])
       doc.stag('link',rel='stylesheet', href='css/normalize.css')
       if __config__.highlight:
         doc.stag('link',rel='stylesheet', href='js/highlight/styles/'+__config__.highlight_style)
       doc.stag('link',rel='stylesheet', href='css/theme.css')
     with tag('body',onload="resetCountdown("+self.metadata.data.data['max_time'][0]+");"):
       with tag('div',id='impress'):
         if self.titlepage.found:
           html = self.titlepage.to_html(position = self.pos, theme = self.theme.slide)
           html = self.metadata.parse(html)
           html = self.toc.parse(html)
           doc.asis(html)
         for section in self.sections:
           for subsection in section.subsections:
             for slide in subsection.slides:
               html = slide.to_html(position = self.pos, theme = self.theme.slide)
               html = self.metadata.parse(html)
               html = self.toc.parse(html,current=[int(slide.data['sectionnumber']),int(slide.data['subsectionnumber']),slide.number])
               doc.asis(html)
       with tag('script'):
         doc.attr(src='js/countDown.js')
       with tag('script'):
         doc.attr(src='js/impress.js')
       with tag('script'):
         doc.asis('impress().init();')
       if __config__.online_mathjax:
         with tag('script'):
           doc.attr(('type','text/javascript'))
           doc.attr(src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML')
       else:
         with tag('script'):
           doc.attr(('type','text/x-mathjax-config'))
           doc.text("""
             MathJax.Hub.Config({
               extensions: ["tex2jax.js"],
               jax: ["input/TeX", "output/HTML-CSS"],
               tex2jax: {
                 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
                 processEscapes: true
               },
               "HTML-CSS": { availableFonts: ["Neo-Euler"] }
             });
           """)
         with tag('script'):
           doc.attr(('type','text/javascript'))
           doc.attr(src='js/MathJax/MathJax.js')
       if __config__.highlight:
         with tag('script'):
           doc.attr(src='js/highlight/highlight.pack.js')
         with tag('script'):
           doc.text("""hljs.initHighlightingOnLoad();""")
   if __config__.indented:
     return indent(doc.getvalue())
   else:
     return doc.getvalue()
Example #23
0
def generate_plot_browser(plot_browser_dir, base_url_dir, github_url, full_report_filename, list_of_figures,
                          list_of_figures_full_report, regions_to_present):
    if not path.exists(plot_browser_dir):
        os.mkdir(plot_browser_dir)

    alphabetical_states = sorted(regions_to_present)  # load_data.map_state_to_current_case_cnt.keys())
    # alphabetical_states.remove('total')
    # alphabetical_states = ['total'] + alphabetical_states

    map_state_to_html = dict()
    for state in alphabetical_states:

        state_lc = state.lower().replace(' ', '_')
        doc, tag, text = Doc(defaults={'title': f'Plots for {state}'}).tagtext()

        doc.asis('<!DOCTYPE html>')
        with tag('html'):
            with tag('head'):
                pass
            with tag('body'):
                with tag('div', id='photo-container'):
                    with tag('ul'):
                        with tag('li'):
                            with tag('a', href='../index.html'):
                                text('<-- Back')
                        for figure_name in list_of_figures:
                            tmp_url = base_url_dir + state_lc + '/' + figure_name
                            with tag("a", href=tmp_url):
                                doc.stag('img', src=tmp_url, klass="photo", height="300", width="400")
                            with tag('li'):
                                with doc.tag("a", href=tmp_url):
                                    doc.text(figure_name)
                            with tag('hr'):
                                pass

        result = doc.getvalue()
        map_state_to_html[state] = result

    for state in map_state_to_html:
        state_lc = state.lower().replace(' ', '_').replace(':','')
        if not path.exists(path.join(plot_browser_dir, state_lc)):
            os.mkdir(path.join(plot_browser_dir, state_lc))
        with open(path.join(plot_browser_dir, path.join(state_lc, 'index.html')), 'w') as f:
            f.write(map_state_to_html[state])

    #####
    # Generate state-report page
    #####

    with open(path.join(plot_browser_dir, full_report_filename), 'w') as f:
        doc, tag, text = Doc(defaults={'title': f'Plots for Full Report'}).tagtext()
        doc.asis('<!DOCTYPE html>')
        with tag('html'):
            with tag('head'):
                pass
            with tag('body'):
                with tag('div', id='photo-container'):
                    with tag('ul'):
                        with tag('li'):
                            with tag('a', href='index.html'):
                                text('<-- Back')
                        for figure_name in list_of_figures_full_report:
                            tmp_url = base_url_dir + figure_name
                            with tag("a", href=tmp_url):
                                doc.stag('img', src=tmp_url, klass="photo", height="400", width="300")
                            with tag('li'):
                                with doc.tag("a", href=tmp_url):
                                    doc.text(figure_name)
                            with tag('hr'):
                                pass
        f.write(doc.getvalue())

    #####
    # Generate landing page
    #####

    with open(path.join(plot_browser_dir, 'index.html'), 'w') as f:
        doc, tag, text = Doc(defaults={'title': f'Plots for {state}'}).tagtext()

        doc.asis('<!DOCTYPE html>')
        with tag('html'):
            with tag('head'):
                pass
            with tag('body'):
                with tag('ul'):
                    with tag('li'):
                        with tag("a", href=github_url):
                            text('<-- Back to Repository')
                    with tag('li'):
                        with tag("a", href=full_report_filename):
                            text(f'Full Report')
                    for state in alphabetical_states:
                        state_lc = state.lower().replace(' ', '_').replace(':', '')
                        tmp_url = state_lc + '/index.html'
                        if state.lower().startswith('us:_'):
                            print_state = state[4:]
                        else:
                            print_state = state
                        print_state = print_state.title().replace('_', ' ').replace(' Of', ' of')
                        with tag('li'):
                            with tag("a", href=tmp_url):
                                text(print_state)
        f.write(doc.getvalue())
class IDontSpeaksSSLReporterHTML(IDontSpeaksSSLReporter):
    pass

    def run(self):
        self.doc = Doc()
        copy_js_css(self.report_folder)
        cprint("[-] Generating the HTML report...", 'blue')
        self.doc.asis('<!DOCTYPE html>')
        self.create_header()
        self.create_body()
        self.write_report()
        cprint("[+] Report generated.", 'green')
        cprint(
            "[+] All results can be found in {}/report.html.".format(
                self.report_folder), 'green')

    def create_body(self):
        with self.doc.tag('body'):
            with self.doc.tag('div'):
                self.doc.attr(klass='container')
                self.doc.line('h1', 'IDontSpeakSSL Report')
                self.add_summary_section(
                    "Findings Summary",
                    self.results['analyzer results']["summary"])
                self.add_hosts_section(
                    "Findings per Host",
                    self.results['analyzer results']["hosts"])

    def add_summary_section(self, section, subsections):
        self.doc.line('h2', section)
        with self.doc.tag('div'):
            self.doc.attr(klass='panel-group')
            for subsection, instances in subsections.items():
                if instances:
                    with self.doc.tag('div', klass='panel panel-default'):
                        with self.doc.tag('div', klass='panel-heading'):
                            with self.doc.tag('div', klass='panel-title'):
                                with self.doc.tag('h4', klass='panel-title'):
                                    with self.doc.tag(
                                            'a', ("data-toggle", "collapse"),
                                        ("href", "#{}".format(
                                            capitalize_sentence(subsection)))):
                                        self.doc.text("{}".format(
                                            capitalize_sentence(subsection)))
                        with self.doc.tag('div'):
                            self.doc.attr(klass='panel-collapse collapse',
                                          id='{}'.format(
                                              capitalize_sentence(subsection)))
                            with self.doc.tag('div', klass='panel-body'):
                                if (subsection != "vulnerabilities"):
                                    with self.doc.tag('ul'):
                                        for instance in instances:
                                            self.doc.line(
                                                'li',
                                                "Host: {}, Port: {}".format(
                                                    instance['host'],
                                                    instance['port']))
                                else:
                                    with self.doc.tag('ul'):
                                        for vulnerability_name, vulnerability_instance in instances.items(
                                        ):
                                            self.doc.line(
                                                'li', "{}".format(
                                                    vulnerability_name))
                                            with self.doc.tag('ul'):
                                                for location in vulnerability_instance:
                                                    self.doc.line(
                                                        'li',
                                                        "Host: {}, Port: {}".
                                                        format(
                                                            location['host'],
                                                            location['port']))

    def add_hosts_section(self, section, hosts):
        self.doc.line('h2', section)
        with self.doc.tag('div'):
            self.doc.attr(klass='panel-group')
            for host, findings in hosts.items():
                if findings:
                    with self.doc.tag('div', klass='panel panel-default'):
                        with self.doc.tag('div', klass='panel-heading'):
                            with self.doc.tag('div', klass='panel-title'):
                                with self.doc.tag('h4', klass='panel-title'):
                                    with self.doc.tag(
                                            'a', ("data-toggle", "collapse"),
                                        ("href", "#{}".format(
                                            host.replace(".", "_")))):
                                        instance_host, instance_port = extract_host_and_port(
                                            host)
                                        self.doc.text(
                                            "Host: {}, Port: {}".format(
                                                instance_host, instance_port))

                    with self.doc.tag('div'):
                        self.doc.attr(klass='panel-collapse collapse',
                                      id='{}'.format(host.replace(".", "_")))
                        with self.doc.tag('div', klass='panel-body'):
                            for finding_type, finding_instance in findings.items(
                            ):
                                self.doc.text("{}".format(finding_type))
                                if (isinstance(finding_instance, list)):
                                    with self.doc.tag('ul'):
                                        for instance in finding_instance:
                                            self.doc.line(
                                                'li', "{}".format(instance))
                                elif (isinstance(finding_instance, bool)):
                                    if (finding_instance):
                                        self.doc.text(": Vulnerable")

    def create_header(self):
        with self.doc.tag('head'):
            self.doc.line('title', 'IDontSpeakSSL Report')
            self.doc.stag('link', ("rel", "stylesheet"),
                          ("href", "html/css/bootstrap.min.css"))
            self.doc.line('script', '', src="html/js/jquery.min.js")
            self.doc.line('script', '', src="html/js/bootstrap.min.js")

    def write_report(self):
        with open("{}/report.html".format(self.report_folder), 'w') as report:
            report.write(indent(self.doc.getvalue()))
Example #25
0
                            text('ЗОЖ - это не всё')
                with tag('div', klass='central_block_exercise'):
                    with tag('br'):
                        with tag('td'):
                            text('Хорошилов Анастас')
                    with tag('br'):
                        with tag('td'):
                            text('Очень хороший тренер')
                    with tag('br'):
                        with tag('td'):
                            text('ЗОЖ - это не всё')
        with tag('div', klass='past_lesson'):
            with tag('a', href='katya.html'):
                text('Предыдущий')
        with tag('div', klass='next_lesson'):
            with tag('a', href='max.html'):
                text('Следующий')
        with tag('div', klass='footer'):
            with tag('p'):
                with tag('a', href='#'):
                    doc.text('Политика конфиденциальности')
                with tag('a', href='#'):
                    doc.text('Связаться с нами')
                with tag('br'):
                    doc.text('All rights reserved')

with open('page_skelet.html', 'w') as f:
    f.write(doc.getvalue())

print(doc.getvalue())
Example #26
0
 def render(self, doc: yattag.Doc) -> None:
     """Render this value to HTML"""
     with doc.tag('a', href=self.target):
         if self.text:
             doc.text(self.text)
Example #27
0
 def to_html(self):
     """Method for producing and html string document from presentation object."""
     doc, tag, text = Doc().tagtext()
     doc.asis('<!DOCTYPE html>')
     with tag('html'):
         doc.attr(title=self.metadata.data.data['title'][0])
         with tag('head'):
             doc.stag('meta', charset='utf-8')
             doc.stag('meta',
                      author=' and '.join(
                          self.metadata.data.data['authors'][0]))
             with tag('title'):
                 text(self.metadata.data.data['title'][0])
             doc.stag('meta',
                      subtitle=self.metadata.data.data['subtitle'][0])
             doc.stag('link', rel='stylesheet', href='css/normalize.css')
             if __config__.highlight:
                 doc.stag('link',
                          rel='stylesheet',
                          href='js/highlight/styles/' +
                          __config__.highlight_style)
             doc.stag('link', rel='stylesheet', href='css/theme.css')
         with tag('body',
                  onload="resetCountdown(" +
                  self.metadata.data.data['max_time'][0] + ");"):
             with tag('div', id='impress'):
                 if self.titlepage.found:
                     if self.theme.slide.data.data['slide-transition'][
                             0].lower() == 'svgpath':
                         pos = self.svgpath_pos[0]
                     else:
                         pos = self.pos
                     html = self.titlepage.to_html(position=pos,
                                                   theme=self.theme.slide)
                     html = self.metadata.parse(html)
                     html = self.toc.parse(html)
                     doc.asis(html)
                 for section in self.sections:
                     for subsection in section.subsections:
                         for slide in subsection.slides:
                             if slide.title == '$overview':
                                 pos = self.center
                             elif self.theme.slide.data.data[
                                     'slide-transition'][0].lower(
                                     ) == 'svgpath':
                                 pos = self.svgpath_pos[slide.number - 1]
                             else:
                                 pos = self.pos
                             html = slide.to_html(position=pos,
                                                  theme=self.theme.slide)
                             html = self.metadata.parse(html)
                             html = self.toc.parse(
                                 html,
                                 current=[
                                     int(slide.data['sectionnumber']),
                                     int(slide.data['subsectionnumber']),
                                     slide.number
                                 ])
                             doc.asis(html)
             with tag('script'):
                 doc.attr(src='js/countDown.js')
             with tag('script'):
                 doc.attr(src='js/impress.js')
             with tag('script'):
                 doc.asis('impress().init();')
             if __config__.online_mathjax:
                 with tag('script'):
                     doc.attr(('type', 'text/javascript'))
                     doc.attr(
                         src=
                         'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
                     )
             else:
                 with tag('script'):
                     doc.attr(('type', 'text/x-mathjax-config'))
                     doc.text("""
           MathJax.Hub.Config({
             extensions: ["tex2jax.js"],
             jax: ["input/TeX", "output/HTML-CSS"],
             tex2jax: {
               inlineMath: [ ['$','$'], ["\\(","\\)"] ],
               displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
               processEscapes: true
             },
             "HTML-CSS": { availableFonts: ["Neo-Euler"] }
           });
         """)
                 with tag('script'):
                     doc.attr(('type', 'text/javascript'))
                     doc.attr(src='js/MathJax/MathJax.js')
             if __config__.highlight:
                 with tag('script'):
                     doc.attr(src='js/highlight/highlight.pack.js')
                 with tag('script'):
                     doc.text("""hljs.initHighlightingOnLoad();""")
     if __config__.indented:
         return indent(doc.getvalue())
     else:
         return doc.getvalue()
Example #28
0
 def render(self, doc: yattag.Doc) -> None:
     """Render this value to HTML"""
     doc.text(self.text)