diff options
author | Robert Göhler <github@ghlr.de> | 2021-02-03 15:43:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 15:43:22 +0100 |
commit | d8b526e8a1035e87fec66cc74384f70db5726d1f (patch) | |
tree | 71c0535a106af81e63fdb66633af02536fbd7bb7 /docs | |
parent | dbbe56b142f37a0705d2a836b77dbc418be11915 (diff) | |
parent | a89503b4e0d014847f6e5c663a1befb39ffc3aa1 (diff) | |
download | vyos-documentation-d8b526e8a1035e87fec66cc74384f70db5726d1f.tar.gz vyos-documentation-d8b526e8a1035e87fec66cc74384f70db5726d1f.zip |
Merge pull request #440 from jestabro/override-defaults
process overriding of defaultValue elements in XML interface definitions
Diffstat (limited to 'docs')
-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]) |