From 10a9bc8cb6414eff3e7f50e3b05bde3ae8ff9cef Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 24 Mar 2023 01:41:12 +0330 Subject: fixed the main function so poetry build actually works correctly --- pyproject.toml | 2 +- virttop/virttop.py | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1f4a7b6..d36c74f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "virttop" -version = "0.2.0" +version = "0.2.1" description = "A top like utility for libvirt" authors = ["terminaldweller "] license = "GPL-3.0" diff --git a/virttop/virttop.py b/virttop/virttop.py index 99f2b61..47bf53f 100755 --- a/virttop/virttop.py +++ b/virttop/virttop.py @@ -363,8 +363,9 @@ def read_config(config_path) -> ConfigData: return config_data -def curses_init() -> None: +def curses_init(): """Initialize ncurses.""" + stdscr = curses.initscr() curses.start_color() curses.use_default_colors() curses.curs_set(False) @@ -372,6 +373,7 @@ def curses_init() -> None: curses.cbreak() stdscr.keypad(True) curses.halfdelay(4) + return stdscr def init_color_pairs(config_data: ConfigData) -> None: @@ -400,14 +402,14 @@ def get_visible_rows(max_rows: int, sel: int) -> typing.Tuple[int, int]: return win_min_row, win_max_row -async def main() -> None: - """entrypoint""" +async def main_loop() -> None: + """Main TUI loop.""" sel: int = 0 current_row: int = 0 current_visi: int = 0 vm_name_ordered_list: typing.List[str] = [] - curses_init() + stdscr = curses_init() signal.signal(signal.SIGINT, sig_handler_sigint) argparser = Argparser() config_data = read_config(argparser.args.config) @@ -422,7 +424,6 @@ async def main() -> None: request_cred, None, ] - # conn = libvirt.openAuth(hv_host, auth, libvirt.VIR_CONNECT_RO) conn = libvirt.openAuth(hv_host, auth, 0) hosts = conn.listAllDomains() if len(hosts) > 0: @@ -537,12 +538,16 @@ async def main() -> None: stdscr.refresh() -# FIXME- the finally wipes the screen, effectively rendering the help option useless -if __name__ == "__main__": - stdscr = curses.initscr() +def main() -> None: + """Entry point.""" try: - asyncio.run(main()) + asyncio.run(main_loop()) except Exception as e: print(e) finally: do_cleanup() + + +# FIXME- the finally wipes the screen, effectively rendering the help option useless +if __name__ == "__main__": + main() -- cgit v1.2.3