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