From 3cd3f936e09dcb5ecca658961aea0c44e251c6cf Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Mon, 15 Apr 2024 07:16:53 +0000 Subject: [PATCH 1/3] fix status calc on non phase output --- embark/embark/logreader.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/embark/embark/logreader.py b/embark/embark/logreader.py index 34a46f0e..6a65d844 100644 --- a/embark/embark/logreader.py +++ b/embark/embark/logreader.py @@ -132,6 +132,9 @@ def phase_identify(status_message): elif re.search(pattern=re.escape(failed_pattern), string=status_message["phase"]): max_module = -2 phase_nmbr = EMBA_PHASE_CNT + else: + logger.info("Undefined pattern in logreader %s ", status_message["phase"]) + logger.info("Not updating status percentage") return max_module, phase_nmbr # update our dict whenever a new module is being processed @@ -146,12 +149,14 @@ def update_status(self, stream_item_list): self.module_cnt = self.module_cnt % max_module # make sure it's in range percentage = phase_nmbr * (100 / EMBA_PHASE_CNT) + ((100 / EMBA_PHASE_CNT) / max_module) * self.module_cnt # increments: F=6.25, S=0.65, L=3.57, P=1.25 else: - logger.debug("Undefined state in logreader %s ", self.status_msg) + logger.error("Undefined state in logreader %s ", self.status_msg) + percentage = self.status_msg["percentage"] logger.debug("Status is %d, in phase %d, with modules %d", percentage, phase_nmbr, max_module) # set attributes of current message self.status_msg["module"] = stream_item_list[0] + # ignore all Q-modules for percentage calc if not re.match(".*Q[0-9][0-9]", stream_item_list[0]): self.status_msg["percentage"] = percentage From 927862d41655f4621a52be4fbf12ba3f013f2343 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 12 Jul 2024 07:07:31 +0000 Subject: [PATCH 2/3] fix module counts --- embark/embark/helper.py | 20 +++++++++++++++++++- embark/embark/logreader.py | 14 +++++++++----- embark/embark/settings/deploy.py | 27 +++------------------------ embark/embark/settings/dev.py | 26 +++----------------------- 4 files changed, 34 insertions(+), 53 deletions(-) diff --git a/embark/embark/helper.py b/embark/embark/helper.py index 872e05ed..b5515209 100644 --- a/embark/embark/helper.py +++ b/embark/embark/helper.py @@ -63,6 +63,24 @@ def cleanup_charfield(charfield) -> str: return charfield +def count_emba_modules(emba_dir_path): + s_module_cnt, p_module_cnt, q_module_cnt, l_module_cnt, f_module_cnt, d_module_cnt = 0, 0, 0, 0, 0, 0 + for mod_file_ in os.listdir(f"{emba_dir_path}/modules"): + if mod_file_.startswith('S'): + s_module_cnt += 1 + elif mod_file_.startswith('P'): + p_module_cnt += 1 + elif mod_file_.startswith('F'): + f_module_cnt += 1 + elif mod_file_.startswith('L'): + l_module_cnt += 1 + elif mod_file_.startswith('Q'): + q_module_cnt += 1 + elif mod_file_.startswith('D'): + d_module_cnt += 1 + return s_module_cnt, p_module_cnt, q_module_cnt, l_module_cnt, f_module_cnt, d_module_cnt + + def get_version_strings(): # gets us the currently installed version if Path(settings.EMBA_ROOT + "/external/onlinechecker").exists(): @@ -100,4 +118,4 @@ def get_version_strings(): TEST_STRING = 'Linux / v2.6.33.2' print(cleanup_charfield(TEST_STRING)) - print(get_version_strings()) + print(count_emba_modules(emba_dir_path="/home/cylox/embark/emba")) diff --git a/embark/embark/logreader.py b/embark/embark/logreader.py index 6a65d844..83f2ffe2 100644 --- a/embark/embark/logreader.py +++ b/embark/embark/logreader.py @@ -112,8 +112,8 @@ def phase_identify(status_message): failed_pattern = "EMBA failed in docker mode!" # calculate percentage - max_module = -1 - phase_nmbr = -1 + max_module = -2 + phase_nmbr = -2 if re.search(pattern=re.escape(pre_checker_phase_pattern), string=status_message["phase"]): max_module = EMBA_P_MOD_CNT phase_nmbr = EMBA_P_PHASE @@ -130,7 +130,7 @@ def phase_identify(status_message): max_module = 0 phase_nmbr = EMBA_PHASE_CNT elif re.search(pattern=re.escape(failed_pattern), string=status_message["phase"]): - max_module = -2 + max_module = -1 phase_nmbr = EMBA_PHASE_CNT else: logger.info("Undefined pattern in logreader %s ", status_message["phase"]) @@ -147,10 +147,14 @@ def update_status(self, stream_item_list): elif max_module > 0: self.module_cnt += 1 self.module_cnt = self.module_cnt % max_module # make sure it's in range - percentage = phase_nmbr * (100 / EMBA_PHASE_CNT) + ((100 / EMBA_PHASE_CNT) / max_module) * self.module_cnt # increments: F=6.25, S=0.65, L=3.57, P=1.25 + percentage = phase_nmbr * (100 / EMBA_PHASE_CNT) + ((100 / EMBA_PHASE_CNT) / max_module) * self.module_cnt + elif max_module == -1: + percentage = 100 + self.finish = True + logger.error("EMBA failed with %s ", self.status_msg) else: logger.error("Undefined state in logreader %s ", self.status_msg) - percentage = self.status_msg["percentage"] + percentage = self.status_msg["percentage"] # stays the same logger.debug("Status is %d, in phase %d, with modules %d", percentage, phase_nmbr, max_module) diff --git a/embark/embark/settings/deploy.py b/embark/embark/settings/deploy.py index f2021c54..b250efa5 100644 --- a/embark/embark/settings/deploy.py +++ b/embark/embark/settings/deploy.py @@ -12,7 +12,7 @@ from dotenv import load_dotenv -from embark.helper import get_version_strings +from embark.helper import count_emba_modules, get_version_strings # load .env file load_dotenv() @@ -307,30 +307,9 @@ SECURE_HSTS_SECONDS = 0 SECURE_SSL_REDIRECT = False - -def count_emba_modules(emba_dir_path): - s_module_cnt, p_module_cnt, q_module_cnt, l_module_cnt, f_module_cnt = 0, 0, 0, 0, 0 - for mod_file_ in os.listdir(f"{emba_dir_path}/modules"): - if mod_file_.startswith('S'): - s_module_cnt += 1 - elif mod_file_.startswith('P'): - p_module_cnt += 1 - elif mod_file_.startswith('F'): - f_module_cnt += 1 - elif mod_file_.startswith('L'): - l_module_cnt += 1 - elif mod_file_.startswith('Q'): - q_module_cnt += 1 - return s_module_cnt, p_module_cnt, f_module_cnt, l_module_cnt, q_module_cnt - - try: - EMBA_S_MOD_CNT, EMBA_P_MOD_CNT, EMBA_F_MOD_CNT, EMBA_L_MOD_CNT, EMBA_Q_MOD_CNT = count_emba_modules(EMBA_ROOT) + EMBA_S_MOD_CNT, EMBA_P_MOD_CNT, EMBA_Q_MOD_CNT, EMBA_L_MOD_CNT, EMBA_F_MOD_CNT, EMBA_D_MOD_CNT = count_emba_modules(EMBA_ROOT) except FileNotFoundError as file_error: - print("[Warning] Installation is missing the EMBA submodule") - EMBA_S_MOD_CNT = 44 - EMBA_P_MOD_CNT = 18 - EMBA_F_MOD_CNT = 4 - EMBA_L_MOD_CNT = 8 + EMBA_S_MOD_CNT, EMBA_P_MOD_CNT, EMBA_Q_MOD_CNT, EMBA_L_MOD_CNT, EMBA_F_MOD_CNT, EMBA_D_MOD_CNT = 46, 20, 1, 10, 6, 3 VERSION = get_version_strings() diff --git a/embark/embark/settings/dev.py b/embark/embark/settings/dev.py index a9fd260b..3ccdad54 100644 --- a/embark/embark/settings/dev.py +++ b/embark/embark/settings/dev.py @@ -8,7 +8,7 @@ from dotenv import load_dotenv -from embark.helper import get_version_strings +from embark.helper import count_emba_modules, get_version_strings # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent.parent @@ -271,29 +271,9 @@ } TEMP_DIR = Path("/tmp/") - -def count_emba_modules(emba_dir_path): - s_module_cnt, p_module_cnt, q_module_cnt, l_module_cnt, f_module_cnt = 0, 0, 0, 0, 0 - for mod_file_ in os.listdir(f"{emba_dir_path}/modules"): - if mod_file_.startswith('S'): - s_module_cnt += 1 - elif mod_file_.startswith('P'): - p_module_cnt += 1 - elif mod_file_.startswith('F'): - f_module_cnt += 1 - elif mod_file_.startswith('L'): - l_module_cnt += 1 - elif mod_file_.startswith('Q'): - q_module_cnt += 1 - return s_module_cnt, p_module_cnt, f_module_cnt, l_module_cnt, q_module_cnt - - try: - EMBA_S_MOD_CNT, EMBA_P_MOD_CNT, EMBA_F_MOD_CNT, EMBA_L_MOD_CNT, EMBA_Q_MOD_CNT = count_emba_modules(EMBA_ROOT) + EMBA_S_MOD_CNT, EMBA_P_MOD_CNT, EMBA_Q_MOD_CNT, EMBA_L_MOD_CNT, EMBA_F_MOD_CNT, EMBA_D_MOD_CNT = count_emba_modules(EMBA_ROOT) except FileNotFoundError as file_error: - EMBA_S_MOD_CNT = 44 - EMBA_P_MOD_CNT = 18 - EMBA_F_MOD_CNT = 4 - EMBA_L_MOD_CNT = 8 + EMBA_S_MOD_CNT, EMBA_P_MOD_CNT, EMBA_Q_MOD_CNT, EMBA_L_MOD_CNT, EMBA_F_MOD_CNT, EMBA_D_MOD_CNT = 46, 20, 1, 10, 6, 3 VERSION = get_version_strings() From 960a5e4cb09eaca7ee345864b3bf1e4bc495c4d9 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 12 Jul 2024 08:42:39 +0000 Subject: [PATCH 3/3] fix VERSION input --- embark/embark/helper.py | 7 +++++-- run-server.sh | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/embark/embark/helper.py b/embark/embark/helper.py index b5515209..4df2e23a 100644 --- a/embark/embark/helper.py +++ b/embark/embark/helper.py @@ -105,8 +105,11 @@ def get_version_strings(): else: emba_version = "" - if Path("./VERSION.txt").exists(): - with open(Path("./VERSION.txt"), 'r', encoding='UTF-8') as embark_version_file: + if Path(f"{settings.BASE_DIR}/VERSION.txt").exists(): + with open(Path(f"{settings.BASE_DIR}/VERSION.txt"), 'r', encoding='UTF-8') as embark_version_file: + embark_version = embark_version_file.read().splitlines()[0] + elif Path(f"{settings.BASE_DIR.parent}/VERSION.txt").exists(): + with open(Path(f"{settings.BASE_DIR.parent}/VERSION.txt"), 'r', encoding='UTF-8') as embark_version_file: embark_version = embark_version_file.read().splitlines()[0] else: embark_version = "" diff --git a/run-server.sh b/run-server.sh index 60633e51..b338532c 100755 --- a/run-server.sh +++ b/run-server.sh @@ -187,8 +187,10 @@ copy_file "${PWD}"/cert/embark.local.key /var/www/conf/cert copy_file "${PWD}"/cert/embark-ws.local.key /var/www/conf/cert copy_file "${PWD}"/cert/embark-ws.local.crt /var/www/conf/cert -# cp .env + +# cp .env and version copy_file ./.env /var/www/embark/embark/settings/ +copy_file ./VERSION.txt /var/www/embark/ # !DIRECTORY-CHANGE! cd /var/www/embark/ || exit 1