Beispiel #1
0
    def make_cfr_report(self, f, cfr):

        print(f".. _{cfr.skb}:\n", file=f)
        print(rstgen.header(1, cfr.skb + " " + cfr.message), file=f)

        total_matches = len(self.all_matches_per_clfr[cfr.skb])
        files_with_matches = self.files_per_cfr[cfr.skb]
        files_matched_rel = len(files_with_matches) / max(1, len(self.matches_per_file))

        print(
            f"Found a total of {len(self.all_matches_per_clfr[cfr.skb])} matches in "
            f"{len(files_with_matches)} ({files_matched_rel*100:.1f}%) runs "
            f'{", ".join(sorted(files_with_matches))}\n',
            file=f,
        )

        # Show example matches
        for cfr_match in self.matches_per_clfr[cfr.skb]:

            first = True

            def test_id(match):
                return (
                    match["test"]["file"],
                    match["test"]["name"],
                    match["test"].get("param"),
                )

            for tid in {test_id(match) for match in cfr_match["matches"]}:

                # Get all data
                matches = [
                    match for match in cfr_match["matches"] if test_id(match) == tid
                ]
                test = matches[0]["test"]

                # Show header for test
                if "param" in test:
                    test_name = f"{test.get('status')} test {test['file']}::{test['name']}[{test['param']}]"
                else:
                    test_name = (
                        f"{test.get('status')} test {test['file']}::{test['name']}"
                    )

                date = cfr_match["date"].strftime("%Y-%m-%d")
                if first:
                    print(f".. _{cfr.skb}-{cfr_match['log_id']}:\n", file=f)
                    first = False
                print(rstgen.header(2, f" {date} {test_name}"), file=f)

                print(
                    f"See also :download:`{cfr_match['name']} <log-{cfr_match['log_id']}.txt>`"
                    f"{'' if cfr_match['source'] is None else ' (source ' + cfr_match['source'] + ')'}"
                    f", recorded {cfr_match['date']}\n",
                    file=f,
                )

                self.make_test_report(f, test, matches)

        return files_matched_rel
Beispiel #2
0
def write_readme(ctx):
    """Generate or update `README.txt` or `README.rst` file from `SETUP_INFO`. """
    if not atelier.current_project.main_package:
        return
    atelier.current_project.load_info()
    info = atelier.current_project.SETUP_INFO
    if not info.get('long_description'):
        return
    # if len(ctx.doc_trees) == 0:
    #     # when there are no docs, then the README file is manually maintained
    #     return
    if ctx.revision_control_system == 'git':
        readme = ctx.root_dir.child('README.rst')
    else:
        readme = ctx.root_dir.child('README.txt')

    # for k in ('name', 'description', 'long_description', 'url'):
    #     if k not in env.current_project.SETUP_INFO:
    #         msg = "SETUP_INFO for {0} has no key '{1}'"
    #         raise Exception(msg.format(env.current_project, k))

    title = rstgen.header(1, "The ``{}`` package".format(info['name']))

    txt = """\
{title}

{long_description}
""".format(title=title, **info)
    if readme.exists() and readme.read_file() == txt:
        return
    must_confirm("Overwrite %s" % readme.absolute())
    readme.write_file(txt)
    docs_index = ctx.root_dir.child('docs', 'index.rst')
    if docs_index.exists():
        docs_index.set_times()
Beispiel #3
0
    def write_index(self):
        index = self.screenshot_root.child('index.rst')
        if self.ref:
            content = ".. _{0}:\n\n".format(self.ref)
        else:
            content = ""
        content += rstgen.header(1, self.title)
        content += "\n\n\n"
        if self.intro:
            content += unindent(self.intro)
            content += "\n\n\n"

        for name, caption, before, after in self.screenshots:
            content += "\n\n"
            content += rstgen.header(2, caption)
            content += """

{before}

.. image:: {name}
    :alt: {caption}
    :width: 500

{after}

""".format(**locals())

        if self.error_message:
            content += "\n\n"
            if self.ref:
                content += ".. _{0}.oops:\n\n".format(self.ref)
            content += rstgen.header(2, "Not finished")
            content += "\n\n"
            content += "Oops, we had a problem when generating this document::\n"
            isep = '\n    '
            content += isep
            content += isep.join(self.error_message.splitlines())
            content += "\n\n"

        if six.PY2:
            content = content.encode('utf-8')
        index.write_file(content)
