diff --git a/python/vyos/xml_ref/generate_op_cache.py b/python/vyos/xml_ref/generate_op_cache.py index 9efcd14be1..dc8f6bca40 100755 --- a/python/vyos/xml_ref/generate_op_cache.py +++ b/python/vyos/xml_ref/generate_op_cache.py @@ -36,6 +36,7 @@ from op_definition import NodeData from op_definition import PathData + xml_op_cache_json = 'xml_op_cache.json' xml_op_tmp = join('/tmp', xml_op_cache_json) op_ref_cache = abspath(join(_here, 'op_cache.py')) @@ -43,13 +44,11 @@ OptElement: TypeAlias = Optional[Element] DEBUG = False - def translate_exec(s: str) -> str: s = s.replace('${vyos_op_scripts_dir}', directories['op_mode']) s = s.replace('${vyos_libexec_dir}', directories['base']) return s - def translate_position(s: str, pos: list[str]) -> str: pos = pos.copy() pat: re.Pattern = re.compile(r'(?:\")?\${?([0-9]+)}?(?:\")?') @@ -61,19 +60,16 @@ def translate_position(s: str, pos: list[str]) -> str: return t - def translate_command(s: str, pos: list[str]) -> str: s = translate_exec(s) s = translate_position(s, pos) return s - def translate_op_script(s: str) -> str: s = s.replace('${vyos_completion_dir}', directories['completion_dir']) s = s.replace('${vyos_op_scripts_dir}', directories['op_mode']) return s - def insert_node(n: Element, l: list[PathData], path = None) -> None: # pylint: disable=too-many-locals,too-many-branches prop: OptElement = n.find('properties') @@ -97,12 +93,12 @@ def insert_node(n: Element, l: list[PathData], path = None) -> None: comp_help = {} if prop is not None: - che = prop.findall("completionHelp") + che = prop.findall('completionHelp') for c in che: - comp_list_els = c.findall("list") - comp_path_els = c.findall("path") - comp_script_els = c.findall("script") + comp_list_els = c.findall('list') + comp_path_els = c.findall('path') + comp_script_els = c.findall('script') comp_lists = [] for i in comp_list_els: @@ -134,23 +130,24 @@ def insert_node(n: Element, l: list[PathData], path = None) -> None: l.append(cur_node_dict) if children is not None: - inner_nodes = children.iterfind("*") + inner_nodes = children.iterfind('*') for inner_n in inner_nodes: inner_path = path[:] insert_node(inner_n, cur_node_dict['children'], inner_path) - def parse_file(file_path, l): tree = ET.parse(file_path) root = tree.getroot() - for n in root.iterfind("*"): + for n in root.iterfind('*'): insert_node(n, l) - def main(): parser = ArgumentParser(description='generate dict from xml defintions') - parser.add_argument('--xml-dir', type=str, required=True, - help='transcluded xml op-mode-definition file') + parser.add_argument( + '--xml-dir', + type=str, required=True, + help='transcluded xml op-mode-definition file' + ) args = vars(parser.parse_args()) @@ -167,5 +164,6 @@ def main(): with open(op_ref_cache, 'w') as f: f.write(f'op_reference = {str(l)}') + if __name__ == '__main__': main()