#!/usr/bin/env python from __future__ import print_function import argparse import copy import os import re import sys import emit_html import emit_rst import emit_xml import emit_md import enum_parse from enum_parse import EnumDocco topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../') topdir = os.path.realpath(topdir) re_loggermessage = re.compile(r"@LoggerMessage\s*:\s*([\w,]+)", re.MULTILINE) re_commentline = re.compile(r"\s*//") re_description = re.compile(r"\s*//\s*@Description\s*:\s*(.*)") re_url = re.compile(r"\s*//\s*@URL\s*:\s*(.*)") re_field = re.compile(r"\s*//\s*@Field\s*:\s*(\w+):\s*(.*)") re_fieldbits = re.compile(r"\s*//\s*@FieldBits\s*:\s*(\w+):\s*(.*)") re_fieldbitmaskenum = re.compile(r"\s*//\s*@FieldBitmaskEnum\s*:\s*(\w+):\s*(.*)") re_fieldvalueenum = re.compile(r"\s*//\s*@FieldValueEnum\s*:\s*(\w+):\s*(.*)") re_vehicles = re.compile(r"\s*//\s*@Vehicles\s*:\s*(.*)") # TODO: validate URLS actually return 200 # TODO: augment with other information from log definitions; type and units... class LoggerDocco(object): vehicle_map = { "Rover": "Rover", "Sub": "ArduSub", "Copter": "ArduCopter", "Plane": "ArduPlane", "Tracker": "AntennaTracker", "Blimp": "Blimp", } def __init__(self, vehicle): self.vehicle = vehicle self.doccos = [] self.emitters = [ emit_html.HTMLEmitter(), emit_rst.RSTEmitter(), emit_xml.XMLEmitter(), emit_md.MDEmitter(), ] class Docco(object): def __init__(self, name): self.name = name self.url = None self.description = None self.fields = {} self.fields_order = [] self.vehicles = None self.bits_enums = [] def set_description(self, desc): self.description = desc def set_url(self, url): self.url = url def ensure_field(self, field): if field not in self.fields: self.fields[field] = {} self.fields_order.append(field) def set_field_description(self, field, description): if field in self.fields: raise ValueError("Already have field %s in %s" % (field, self.name)) self.ensure_field(field) self.fields[field]["description"] = description def set_field_bits(self, field, bits): bits = bits.split(",") count = 0 entries = [] for bit in bits: entries.append(EnumDocco.EnumEntry(bit, 1<