Skip to content

Commit

Permalink
Cotea config was added
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBMSTU committed May 20, 2024
1 parent a131ca6 commit 972597c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
build/
venv/
.venv/
src/cotea_dev_run.py
3 changes: 3 additions & 0 deletions src/cotea/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
COTEA_CONFIG_DIR="~"
COTEA_CONFIG_FILE_NAME="cotea_config.ini"
COTEA_CONFIG_SECTION_NAME="COTEA_CONF"
39 changes: 39 additions & 0 deletions src/cotea/cotea_config.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/cotea/debug_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down
14 changes: 13 additions & 1 deletion src/cotea/runner.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions src/cotea_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[COTEA_CONF]
continue_on_fail = False

0 comments on commit 972597c

Please sign in to comment.