Commit 43520385 authored by Robin Mueller's avatar Robin Mueller
Browse files

doc, refactoring continued

parent ee6e5a36
#!/usr/bin/python3
"""
@brief Core method called by entry point files to initiate the TMTC commander.
The commander is started by running the run_tmtc_client function.
The commander is started by first running initialize_tmtc_commander and then
running run_tmtc_commander
@details
@manual
@author R. Mueller
......@@ -25,42 +26,84 @@ except ImportError as error:
logger.warning("TMTC Runner: No user versioning file found!")
def assign_tmtc_commander_hooks(hook_base: TmTcHookBase):
from tmtc_core.core.globals_manager import update_global
from tmtc_core.core.definitions import CoreGlobalIds
if hook_base is None:
logger.error("Passed hook base object handle is invalid! Terminating..")
sys.exit(-1)
update_global(CoreGlobalIds.TMTC_HOOK, hook_base)
def initialize_tmtc_commander(hook_object: TmTcHookBase):
"""
This function needs to be called first before running the TMTC commander core. A hook
object handle needs to be passed to this function. The user should implement an own hook class
instance which in turn implemented TmTcHookBase. An instantiation of the hook object is then
passed to the core. The hook object ecncapsulates the control of the user over the TMTC
commander core.
Example for a simple main function content to use the command line mode:
hook_obj = MyCustomHookClass()
initialize_tmtc_core(hook_obj)
run_tmtc_client(False)
:param: hook_base: Instantiation of a custom hook object. The TMTC core will call the various
hook functions during program run-time.
"""
assign_tmtc_commander_hooks(hook_object=hook_object)
def run_tmtc_client(use_gui: bool, reduced_printout: bool = False):
def run_tmtc_commander(use_gui: bool, reduced_printout: bool = False):
"""
This is the primary function to run the TMTC commander. Users should call this function to
start the TMTC commander.
start the TMTC commander. Please note that assign_tmtc_commander_hooks needs to be called
before this function.
Example for a simple main function content to use the command line mode:
hook_obj = MyCustomHookClass()
initialize_tmtc_core(hook_obj)
run_tmtc_client(False)
:param use_gui: Specify whether the GUI is used or not
:param reduced_printout: It is possible to reduce the initial printout with this flag
:return:
"""
set_up_tmtc_commander(use_gui=use_gui, reduced_printout=reduced_printout)
if use_gui:
start_tmtc_commander_qt_gui()
else:
start_tmtc_commander_cli()
def assign_tmtc_commander_hooks(hook_object: TmTcHookBase):
from tmtc_core.core.globals_manager import update_global
from tmtc_core.core.definitions import CoreGlobalIds
if hook_object is None:
logger.error("Passed hook base object handle is invalid! Terminating..")
sys.exit(-1)
# Insert hook object handle into global dictionary so it can be used by the TMTC commander
update_global(CoreGlobalIds.TMTC_HOOK, hook_object)
def set_up_tmtc_commander(use_gui: bool, reduced_printout: bool):
from tmtc_core.core.globals_manager import get_global
from tmtc_core.core.definitions import CoreGlobalIds
from tmtc_core.core.hook_base import TmTcHookBase
from typing import cast
if not reduced_printout:
handle_init_printout(use_gui)
set_tmtc_logger()
logger.info("Starting TMTC Client..")
# First, we check whether a hook object was passed to the TMTC commander. This hook object
# encapsulates control of the commnader core so it is required for proper functioning
# of the commander core.
hook_obj_raw = get_global(CoreGlobalIds.TMTC_HOOK)
if hook_obj_raw is None:
logger.info("No valid hook object found. Please make sure to implement it, instantiate it "
"and pass it via the assign_tmtc_commander_hooks function!")
hook_obj = cast(TmTcHookBase, hook_obj_raw)
logger.info("Starting TMTC Commander..")
if use_gui:
from config.tmtcc_globals import add_globals_pre_args_parsing
add_globals_pre_args_parsing(True)
hook_obj.add_globals_pre_args_parsing(True)
else:
handle_cli_args_and_globals()
logger.info("Starting TMTC Handler..")
if use_gui:
start_tmtc_commander_qt_gui()
else:
start_tmtc_commander_cli()
def handle_init_printout(use_gui: bool):
print("-- Python TMTC Commander --")
......@@ -72,14 +115,18 @@ def handle_init_printout(use_gui: bool):
def handle_cli_args_and_globals():
from config.tmtcc_globals import add_globals_pre_args_parsing, add_globals_post_args_parsing
from typing import cast
from tmtc_core.core.globals_manager import get_global
hook_obj = cast(TmTcHookBase, get_global(CoreGlobalIds.TMTC_HOOK))
logger.info("Setting up pre-globals..")
add_globals_pre_args_parsing(False)
hook_obj.add_globals_pre_args_parsing(False)
logger.info("Parsing input arguments..")
args = parse_input_arguments()
logger.info("Setting up post-globals..")
add_globals_post_args_parsing(args)
hook_obj.add_globals_post_args_parsing(args)
def start_tmtc_commander_cli():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment