2012-07-04 20:44:53 -03:00
|
|
|
import os, glob, re
|
|
|
|
|
|
|
|
from param import *
|
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
|
|
|
|
# Regular expressions for parsing the parameter metadata
|
|
|
|
|
|
|
|
prog_param = re.compile(r"@Param:\s*(\w+).*((?:\n\s*//\s*@(\w+): (.*))+)\s*G", re.MULTILINE)
|
|
|
|
|
|
|
|
prog_param_fields = re.compile(r"\s*//\s*@(\w+): (.*)")
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
prog_groups = re.compile(r"@Group:\s*(\w+).*((?:\n\s*//\s*@(\w+): (.*))+)\s*G", re.MULTILINE)
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
prog_group_param = re.compile(r"@Param:\s*(\w+).*((?:\n\s*//\s*@(\w+): (.*))+)\s*AP_", re.MULTILINE)
|
|
|
|
|
2012-07-05 01:27:58 -03:00
|
|
|
prog_values_field = re.compile(r"\s*(\w+:\w+)+,*")
|
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
def camelcase_escape(word):
|
|
|
|
if re.match(r"([A-Z][a-z]+[A-Z][a-z]*)", word.strip()):
|
|
|
|
return "!"+word
|
|
|
|
else:
|
|
|
|
return word
|
|
|
|
|
2012-07-05 00:55:55 -03:00
|
|
|
def wikichars_escape(text):
|
|
|
|
for c in "*,{,},[,],_,=,#,^,~,!,@,$,|,<,>,&,|,\,/".split(','):
|
|
|
|
text = re.sub("\\"+c, '`'+c+'`', text)
|
|
|
|
return text
|
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
def wiki_parameters(g, f):
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-04 21:58:09 -03:00
|
|
|
t = "\n\n== %s Parameters ==\n" % (camelcase_escape(g.name))
|
2012-07-04 20:44:53 -03:00
|
|
|
|
|
|
|
for param in g.params:
|
2012-07-05 03:01:52 -03:00
|
|
|
if hasattr(param, 'DisplayName'):
|
|
|
|
t += "\n\n=== %s (%s) ===" % (camelcase_escape(param.DisplayName),camelcase_escape(param.name))
|
|
|
|
else:
|
|
|
|
t += "\n\n=== %s ===" % camelcase_escape(param.name)
|
|
|
|
|
|
|
|
if hasattr(param, 'Description'):
|
|
|
|
t += "\n\n_%s_\n" % wikichars_escape(param.Description)
|
|
|
|
else:
|
|
|
|
t += "\n\n_TODO: description_\n"
|
|
|
|
|
2012-07-04 20:44:53 -03:00
|
|
|
for field in param.__dict__.keys():
|
|
|
|
if field not in ['name', 'DisplayName', 'Description', 'User'] and field in known_param_fields:
|
2012-07-05 01:27:58 -03:00
|
|
|
if field == 'Values' and prog_values_field.match(param.__dict__[field]):
|
|
|
|
t+= " * Values \n"
|
|
|
|
values = (param.__dict__[field]).split(',')
|
|
|
|
t+="|| *Value* || *Meaning* ||\n"
|
|
|
|
for value in values:
|
|
|
|
v = value.split(':')
|
2012-07-09 01:45:26 -03:00
|
|
|
t+="|| "+v[0]+" || "+camelcase_escape(v[1])+" ||\n"
|
2012-07-05 01:27:58 -03:00
|
|
|
else:
|
|
|
|
t += " * %s: %s\n" % (camelcase_escape(field), wikichars_escape(param.__dict__[field]))
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
#print t
|
2012-07-04 20:44:53 -03:00
|
|
|
f.write(t)
|
2012-07-04 21:42:38 -03:00
|
|
|
|
2012-07-04 20:44:53 -03:00
|
|
|
|
|
|
|
apm_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../')
|
|
|
|
vehicle_paths = glob.glob(apm_path + "*/Parameters.pde")
|
|
|
|
|
|
|
|
vehicles = []
|
|
|
|
libraries = []
|
|
|
|
|
|
|
|
for vehicle_path in vehicle_paths:
|
|
|
|
name = os.path.basename(os.path.dirname(vehicle_path))
|
|
|
|
path = os.path.normpath(os.path.dirname(vehicle_path))
|
|
|
|
vehicles.append(Vehicle(name, path))
|
|
|
|
#print 'Added %s at %s' % (name, path)
|
|
|
|
|
|
|
|
for vehicle in vehicles:
|
2012-07-04 21:42:38 -03:00
|
|
|
print "===\n\n\nProcessing %s" % vehicle.name
|
2012-07-04 20:44:53 -03:00
|
|
|
|
|
|
|
f = open(vehicle.path+'/Parameters.pde')
|
|
|
|
p_text = f.read()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
param_matches = prog_param.findall(p_text)
|
|
|
|
group_matches = prog_groups.findall(p_text)
|
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
print group_matches
|
2012-07-04 20:44:53 -03:00
|
|
|
for group_match in group_matches:
|
2012-07-04 21:42:38 -03:00
|
|
|
l = Library(group_match[0])
|
|
|
|
fields = prog_param_fields.findall(group_match[1])
|
|
|
|
for field in fields:
|
|
|
|
if field[0] in known_group_fields:
|
|
|
|
setattr(l, field[0], field[1])
|
|
|
|
else:
|
|
|
|
print "unknown parameter metadata field %s" % field[0]
|
2012-07-04 20:44:53 -03:00
|
|
|
if l not in libraries:
|
|
|
|
libraries.append(l)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for param_match in param_matches:
|
2012-07-09 01:45:26 -03:00
|
|
|
p = Parameter(vehicle.name+":"+param_match[0])
|
2012-07-04 21:42:38 -03:00
|
|
|
print p.name + ' '
|
2012-07-04 20:44:53 -03:00
|
|
|
field_text = param_match[1]
|
2012-07-04 21:42:38 -03:00
|
|
|
#print "\n\nParameter: %s\n" % p.name
|
2012-07-04 20:44:53 -03:00
|
|
|
fields = prog_param_fields.findall(field_text)
|
|
|
|
for field in fields:
|
|
|
|
if field[0] in known_param_fields:
|
|
|
|
# #print " %s: %s" % (field[0], field[1])
|
|
|
|
setattr(p, field[0], field[1])
|
|
|
|
else:
|
|
|
|
print "unknown parameter metadata field %s" % field[0]
|
|
|
|
|
|
|
|
vehicle.params.append(p)
|
|
|
|
|
|
|
|
##print vehicle.__dict__
|
2012-07-04 21:42:38 -03:00
|
|
|
print "Processed %u params" % len(vehicle.params)
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
print "Found %u documented libraries" % len(libraries)
|
2012-07-04 20:44:53 -03:00
|
|
|
|
|
|
|
for library in libraries:
|
2012-07-04 21:42:38 -03:00
|
|
|
print "===\n\n\nProcessing library %s" % library.name
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-05 03:01:52 -03:00
|
|
|
if hasattr(library, 'Path'):
|
|
|
|
paths = library.Path.split(',')
|
|
|
|
for path in paths:
|
|
|
|
path = path.strip()
|
2012-07-17 03:37:13 -03:00
|
|
|
print "\n Processing file %s" % path
|
|
|
|
libraryfname = os.path.normpath(os.path.join(apm_path + '/libraries/' + path))
|
|
|
|
if path and os.path.exists(libraryfname):
|
|
|
|
f = open(libraryfname)
|
|
|
|
p_text = f.read()
|
|
|
|
f.close()
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-05 03:01:52 -03:00
|
|
|
param_matches = prog_group_param.findall(p_text)
|
|
|
|
print "Found %u documented parameters" % len(param_matches)
|
|
|
|
for param_match in param_matches:
|
|
|
|
p = Parameter(library.name+param_match[0])
|
|
|
|
print p.name + ' '
|
|
|
|
field_text = param_match[1]
|
|
|
|
# #print "\n\nParameter: %s\n" % p.name
|
|
|
|
fields = prog_param_fields.findall(field_text)
|
|
|
|
for field in fields:
|
|
|
|
if field[0] in known_param_fields:
|
|
|
|
# #print " %s: %s" % (field[0], field[1])
|
|
|
|
setattr(p, field[0], field[1])
|
|
|
|
else:
|
|
|
|
print "unknown parameter metadata field %s" % field[0]
|
|
|
|
|
|
|
|
##print p.__dict__
|
|
|
|
library.params.append(p)
|
|
|
|
else:
|
|
|
|
print "Skipped: no Path found"
|
|
|
|
|
|
|
|
print "Processed %u documented parameters" % len(library.params)
|
2012-07-04 20:44:53 -03:00
|
|
|
|
2012-07-04 21:42:38 -03:00
|
|
|
wiki_fname = 'Parameters.wiki'
|
|
|
|
f = open(wiki_fname, mode='w')
|
|
|
|
preamble = '''#summary Dynamically generated list of documented parameters
|
2012-07-04 21:58:09 -03:00
|
|
|
= Table of Contents =
|
2012-07-04 21:42:38 -03:00
|
|
|
<wiki:toc max_depth="4" />
|
|
|
|
|
2012-07-04 21:58:09 -03:00
|
|
|
= Vehicles =
|
2012-07-04 21:42:38 -03:00
|
|
|
'''
|
|
|
|
f.write(preamble)
|
2012-07-04 20:44:53 -03:00
|
|
|
|
|
|
|
for vehicle in vehicles:
|
2012-07-04 21:42:38 -03:00
|
|
|
wiki_parameters(vehicle, f)
|
2012-07-04 21:58:09 -03:00
|
|
|
|
|
|
|
t = "\n\n=Libraries=\n\n"
|
|
|
|
f.write(t)
|
2012-07-04 20:44:53 -03:00
|
|
|
|
|
|
|
for library in libraries:
|
2012-07-04 21:58:09 -03:00
|
|
|
if library.params:
|
|
|
|
wiki_parameters(library, f)
|
2012-07-04 21:42:38 -03:00
|
|
|
|
|
|
|
f.close
|
2012-07-05 00:55:55 -03:00
|
|
|
|