diff options
author | John Estabrook <jestabro@vyos.io> | 2021-02-01 13:30:57 -0600 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2021-02-01 13:30:57 -0600 |
commit | a89503b4e0d014847f6e5c663a1befb39ffc3aa1 (patch) | |
tree | 30fe87ebb2550c063461265c97a28f543b35346b | |
parent | f701d667e60c19dab328a8fce9b722ab46c0d73a (diff) | |
download | vyos-documentation-a89503b4e0d014847f6e5c663a1befb39ffc3aa1.tar.gz vyos-documentation-a89503b4e0d014847f6e5c663a1befb39ffc3aa1.zip |
process overriding of defaultValue elements in XML interface definitions
-rw-r--r-- | docs/_ext/testcoverage.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/docs/_ext/testcoverage.py b/docs/_ext/testcoverage.py index 70714d6b..39028912 100644 --- a/docs/_ext/testcoverage.py +++ b/docs/_ext/testcoverage.py @@ -281,13 +281,15 @@ def get_working_commands(): while line: string = string + include_file(line.strip(), entry['input_dir']) line = fp.readline() - + try: xml = ET.parse(BytesIO(bytes(string, 'utf-8'))) except Exception as e: print("Failed to load interface definition file {0}".format(f)) print(e) sys.exit(1) + + override_defaults(xml) try: relaxng_xml = ET.parse(entry['schema_file']) @@ -343,9 +345,38 @@ def get_working_commands(): cmd['cmd'] = " ".join(cmd['name']) return result +def override_defaults(xml): + root = xml.getroot() + defv = {} + + xpath_str = f'//defaultValue' + xp = xml.xpath(xpath_str) + + for element in xp: + ap = element.xpath('ancestor::*[@name]') + defv.setdefault((ap[-1].get("name"), str(ap[:-1])), []).append(element) + + for k, v in defv.items(): + if len(v) > 1: + override_element(v) + +def override_element(l: list): + if len(l) < 2: + return + + # assemble list of leafNodes of overriding defaultValues, for later removal + parents = [] + for el in l[1:]: + parents.append(el.getparent()) + + # replace element with final override + l[0].getparent().replace(l[0], l[-1]) + # remove all but overridden element + for el in parents: + el.getparent().remove(el) if __name__ == "__main__": res = get_working_commands() print(json.dumps(res)) - #print(res['cfgcmd'][0])
\ No newline at end of file + #print(res['cfgcmd'][0]) |