Example #1
0
    def show_memo_commands(self, doctestfmt=False):
        rst = ""
        mp = settings.SITE.kernel.memo_parser
        items = []
        for cmd, func in sorted(mp.commands.items()):
            doc = unindent(func.__doc__ or '')
            if doc:
                # doc = doc.splitlines()[0]
                items.append("[{0} ...] : {1}".format(cmd, doc))

        # rst += "\n**Commands**"
        # rst += rstgen.boldheader("Commands")
        rst += rstgen.ul(items)

        if False:
            items = []
            for model, func in sorted(mp.renderers.items()):
                doc = unindent(func.__doc__ or '')
                if doc:
                    items.append("[{0} ...] : {1}".format(model, doc))
            if len(items):
                rst += "\n**Renderers**"
                rst += rstgen.ul(items)

        return rst
Example #2
0
 def screenshot(self, name, caption, before='', after=''):
     filename = self.screenshot_root.child(name)
     print("Writing screenshot {0} ...".format(filename))
     if not self.driver.get_screenshot_as_file(filename):
         print("Failed to create {0}".format(filename))
         sys.exit(-1)
     before = unindent(before)
     after = unindent(after)
     self.screenshots.append((name, caption, before, after))
Example #3
0
 def screenshot(self, name, caption, before='', after=''):
     filename = self.screenshot_root.child(name)
     print("Writing screenshot {0} ...".format(filename))
     if not self.driver.get_screenshot_as_file(filename):
         print("Failed to create {0}".format(filename))
         sys.exit(-1)
     before = unindent(before)
     after = unindent(after)
     self.screenshots.append((name, caption, before, after))
Example #4
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())

        index.write_file(content.encode('utf-8'))
Example #5
0
def show_fields(model, fieldnames=None):
    """Print an overview description of the specified fields of the
    specified model.

    """
    cells = []
    cols = ["Internal name", "Verbose name", "Help text"]
    if isinstance(model, BoundAction):
        get_field = model.action.parameters.get
        if fieldnames is None:
            fieldnames = model.action.params_layout
    elif isinstance(model, Action):
        get_field = model.parameters.get
        if fieldnames is None:
            fieldnames = model.params_layout.main
    elif issubclass(model, Model):
        get_field = model._meta.get_field
        if fieldnames is None:
            fieldnames = [f.name for f in model._meta.get_fields()]
    elif issubclass(model, AbstractTable):
        get_field = model.parameters.get
        if fieldnames is None:
            fieldnames = model.params_layout.main
    if isinstance(fieldnames, six.string_types):
        fieldnames = fieldnames.split()
    for n in fieldnames:
        fld = get_field(n)
        if fld is not None and hasattr(fld, 'verbose_name'):
            cells.append([n, fld.verbose_name, unindent(fld.help_text or '')])

    print(table(cols, cells).strip())
Example #6
0
def show_fields(model, fieldnames=None):
    """Print an overview description of the specified fields of the
    specified model.

    """
    cells = []
    cols = ["Internal name", "Verbose name", "Help text"]
    if isinstance(model, BoundAction):
        get_field = model.action.parameters.get
        if fieldnames is None:
            fieldnames = model.action.params_layout
    elif isinstance(model, Action):
        get_field = model.parameters.get
        if fieldnames is None:
            fieldnames = model.params_layout.main
    elif issubclass(model, Model):
        get_field = model._meta.get_field
    elif issubclass(model, AbstractTable):
        get_field = model.parameters.get
        if fieldnames is None:
            fieldnames = model.params_layout.main
    if isinstance(fieldnames, six.string_types):
        fieldnames = fieldnames.split()
    for n in fieldnames:
        fld = get_field(n)
        if fld is not None:
            cells.append([n, fld.verbose_name, unindent(fld.help_text)])

    print(table(cols, cells).strip())
Example #7
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())

        index.write_file(content.encode('utf-8'))
