diff options
Diffstat (limited to 'docs/_ext/testcoverage.py')
-rw-r--r-- | docs/_ext/testcoverage.py | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/docs/_ext/testcoverage.py b/docs/_ext/testcoverage.py index 3d1461a9..efe6e01d 100644 --- a/docs/_ext/testcoverage.py +++ b/docs/_ext/testcoverage.py @@ -1,14 +1,13 @@ ''' generate json with all commands from xml for vyos documentation coverage - ''' - import sys import os import json import re import logging +import datetime from io import BytesIO from lxml import etree as ET @@ -33,11 +32,32 @@ input_data = [ } ] +vyos_commands_dir = "_include/coverage" + node_data = { 'cfgcmd': {}, 'opcmd': {}, } + +def get_vyos_commands(): + return_data = None + for (dirpath, dirnames, filenames) in os.walk(vyos_commands_dir): + for file in filenames: + with open(f"{vyos_commands_dir}/{file}") as f: + data = json.load(f) + + if not return_data: + return_data = data + + # find latestes export + if datetime.datetime.fromisoformat(return_data['date']) < datetime.datetime.fromisoformat(data['date']): + return_data = data + + return return_data + + + def get_properties(p): props = {} props['valueless'] = False @@ -155,12 +175,18 @@ def get_properties(p): def process_node(n, f): + props_elem = n.find("properties") children = n.find("children") command = n.find("command") children_nodes = [] owner = n.get("owner") node_type = n.tag + defaultvalue = n.find("defaultValue") + + if defaultvalue is not None: + defaultvalue = defaultvalue.text + name = n.get("name") props = get_properties(props_elem) @@ -198,7 +224,9 @@ def process_node(n, f): 'children': children_nodes, 'props': props, 'command': test_command, - 'filename': f + 'filename': f, + 'defaultvalue': defaultvalue + } return node @@ -212,9 +240,11 @@ def create_commands(data, parent_list=[], level=0): 'tag_help': [], 'level': level, 'no_childs': False, - 'filename': None + 'filename': None, + 'defaultvalue': None, } command['filename'] = data['filename'] + command['defaultvalue'] = data['defaultvalue'] command['name'].extend(parent_list) command['name'].append(data['name']) @@ -328,6 +358,7 @@ def get_working_commands(): 'children': [], 'command': node_data[kind][entry]['command'], 'filename': node_data[kind][entry]['filename'], + 'defaultvalue': node_data[kind][entry]['defaultvalue'] } config_tree_new[kind][node_0]['children'].extend(node_data[kind][entry]['children']) @@ -378,6 +409,4 @@ def override_element(l: list): el.getparent().remove(el) if __name__ == "__main__": - res = get_working_commands() - print(json.dumps(res)) - #print(res['cfgcmd'][0]) + get_vyos_commands() |