Skip to content

Commit

Permalink
opmode: T7084: normalize formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbaturin committed Jan 23, 2025
1 parent 7ab82e1 commit 313a3d1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions python/vyos/xml_ref/generate_op_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -74,7 +75,7 @@ def translate_op_script(s: str) -> str:
return s


def insert_node(n: Element, l: list[PathData], path = None) -> None:
def insert_node(n: Element, l: list[PathData], path=None) -> None:
# pylint: disable=too-many-locals,too-many-branches
prop: OptElement = n.find('properties')
children: OptElement = n.find('children')
Expand All @@ -97,12 +98,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:
Expand Down Expand Up @@ -134,7 +135,7 @@ 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)
Expand All @@ -143,14 +144,18 @@ def insert_node(n: Element, l: list[PathData], path = None) -> None:
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())

Expand All @@ -167,5 +172,6 @@ def main():
with open(op_ref_cache, 'w') as f:
f.write(f'op_reference = {str(l)}')


if __name__ == '__main__':
main()

0 comments on commit 313a3d1

Please sign in to comment.