Beispiel #4
0
def list(ctx, rst):
    """
    List the Lino applications known by getlino.

    """

    if rst:
        click.echo(".. Generated by `getlino list --rst`")
        click.echo(".. _getlino.apps:\n")
        click.echo(rstgen.header(1, "List of the known Lino applications"))
        click.echo(
            "\nThe following applications are supported by :cmd:`getlino startsite`.\n"
        )
    rows = []
    headings = ["Name", "Short description", "Nickname"]
    for r in KNOWN_APPS:
        m = import_module(r.settings_module)
        s = m.Site
        # r: nickname package_name git_repo settings_module front_end
        # print(r.settings_module)
        if rst:
            cells = [
                ":ref:`{s.verbose_name}<{r.nickname}>`".format(**locals()),
                s.description or '', r.nickname
            ]
            rows.append(cells)
        else:
            click.echo(
                "{r.nickname} : {s.verbose_name} : {s.description}".format(
                    **locals()))
            # if s.description:
            #     click.echo("\n" + s.description.strip() + "\n")
            # if r.git_repo:
            #     print("(`Source repository <{r.git_repo}>`__)".format(**locals()))
    if rst:
        click.echo(rstgen.table(headings, rows))
        tpl = JINJA_ENV.get_template("apps_section.rst")
        for r in KNOWN_APPS:
            m = import_module(r.settings_module)
            s = m.Site
            p = import_module(r.package_name.replace("-", "_"))
            public_url = None
            if hasattr(p, 'intersphinx_urls'):
                public_url = p.intersphinx_urls.get('docs', None)
            context = dict(repo=r,
                           package=p,
                           m=m,
                           site=s,
                           rstgen=rstgen,
                           public_url=public_url)
            click.echo(tpl.render(**context))
Beispiel #5
0
def edit_blog_entry(ctx, today=None):
    """Edit today's blog entry, create an empty file if it doesn't yet exist.

    :today: Useful when a working day lasted longer than midnight, or
            when you start some work in the evening, knowing that you
            won't commit it before the next morning.  Note that you
            must specify the date using the YYYYMMDD format.

            Usage example::

                $ inv blog -t 20150727

    """
    if not ctx.editor_command:
        raise MissingConfig("editor_command")
    today = get_current_date(today)
    entry = get_blog_entry(ctx, today)
    if not entry.path.exists():
        if ctx.languages is None:
            # txt = today.strftime(ctx.long_date_format)
            lng = 'en'
        else:
            lng = ctx.languages[0]
        txt = format_date(today, format='full', locale=lng)
        txt = txt[0].upper() + txt[1:]  # estonian weekdays
        content = rstgen.header(1, txt)
        content = ":date: {0}\n\n".format(today) + content
        msg = "{0}\nCreate file {1}?".format(content, entry.path)
        if not confirm(msg):
            return
        # for every year we create a new directory.
        yd = entry.path.parent
        if not yd.exists():
            if not confirm("Happy New Year! Create directory %s?" % yd):
                return
            yd.mkdir()
            txt = ".. blogger_year::\n"
            yd.child('index.rst').write_file(txt)

        entry.path.write_file(content)
        # touch it for Sphinx:
        entry.path.parent.child('index.rst').set_times()
    args = [ctx.editor_command.format(entry.path)]
    args += [entry.path]
    # raise Exception("20160324 %s", args)
    ctx.run(' '.join(args), pty=False)
Beispiel #6
0
    def make_test_report(self, f, test, matches):

        # Get the timestamps of all lines that matched. We assume those to
        # be unique.
        match_lines = set()
        for match in matches:
            match_lines |= {line["time"] for line in match["matched"]}

        # Print test data
        self.make_log_block(f, test["msgs"], match_lines)
        for section_name, section_lines in test.get("detail", {}).items():
            print(f"{section_name}:\n", file=f)
            self.make_log_block(f, section_lines, match_lines)

        if "teardown" not in test:
            return
        print(rstgen.header(4, f"Teardown"), file=f)
        self.make_log_block(f, test["teardown"], match_lines)
        for section_name, section_lines in test.get("teardown_detail", {}).items():
            print(f"{section_name}:\n", file=f)
            self.make_log_block(f, section_lines, match_lines)
