Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 7 additions & 34 deletions codegen/tuigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ def get_child_names(self) -> Iterable[str]:
def get_doc_string(self) -> str:
return self._menu.get_doc_string(True)

def is_extended_tui(self) -> bool:
return self._menu.is_extended_tui(True)

def is_container(self) -> bool:
return self._menu.is_container(True)


class _TUIMenu:
"""Class representing Fluent's TUI menu."""
Expand All @@ -109,8 +103,6 @@ def __init__(self, path: str):
del _XML_HELPSTRINGS[tui_path]
self.children = {}
self.is_command = False
self.is_extended_tui = False
self.is_container = False

def get_command_path(self, command: str) -> str:
return convert_path_to_grpc_path(self.path + [(command, None)])
Expand All @@ -136,61 +128,44 @@ def _populate_menu(self, menu: _TUIMenu):
menugen = _TUIMenuGenerator(menu.path, self._service)
if not menu.doc:
menu.doc = menugen.get_doc_string()
menu.is_extended_tui = menugen.is_extended_tui()
menu.is_container = menugen.is_container()
child_names = menugen.get_child_names()
if child_names:
for child_name in child_names:
if child_name:
child_menu = _TUIMenu(menu.path + [(child_name, None)])
menu.children[child_menu.name] = child_menu
self._populate_menu(child_menu)
elif not menu.is_extended_tui:
else:
menu.is_command = True

def _write_code_to_tui_file(self, code: str, indent: int = 0):
self.__writer.write(" " * _INDENT_STEP * indent + code)

def _write_menu_to_tui_file(self, menu: _TUIMenu, indent: int = 0):
self._write_code_to_tui_file("\n")
if menu.is_container:
self._write_code_to_tui_file(
f"class {menu.name}(metaclass=PyNamedObjectMeta):\n",
indent,
)
else:
self._write_code_to_tui_file(
f"class {menu.name}(metaclass=PyMenuMeta):\n", indent
)
self._write_code_to_tui_file(f"class {menu.name}(TUIMenu):\n", indent)
indent += 1
self._write_code_to_tui_file('"""\n', indent)
doc_lines = menu.doc.splitlines()
for line in doc_lines:
self._write_code_to_tui_file(f"{line}\n", indent)
self._write_code_to_tui_file('"""\n', indent)
if menu.is_extended_tui:
self._write_code_to_tui_file("is_extended_tui = True\n", indent)
self._write_code_to_tui_file(
"def __init__(self, path, service):\n", indent
)
indent += 1
self._write_code_to_tui_file("self.path = path\n", indent)
self._write_code_to_tui_file("self.service = service\n", indent)
for k, v in menu.children.items():
if v.is_command:
continue
elif v.is_container:
self._write_code_to_tui_file(
f"self.{k} = self.__class__.{k}"
f'(path + [("{v.tui_name}", None)], None, service)\n',
indent,
)
else:
if not v.is_command:
self._write_code_to_tui_file(
f"self.{k} = self.__class__.{k}"
f'(path + [("{v.tui_name}", None)], service)\n',
indent,
)
self._write_code_to_tui_file(
"super().__init__(path, service)\n", indent
)
indent -= 1

command_names = [
Expand Down Expand Up @@ -236,10 +211,8 @@ def generate(self) -> None:
"# This is an auto-generated file. DO NOT EDIT!\n"
"#\n"
"# pylint: disable=line-too-long\n\n"
"from ansys.fluent.core.meta "
"import PyMenuMeta, PyNamedObjectMeta\n"
"from ansys.fluent.core.services.datamodel_tui "
"import PyMenu\n\n\n"
"import PyMenu, TUIMenu\n\n\n"
)
self._main_menu.name = "main_menu"
self._write_menu_to_tui_file(self._main_menu)
Expand Down
Loading