diff --git a/.gitignore b/.gitignore index 90b889c..000d161 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist/ build/ venv/ .venv/ +src/cotea_dev_run.py diff --git a/src/cotea/consts.py b/src/cotea/consts.py new file mode 100644 index 0000000..f557acc --- /dev/null +++ b/src/cotea/consts.py @@ -0,0 +1,3 @@ +COTEA_CONFIG_DIR="~" +COTEA_CONFIG_FILE_NAME="cotea_config.ini" +COTEA_CONFIG_SECTION_NAME="COTEA_CONF" \ No newline at end of file diff --git a/src/cotea/cotea_config.py b/src/cotea/cotea_config.py new file mode 100644 index 0000000..d173d73 --- /dev/null +++ b/src/cotea/cotea_config.py @@ -0,0 +1,39 @@ +import os +import configparser +import cotea.consts as consts + + +class cotea_config: + def __init__(self): + self.conf = {} + + # default values + self.conf["continue_on_fail"] = False + + + def load_from_file(self, config_path): + if os.path.isfile(config_path): + confparser_obj = configparser.ConfigParser() + confparser_obj.read(config_path) + section_name = consts.COTEA_CONFIG_SECTION_NAME + + if section_name in confparser_obj: + section = confparser_obj[section_name] + + for key in self.conf: + if key in section: + value = section[key] + + if value == "True": + value = True + elif value == "False": + value = False + + self.conf[key] = value + + + def get_conf_param(self, param_name): + if param_name in self.conf: + return self.conf[param_name] + + return None \ No newline at end of file diff --git a/src/cotea/debug_utils.py b/src/cotea/debug_utils.py index 1248faf..eab22dd 100644 --- a/src/cotea/debug_utils.py +++ b/src/cotea/debug_utils.py @@ -48,6 +48,9 @@ def pretty_print_task(task: Task): def interactive_discotech(failed_task: Task, r: runner): print("\nINTERACTIVE MODE") + + if r.continue_on_fail: + return while True: command = get_string_from_input("Enter command: ") diff --git a/src/cotea/runner.py b/src/cotea/runner.py index 72c0410..620740c 100644 --- a/src/cotea/runner.py +++ b/src/cotea/runner.py @@ -1,7 +1,8 @@ -import json import os +import json import threading +import cotea.consts as consts import cotea.utils as cotea_utils # during the imports ansible global objects are created @@ -31,6 +32,7 @@ from cotea.wrappers.iterator_add_task_wrapper import iterator_add_task_wrapper from cotea.progress_bar import ansible_progress_bar from cotea.ansible_execution_tree import AnsibleExecTree +from cotea.cotea_config import cotea_config import logging @@ -49,6 +51,16 @@ def __init__(self, pb_path, arg_maker, debug_mod=None, show_progress_bar=False, self.pb_path = pb_path self.arg_maker = arg_maker + + # cotea config init and fetch + self.cotea_conf = cotea_config() + + config_file_dir = os.path.expanduser(consts.COTEA_CONFIG_DIR) + config_file_name = consts.COTEA_CONFIG_FILE_NAME + config_file_path = os.path.join(config_file_dir, config_file_name) + + self.cotea_conf.load_from_file(config_file_path) + self.continue_on_fail = self.cotea_conf.get_conf_param("continue_on_fail") self.logger = logging.getLogger("RUNNER") diff --git a/src/cotea_config.ini b/src/cotea_config.ini new file mode 100644 index 0000000..54de24d --- /dev/null +++ b/src/cotea_config.ini @@ -0,0 +1,2 @@ +[COTEA_CONF] +continue_on_fail = False