Beispiel #7
0
    try:
        report.add_file_or_uri(fname)
    except Exception:
        traceback.print_exc()
report.build_maps()

# Create overview
pages = {
    "Overview": ["overview.rst", "timing.rst"],
    "Never": [],
    "Always": [],
    "Sometimes": [],
}
with open("overview.rst", "w", encoding="utf-8") as f:

    print(rstgen.header(1, "Test Overview"), file=f)
    print(
        f"{report.total_lines} lines scanned against {len(classifiers.classifiers)} "
        "classifiers, result summary:\n",
        file=f,
    )
    report.make_overview_table(f)

    for rev, date in sorted(report.revisions.items(),
                            key=lambda rev_date: rev_date[1],
                            reverse=True):
        print(rstgen.header(2, rev), file=f)
        report.make_overview_table(f, rev)

# Create timing overview
with open("timing.rst", "w", encoding="utf-8") as f:
Beispiel #8
0
def html2rst(e, stripped=False):
    """
    Convert an element tree to reStructuredText.
    """
    #~ print("20120613 html2odftext()", e.tag, e.text)
    rst = ''
    if e.tag in ('p', 'li'):
        if not stripped:
            rst += '\n\n'

    elif e.tag in ('ul', 'ol'):
        rst += '\n'
    elif e.tag == 'br':
        if stripped:
            rst += '\n'
        else:
            rst += ' |br| \n'
    elif e.tag == 'b':
        rst += '**'
    elif e.tag == 'em' or e.tag == 'i':
        rst += '*'
    elif e.tag == 'a':
        rst += '`'

    if e.text:
        rst += e.text
    for child in e:
        rst += html2rst(child, stripped)

    if e.tag in NEWLINE_TAGS:
        if stripped:
            rst += '\n'
        else:
            rst += '\n\n'
    elif e.tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6'):
        rst = rstgen.header(int(e.tag[1]), rst.strip()).strip()
        if stripped:
            rst += '\n'
        else:
            rst = '\n\n' + rst + '\n\n'
    elif e.tag == 'b' or e.tag == 'strong':
        if rst == '**':
            rst = ''
        else:
            rst += '**'
    elif e.tag == 'em' or e.tag == 'i':
        if rst == '*':
            rst = ''
        else:
            rst += '*'
    elif e.tag == 'a':
        rst += ' <%s>`__' % e.get('href')
    elif e.tag == 'img':
        text = e.get('alt') or e.get('src')
        rst += '[img %s]' % text
    elif e.tag in ('td', 'th'):
        rst += ' '
    else:
        if e.tag not in IGNORED_TAGS:
            raise UnsupportedHtmlTag(e.tag)
    if e.tail:
        rst += e.tail
    return rst
Beispiel #9
0
    def table2story(self, ar, column_names=None, header_level=None,
                    header_links=None, nosummary=False, stripped=True,
                    show_links=False, display_mode=None, **kwargs):
        """
        Render the given table request as reStructuredText to stdout.  See
        :meth:`ar.show <lino.core.request.BaseRequest.show>`.
        """
        if display_mode is None:
            display_mode = ar.actor.display_mode
        # if ar.actor.master is not None and not nosummary:
        if not nosummary:
            if display_mode == 'summary':
                s = to_rst(
                    ar.actor.get_table_summary(ar.master_instance, ar),
                    stripped=stripped)
                if stripped:
                    s = s.strip()
                yield s
                return

        fields, headers, widths = ar.get_field_info(column_names)

        # if str(ar.actor) == "working.WorkedHours":
        #     yield "20200306 fields {}".format(headers)

        sums = [fld.zero for fld in fields]
        rows = []
        recno = 0
        for row in ar.sliced_data_iterator:
            recno += 1
            if show_links:
                rows.append([
                    to_rst(x) for x in ar.row2html(recno, fields, row, sums)])
            else:
                rows.append([x for x in ar.row2text(fields, row, sums)])

        if header_level is not None:
            h = rstgen.header(header_level, ar.get_title())
            if stripped:
                h = h.strip()
            yield h
            # s = h + "\n" + s
            # s = tostring(E.h2(ar.get_title())) + s

        # if str(ar.actor) == "working.WorkedHours":
        #     yield "20200306 rows {}".format(rows)
        if len(rows) == 0:
            s = str(ar.no_data_text)
            if not stripped:
                s = "\n" + s + "\n"
            yield s
            return

        if not ar.actor.hide_sums:
            has_sum = False
            for i in sums:
                if i:
                    #~ print '20120914 zero?', repr(i)
                    has_sum = True
                    break
            if has_sum:
                rows.append([x for x in ar.sums2html(fields, sums)])

        t = RstTable(headers, **kwargs)
        yield t.to_rst(rows)
