#!/usr/bin/env python from xml.sax.saxutils import escape, quoteattr from emit import Emit from param import known_param_fields, known_units INDENT2 = " " INDENT4 = " " INDENT6 = " " INDENT8 = " " INDENT10 = " " # Emit APM documentation in an machine readable XML format class XmlEmit(Emit): def __init__(self): Emit.__init__(self) self.wiki_fname = 'apm.pdef.xml' self.f = open(self.wiki_fname, mode='w') self.preamble = ''' ''' self.f.write(self.preamble) self.f.write(''' \n''') def close(self): self.f.write(INDENT2 + '\n') self.f.write('''\n''') self.f.close() def emit_comment(self, s): self.f.write("") def start_libraries(self): self.f.write(INDENT2 + '\n') self.f.write(INDENT2 + '\n') def emit(self, g): t = INDENT4 + '''\n''' % quoteattr(g.name) # i.e. ArduPlane for param in g.params: # Begin our parameter node if hasattr(param, 'DisplayName'): t += INDENT6 + '\n" values = (param.__dict__[field]).split(',') for value in values: v = value.split(':') if len(v) != 2: raise ValueError("Bad value (%s)" % v) t += INDENT10 + '''%s\n''' % (quoteattr(v[0]), escape(v[1])) # i.e. numeric value, string label t += INDENT8 + "\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 += INDENT8 + '''%s\n''' % (quoteattr(field), escape(abreviated_units)) # i.e. A/s t += INDENT8 + '''%s\n''' % (quoteattr('UnitText'), escape(units)) # i.e. ampere per second else: t += INDENT8 + '''%s\n''' % (quoteattr(field), escape(param.__dict__[field])) # i.e. Range: 0 10 t += INDENT6 + '''\n''' t += INDENT4 + '''\n''' # print t self.f.write(t)