Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/autotest/param_metadata/htmlemit.py
9659 views
1
# flake8: noqa
2
3
"""
4
Emit docs in a form acceptable to the old Ardupilot wordpress docs site
5
"""
6
7
from param import known_param_fields, known_units
8
from emit import Emit
9
try:
10
from cgi import escape as cescape
11
except Exception:
12
from html import escape as cescape
13
14
15
class HtmlEmit(Emit):
16
17
def __init__(self, *args, **kwargs):
18
Emit.__init__(self, *args, **kwargs)
19
html_fname = 'Parameters.html'
20
self.f = open(html_fname, mode='w')
21
self.preamble = """<!-- Dynamically generated list of documented parameters
22
This page was generated using Tools/autotest/param_metadata/param_parse.py
23
24
DO NOT EDIT
25
-->
26
27
28
<h3 style="text-align: center">Complete Parameter List</h3>
29
<hr />
30
31
<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>
32
33
<!-- add auto-generated table of contents with "Table of Contents Plus" plugin -->
34
[toc exclude="Complete Parameter List"]
35
36
"""
37
self.t = ''
38
39
def escape(self, s):
40
s = s.replace(' ', '-')
41
s = s.replace(':', '-')
42
s = s.replace('(', '')
43
s = s.replace(')', '')
44
return s
45
46
def close(self):
47
self.f.write(self.preamble)
48
self.f.write(self.t)
49
self.f.close()
50
51
def start_libraries(self):
52
pass
53
54
def emit(self, g):
55
tag = '%s Parameters' % g.reference
56
t = '\n\n<h1>%s</h1>\n' % tag
57
58
for param in g.params:
59
if not self.should_emit_param(param):
60
continue
61
if not hasattr(param, 'DisplayName') or not hasattr(param, 'Description'):
62
continue
63
d = param.__dict__
64
tag = '%s (%s)' % (param.DisplayName, param.name)
65
t += '\n\n<h2>%s</h2>' % tag
66
if d.get('User', None) == 'Advanced':
67
t += '<em>Note: This parameter is for advanced users</em><br>'
68
t += "\n\n<p>%s</p>\n" % cescape(param.Description)
69
t += "<ul>\n"
70
71
for field in param.__dict__.keys():
72
if not self.should_emit_field(param, field):
73
continue
74
if field not in ['name', 'DisplayName', 'Description', 'User', 'SortValues'] and field in known_param_fields:
75
if field == 'Values' and Emit.prog_values_field.match(param.__dict__[field]):
76
values = (param.__dict__[field]).split(',')
77
t += "<table><th>Value</th><th>Meaning</th>\n"
78
for value in values:
79
v = value.split(':')
80
if len(v) != 2:
81
raise ValueError("Bad value (%s)" % v)
82
t += "<tr><td>%s</td><td>%s</td></tr>\n" % (v[0], v[1])
83
t += "</table>\n"
84
elif field == 'Units':
85
abreviated_units = param.__dict__[field]
86
if abreviated_units != '':
87
units = known_units[abreviated_units] # use the known_units dictionary to convert the abbreviated unit into a full textual one
88
t += "<li>%s: %s</li>\n" % (field, cescape(units))
89
else:
90
t += "<li>%s: %s</li>\n" % (field, cescape(param.__dict__[field]))
91
t += "</ul>\n"
92
self.t += t
93
94