#!/usr/bin/env python from xml.sax.saxutils import escape, quoteattr from emit import Emit from param import known_param_fields, known_units from lxml import etree # Emit ArduPilot documentation in an machine readable XML format for Mission Planner class XmlEmitMP(Emit): def __init__(self, *args, **kwargs): Emit.__init__(self, *args, **kwargs) self.mp_fname = 'ParameterMetaData.xml' self.f = open(self.mp_fname, mode='w') self.preamble = '''\n''' self.f.write(self.preamble) self.f.write('\n') self.gname = None self.skip_name = False def close(self): self.f.write(' \n' % self.gname) self.f.write('''\n''') self.f.close() # sort and reformat XML parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(self.mp_fname, parser) root = tree.getroot() vehicle = tree.find(self.gname) sort_xml_node(vehicle) sorted_unicode = etree.tostring(root, pretty_print=True, encoding='unicode') f = open(self.mp_fname, mode='w') f.write(self.preamble) f.write(sorted_unicode) f.close() def emit_comment(self, s): self.f.write("") def start_libraries(self): self.skip_name = True def emit(self, g): t = "" if not self.skip_name: self.gname = g.reference if self.gname == "ArduCopter": self.gname = "ArduCopter2" if self.gname == "APMrover2" or self.gname == "Rover": self.gname = "ArduRover" t = ' <%s>\n' % self.gname for param in g.params: # Begin our parameter node # Get param name and and remove key name = param.name.split(':')[-1] t += ' <%s>\n' % name if hasattr(param, 'DisplayName'): t += ' %s\n' % param.DisplayName if hasattr(param, 'Description'): t += ' %s\n' % escape(param.Description) # i.e. parameter docs if hasattr(param, 'User'): t += ' %s\n' % param.User # i.e. Standard or Advanced # not used yet # if hasattr(param, 'Calibration'): # t += ' %s