Atrinik Server 2.5
doc/types-extra.py
00001 # This script is used to generate documentation about field/flag
00002 # usage of different object types. Unlike the Gridarta types.xml
00003 # convert tool, types-extra should include everything, even
00004 # internally used, to make it easier for developers to see unused
00005 # fields/flags, and to understand what they do.
00006 
00007 fp = open("types-extra", "r")
00008 
00009 last_field = None
00010 last_type = None
00011 types = {}
00012 definitions = {}
00013 
00014 def preprocess(string):
00015     for definition in definitions:
00016         string = string.replace(definition, definitions[definition])
00017 
00018     return string
00019 
00020 for line in fp:
00021     if line[:1] == "#" and not last_type:
00022         if line[:8] == "#define ":
00023             definition_name = line[8:line.find(" ", 8)]
00024             definition_content = line[8 + len(definition_name):].strip()
00025             definitions[definition_name] = definition_content
00026 
00027         continue
00028 
00029     if line[:5] == "type ":
00030         last_type = line[5:].strip()
00031         types[last_type] = {
00032             "fields": [],
00033         }
00034     elif line == "end\n":
00035         last_field = None
00036         last_type = None
00037     elif line != "\n":
00038         if last_field and line[:6] == "field ":
00039             last_field = None
00040 
00041         if line[:6] == "field ":
00042             last_field = line[6:].strip()
00043             types[last_type]["fields"].append({
00044                 "field": last_field,
00045                 "explanation": "",
00046                 "field_help": None,
00047             })
00048         elif line[:11] == "field_help ":
00049             types[last_type]["fields"][len(types[last_type]["fields"]) - 1]["field_help"] = line[11:].strip()
00050         else:
00051             types[last_type]["fields"][len(types[last_type]["fields"]) - 1]["explanation"] += line
00052 
00053 fp.close()
00054 
00055 doc_fp = open("types-extra.dox", "w")
00056 
00057 for type in types:
00058     doc_fp.write("/**\n@def %s\n@ref ::obj \"Object\" fields and flags used by this type." % type)
00059     doc_fp.write("\n<table>\n<tr>\n<th>Field/Flag</th>\n<th>Explanation</th>\n</tr>")
00060 
00061     for i in range(0, len(types[type]["fields"])):
00062         doc_fp.write("\n<tr>\n<td>")
00063 
00064         if types[type]["fields"][i]["field_help"]:
00065             doc_fp.write("<span title=\"%s\" style=\"border-bottom: 1px dashed #000;\">" % preprocess(types[type]["fields"][i]["field_help"]))
00066 
00067         if types[type]["fields"][i]["field"][:5] == "FLAG_":
00068             doc_fp.write("@ref ")
00069 
00070         doc_fp.write(types[type]["fields"][i]["field"])
00071 
00072         if types[type]["fields"][i]["field_help"]:
00073             doc_fp.write("</span>")
00074 
00075         doc_fp.write("</td>\n<td>%s</td>\n</tr>" % types[type]["fields"][i]["explanation"].strip())
00076 
00077     doc_fp.write("\n</table>\n*/\n\n")
00078 
00079 doc_fp.close()