Example #8
0
def show_fields(model, fieldnames=None, columns=False, all=None):
    """
    Print an overview description of the specified fields of the
    specified model. 

    If model is an action or table, print the parameter fields of that
    action or table.

    If model is a table and you want the columns instead of the
    parameter fields, then specify `columns=True`.

    By default this shows only fields which have a help text.  If you
    specify `all=True`, then also fields that have no help text will
    be shown.
    """
    cells = []
    cols = ["Internal name", "Verbose name", "Help text"]
    if all is None:
        all = fieldnames is not None
    if isinstance(model, BoundAction):
        get_field = model.action.parameters.get
        if fieldnames is None:
            fieldnames = model.action.params_layout
    elif isinstance(model, Action):
        get_field = model.parameters.get
        if fieldnames is None:
            fieldnames = model.params_layout.main
    elif issubclass(model, Model):
        get_field = model._meta.get_field
        # get_field = model.get_data_elem
        if fieldnames is None:
            fieldnames = [f.name for f in model._meta.get_fields()]
    elif issubclass(model, AbstractTable):
        if columns:
            get_field = model.get_data_elem
            if fieldnames is None:
                fieldnames = model.column_names
                # get_handle().list_layout.main.columns
        else:
            get_field = model.parameters.get
            if fieldnames is None:
                fieldnames = model.params_layout.main
    if isinstance(fieldnames, six.string_types):
        fieldnames = fieldnames.split()
    for n in fieldnames:
        fld = get_field(n)
        if fld is not None and hasattr(fld, 'verbose_name'):
            ht = fld.help_text or ''
            if ht or all:
                cells.append([n,
                              fld.verbose_name,
                              unindent(ht)])

    print(table(cols, cells).strip())
Example #9
0
 def doit():
     cells = []
     cols = ["Action name", "Verbose name", "Help text",
             "Target state", "Required states"]  # , "Required roles"]
     for a in actions:
         ht = a.help_text or ''
         if ht or all:
             # required_roles = ' '.join(
             #     [str(r) for r in a.required_roles])
             cells.append(
                 [a.action_name, a.label, unindent(ht),
                  a.target_state, a.required_states or '',
                  # required_roles
                 ])
     print(table(cols, cells).strip())
Example #10
0
def get_actor_description(self):
    """
    `self` is the actor
    """
    body = "\n\n"
    if self.help_text:
        body += unindent(force_text(self.help_text).strip()) + "\n\n"

    #~ ll = self.get_handle().list_layout
    #~ if ll is not None:
        #~ body += fields_table([ e.field for e in ll.main.columns] )

    #~ model_reports = [r for r in kernel.master_tables if r.model is self.model]
    #~ if model_reports:
        #~ body += '\n\nMaster tables: %s\n\n' % rptlist(model_reports)
    #~ if getattr(model,'_lino_slaves',None):
        #~ body += '\n\nSlave tables: %s\n\n' % rptlist(model._lino_slaves.values())

    return body
Example #11
0
def get_actor_description(self):
    """
    `self` is the actor
    """
    body = "\n\n"
    if self.help_text:
        body += unindent(force_unicode(self.help_text).strip()) + "\n\n"

    #~ ll = self.get_handle().list_layout
    #~ if ll is not None:
    #~ body += fields_table([ e.field for e in ll.main.columns] )

    #~ model_reports = [r for r in dbtables.master_reports if r.model is self.model]
    #~ if model_reports:
    #~ body += '\n\nMaster tables: %s\n\n' % rptlist(model_reports)
    #~ if getattr(model,'_lino_slaves',None):
    #~ body += '\n\nSlave tables: %s\n\n' % rptlist(model._lino_slaves.values())

    return body
Example #12
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)
Example #13
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)
Example #14
0
    def attach(self, cls):
        super(UserType, self).attach(cls)
        self.kw.setdefault('hidden_languages', cls.hidden_languages)
        if 'remark' not in self.kw:
            s = self.role.__doc__
            if s is not None:
                self.kw['remark'] = unindent(s)

        for k, vf in cls.virtual_fields.items():
            if vf.has_default():
                self.kw.setdefault(k, vf.get_default())
            elif vf.return_type.blank:
                self.kw.setdefault(k, None)

        for k, v in self.kw.items():
            setattr(self, k, v)

        if self.hidden_languages is not None:
            self.hidden_languages = set(
                settings.SITE.resolve_languages(self.hidden_languages))

        del self.kw