2019-10-18 00:33:17 -03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2020-10-07 17:14:20 -03:00
|
|
|
from lxml import etree
|
2019-10-18 00:33:17 -03:00
|
|
|
import emitter
|
|
|
|
|
|
|
|
class XMLEmitter(emitter.Emitter):
|
|
|
|
def preface(self):
|
|
|
|
return """<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!-- Dynamically generated list of documented logfile messages (generated by parse.py) -->
|
|
|
|
"""
|
2020-10-07 17:14:20 -03:00
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
def postface(self):
|
2020-10-07 17:14:20 -03:00
|
|
|
return
|
2019-10-18 00:33:17 -03:00
|
|
|
|
|
|
|
def start(self):
|
2020-10-07 17:14:20 -03:00
|
|
|
self.logname = "LogMessages.xml"
|
2019-10-18 00:33:17 -03:00
|
|
|
self.fh = open("LogMessages.xml", mode='w')
|
|
|
|
print(self.preface(), file=self.fh)
|
2020-10-07 17:14:20 -03:00
|
|
|
self.loggermessagefile = etree.Element('loggermessagefile')
|
2019-10-18 00:33:17 -03:00
|
|
|
|
|
|
|
def emit(self, doccos):
|
|
|
|
self.start()
|
|
|
|
for docco in doccos:
|
2020-10-07 17:14:20 -03:00
|
|
|
xml_logformat = etree.SubElement(self.loggermessagefile, 'logformat', name=docco.name)
|
2019-10-18 00:33:17 -03:00
|
|
|
if docco.url is not None:
|
2020-10-07 17:14:20 -03:00
|
|
|
xml_url = etree.SubElement(xml_logformat, 'url')
|
|
|
|
xml_url.text = docco.url
|
2019-10-18 00:33:17 -03:00
|
|
|
if docco.description is not None:
|
2020-10-07 17:14:20 -03:00
|
|
|
xml_description = etree.SubElement(xml_logformat, 'description')
|
|
|
|
xml_description.text = docco.description
|
|
|
|
|
|
|
|
xml_fields = etree.SubElement(xml_logformat, 'fields')
|
2020-03-20 03:05:57 -03:00
|
|
|
for f in docco.fields_order:
|
2020-10-07 17:14:20 -03:00
|
|
|
xml_field = etree.SubElement(xml_fields, 'field', name=f)
|
2019-10-18 00:33:17 -03:00
|
|
|
if "description" in docco.fields[f]:
|
2020-10-07 17:14:20 -03:00
|
|
|
xml_description2 = etree.SubElement(xml_field, 'description')
|
|
|
|
xml_description2.text = docco.fields[f]["description"]
|
2019-10-18 00:33:17 -03:00
|
|
|
if "bits" in docco.fields[f]:
|
2020-10-07 17:14:20 -03:00
|
|
|
xml_bits = etree.SubElement(xml_field, 'bits')
|
|
|
|
xml_bits.text = docco.fields[f]["bits"]
|
|
|
|
if xml_fields.text is None and not len(xml_fields):
|
|
|
|
xml_fields.text = '\n' # add </param> on next line in case of empty element.
|
2019-10-18 00:33:17 -03:00
|
|
|
self.stop()
|
|
|
|
|
|
|
|
def stop(self):
|
2021-04-01 22:53:42 -03:00
|
|
|
# etree.indent(self.loggermessagefile) # not available on thor, Ubuntu 16.04
|
2020-10-07 17:14:20 -03:00
|
|
|
pretty_xml = etree.tostring(self.loggermessagefile, pretty_print=True, encoding='unicode')
|
|
|
|
self.fh.write(pretty_xml)
|
2019-10-18 00:33:17 -03:00
|
|
|
self.fh.close()
|