Path: blob/master/Tools/autotest/param_metadata/htmlemit.py
9659 views
# flake8: noqa12"""3Emit docs in a form acceptable to the old Ardupilot wordpress docs site4"""56from param import known_param_fields, known_units7from emit import Emit8try:9from cgi import escape as cescape10except Exception:11from html import escape as cescape121314class HtmlEmit(Emit):1516def __init__(self, *args, **kwargs):17Emit.__init__(self, *args, **kwargs)18html_fname = 'Parameters.html'19self.f = open(html_fname, mode='w')20self.preamble = """<!-- Dynamically generated list of documented parameters21This page was generated using Tools/autotest/param_metadata/param_parse.py2223DO NOT EDIT24-->252627<h3 style="text-align: center">Complete Parameter List</h3>28<hr />2930<p>This is a complete list of the parameters which can be set via the MAVLink protocol in the EEPROM of your autopilot to control vehicle behaviour. This list is automatically generated from the latest ardupilot source code, and so may contain parameters which are not yet in the stable released versions of the code.</p>3132<!-- add auto-generated table of contents with "Table of Contents Plus" plugin -->33[toc exclude="Complete Parameter List"]3435"""36self.t = ''3738def escape(self, s):39s = s.replace(' ', '-')40s = s.replace(':', '-')41s = s.replace('(', '')42s = s.replace(')', '')43return s4445def close(self):46self.f.write(self.preamble)47self.f.write(self.t)48self.f.close()4950def start_libraries(self):51pass5253def emit(self, g):54tag = '%s Parameters' % g.reference55t = '\n\n<h1>%s</h1>\n' % tag5657for param in g.params:58if not self.should_emit_param(param):59continue60if not hasattr(param, 'DisplayName') or not hasattr(param, 'Description'):61continue62d = param.__dict__63tag = '%s (%s)' % (param.DisplayName, param.name)64t += '\n\n<h2>%s</h2>' % tag65if d.get('User', None) == 'Advanced':66t += '<em>Note: This parameter is for advanced users</em><br>'67t += "\n\n<p>%s</p>\n" % cescape(param.Description)68t += "<ul>\n"6970for field in param.__dict__.keys():71if not self.should_emit_field(param, field):72continue73if field not in ['name', 'DisplayName', 'Description', 'User', 'SortValues'] and field in known_param_fields:74if field == 'Values' and Emit.prog_values_field.match(param.__dict__[field]):75values = (param.__dict__[field]).split(',')76t += "<table><th>Value</th><th>Meaning</th>\n"77for value in values:78v = value.split(':')79if len(v) != 2:80raise ValueError("Bad value (%s)" % v)81t += "<tr><td>%s</td><td>%s</td></tr>\n" % (v[0], v[1])82t += "</table>\n"83elif field == 'Units':84abreviated_units = param.__dict__[field]85if abreviated_units != '':86units = known_units[abreviated_units] # use the known_units dictionary to convert the abbreviated unit into a full textual one87t += "<li>%s: %s</li>\n" % (field, cescape(units))88else:89t += "<li>%s: %s</li>\n" % (field, cescape(param.__dict__[field]))90t += "</ul>\n"91self.t += t929394