From 4de662e2af73c61388d1536fdbe5874ca40ae5e0 Mon Sep 17 00:00:00 2001 From: "Andreas M. Antonopoulos" Date: Wed, 4 Jul 2012 23:01:52 -0700 Subject: [PATCH] param_parser - better tolerance for missing parameters --- Tools/autotest/param_metadata/param_parse.py | 71 +++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/Tools/autotest/param_metadata/param_parse.py b/Tools/autotest/param_metadata/param_parse.py index 50148bef6a..099fce8187 100644 --- a/Tools/autotest/param_metadata/param_parse.py +++ b/Tools/autotest/param_metadata/param_parse.py @@ -26,15 +26,21 @@ def wikichars_escape(text): text = re.sub("\\"+c, '`'+c+'`', text) return text - - def wiki_parameters(g, f): t = "\n\n== %s Parameters ==\n" % (camelcase_escape(g.name)) for param in g.params: - t += "\n\n=== %s (%s) ===" % (camelcase_escape(param.DisplayName),camelcase_escape(param.name)) - t += "\n\n_%s_\n" % wikichars_escape(param.Description) + 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" + for field in param.__dict__.keys(): if field not in ['name', 'DisplayName', 'Description', 'User'] and field in known_param_fields: if field == 'Values' and prog_values_field.match(param.__dict__[field]): @@ -51,8 +57,6 @@ def wiki_parameters(g, f): f.write(t) - - apm_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../') vehicle_paths = glob.glob(apm_path + "*/Parameters.pde") @@ -114,33 +118,36 @@ print "Found %u documented libraries" % len(libraries) for library in libraries: print "===\n\n\nProcessing library %s" % library.name - paths = library.Path.split(',') - for path in paths: - path = path.strip() - #print "\n Processing file %s" % path - f = open(os.path.normpath(os.path.join(apm_path + '/libraries/' + path))) - p_text = f.read() - f.close() - - 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) + if hasattr(library, 'Path'): + paths = library.Path.split(',') + for path in paths: + path = path.strip() + #print "\n Processing file %s" % path + f = open(os.path.normpath(os.path.join(apm_path + '/libraries/' + path))) + p_text = f.read() + f.close() - #print "Processed %u documented parameters" % len(library.params) + 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) wiki_fname = 'Parameters.wiki' f = open(wiki_fname, mode='w')