Пример #1
0
    def emit(self, g):
        tag = '%s Parameters' % g.reference
        t = '\n\n<h1>%s</h1>\n' % tag

        for param in g.params:
            if not hasattr(param, 'DisplayName') or not hasattr(param, 'Description'):
                continue
            d = param.__dict__
            tag = '%s (%s)' % (param.DisplayName, param.name)
            t += '\n\n<h2>%s</h2>' % tag
            if d.get('User', None) == 'Advanced':
                t += '<em>Note: This parameter is for advanced users</em><br>'
            t += "\n\n<p>%s</p>\n" % cescape(param.Description)
            t += "<ul>\n"

            for field in param.__dict__.keys():
                if field not in ['name', 'DisplayName', 'Description', 'User'] and field in known_param_fields:
                    if field == 'Values' and Emit.prog_values_field.match(param.__dict__[field]):
                        values = (param.__dict__[field]).split(',')
                        t += "<table><th>Value</th><th>Meaning</th>\n"
                        for value in values:
                            v = value.split(':')
                            if len(v) != 2:
                                raise ValueError("Bad value (%s)" % v)
                            t += "<tr><td>%s</td><td>%s</td></tr>\n" % (v[0], v[1])
                        t += "</table>\n"
                    elif field == 'Units':
                        abreviated_units = param.__dict__[field]
                        if abreviated_units != '':
                            units = known_units[abreviated_units]   # use the known_units dictionary to convert the abreviated unit into a full textual one
                            t += "<li>%s: %s</li>\n" % (field, cescape(units))
                    else:
                        t += "<li>%s: %s</li>\n" % (field, cescape(param.__dict__[field]))
            t += "</ul>\n"
        self.t += t
Пример #2
0
    def emit(self, g):
        tag = '%s Parameters' % self.escape(g.name)
        reference = "parameters_" + g.name

        field_table_info = {
            "Values": {
                "headings": ['Value', 'Meaning'],
            },
            "Bitmask": {
                "headings": ['Bit', 'Meaning'],
            },
        }

        ret = """

.. _{reference}:

{tag}
{underline}
""".format(tag=tag, underline="-" * len(tag), reference=reference)

        for param in g.params:
            if not hasattr(param, 'DisplayName') or not hasattr(
                    param, 'Description'):
                continue
            d = param.__dict__

            # Get param path if defined (i.e. is duplicate parameter)
            param_path = getattr(param, 'path', '')

            name = param.name.split(':')[-1]

            tag_param_path = ' (%s)' % param_path if param_path else ''
            tag = '%s%s: %s' % (
                self.escape(name),
                self.escape(tag_param_path),
                self.escape(param.DisplayName),
            )

            tag = tag.strip()
            reference = param.name
            # remove e.g. "ArduPlane:" from start of parameter name:
            reference = reference.split(":")[-1]
            if param_path:
                reference += '__' + param_path

            ret += """

.. _{reference}:

{tag}
{tag_underline}
""".format(tag=tag, tag_underline='~' * len(tag), reference=reference)

            if d.get('User', None) == 'Advanced':
                ret += '\n| *Note: This parameter is for advanced users*'
            ret += "\n\n%s\n" % self.escape(param.Description)

            headings = []
            row = []
            for field in sorted(param.__dict__.keys()):
                if field not in ['name', 'DisplayName', 'Description', 'User'
                                 ] and field in known_param_fields:
                    headings.append(field)
                    if field in field_table_info and Emit.prog_values_field.match(
                            param.__dict__[field]):
                        row.append(
                            self.render_prog_values_field(
                                field_table_info[field], param, field))
                    elif field == "Range":
                        (param_min,
                         param_max) = (param.__dict__[field]).split(' ')
                        row.append("%s - %s" % (
                            param_min,
                            param_max,
                        ))
                    elif field == 'Units':
                        abreviated_units = param.__dict__[field]
                        if abreviated_units != '':
                            # use the known_units dictionary to
                            # convert the abreviated unit into a full
                            # textual one:
                            units = known_units[abreviated_units]
                            row.append(cescape(units))
                    else:
                        row.append(cescape(param.__dict__[field]))
            if len(row):
                ret += "\n\n" + self.tablify([row], headings=headings) + "\n\n"
        self.t += ret + "\n"