Beispiel #10
0
    def get_rst(self):
        #~ from actordoc import get_actor_description
        #~ from django.conf import settings
        #~ from djangosite.dbutils import set_language
        with translation.override(self.language):
            level, cls = resolve_name(self.content[0])
            if isinstance(cls, models.Field):
                fld = cls
                s = ''
                name = str(fld.model) + '.' + fld.name
                title = force_text(fld.verbose_name).strip()

                s += "\n.. index::\n   single: "
                s += str(_('%(field)s (field in %(model)s)') % dict(
                    field=title, model=model_ref(fld.model)))
                s += '\n\n'
                s += rstgen.header(level, _("%s (field)") % title)
                if len(self.content) > 1:
                    s += '\n'.join(self.content[1:])
                    s += '\n\n'
                return s

            if isinstance(cls, Plugin):
                s = ''
                title = str(cls.verbose_name)
                s += "\n.. index::\n   single: "
                s += str(_('%s (app)') % title)
                s += '\n\n.. _' + name + ':\n'
                s += '\n'
                s += rstgen.header(level, _("%s (app)") % title)
                return s

            if not isinstance(cls, type):
                raise Exception("%s is not an actor." % self.content[0])

            if issubclass(cls, models.Model):
                model = cls

                s = ''
                name = model_name(model).lower()
                title = force_text(model._meta.verbose_name)
                s += "\n.. index::\n   single: "
                s += str(_('%(model)s (model in %(app)s)') % dict(
                    model=title, app=model._meta.app_label))

                s += '\n\n'

                s += '\n\n.. _' + name + ':\n'

                s += '\n'
                s += rstgen.header(level, _("%s (model)") % title)

                s += '\n'
                s += '\n:Internal name: ``%s``\n' % full_model_name(cls)
                s += '\n:Implemented by: %s\n' % typeref(cls)
                s += '\n'

                if len(self.content) > 1:
                    s += '\n'.join(self.content[1:])
                    s += '\n\n'

                model_reports = [
                    r for r in kernel.master_tables if r.model is cls]
                model_reports += [r for r in kernel.slave_tables
                                  if r.model is cls]
                s += rstgen.boldheader(_("Views on %s") %
                                       cls._meta.verbose_name)
                s += actors_overview_ul(model_reports)

                s += rstgen.boldheader(_("Fields in %s") %
                                       cls._meta.verbose_name)
                s += fields_ul(cls._meta.fields)

                action_list = cls.get_default_table().get_actions()
                action_list = [
                    ba for ba in action_list
                    if not isinstance(ba.action, IGNORED_ACTIONS)]
                if action_list:
                    s += '\n'
                    s += rstgen.boldheader(_("Actions on %s") %
                                           cls._meta.verbose_name)
                    s += actions_ul(action_list)

                slave_tables = getattr(cls, '_lino_slaves', {}).values()
                if slave_tables:
                    s += rstgen.boldheader(_("Tables referring to %s") %
                                           cls._meta.verbose_name)
                    s += actors_overview_ul(slave_tables)

                return s

            if issubclass(cls, actors.Actor):

                title = force_text(cls.label or cls.title)
                indextext = _('%(actor)s (view in %(app)s)') % dict(
                    actor=title, app=cls.app_label)
                name = actor_name(cls)
                #~ if name == 'welfare.reception.waitingvisitors':
                    #~ self.debug = True
                #~ print(20130907, name)
                self.index_entries.append(('single', indextext, name, ''))
                #~ self.add_ref_target(name,name)

                s = ''
                s += '\n\n.. _%s:\n\n' % name
                s += rstgen.header(level, _("%s (view)") % title)
                s += '\n:Internal name: ``%s`` (%s)\n' % (cls, typeref(cls))

                if len(self.content) > 1:
                    s += '\n'.join(self.content[1:])
                    s += '\n\n'

                s += '\n\n'
                s += get_actor_description(cls)
                s += '\n\n'
                return s
            raise Exception("Cannot handle actor %r." % cls)