From 411657474134eeb4bbf2da76b01d0c3eb7db9e69 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Fri, 18 Oct 2024 10:36:06 +0300 Subject: [PATCH 1/2] Fixed the issue where the progress bar would get stuck when it overflowed --- pleskdistup/common/src/action.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pleskdistup/common/src/action.py b/pleskdistup/common/src/action.py index fed5a43..2a64473 100644 --- a/pleskdistup/common/src/action.py +++ b/pleskdistup/common/src/action.py @@ -515,7 +515,7 @@ def display(self) -> None: start_time = int(time.time()) passed_time = 0 - while passed_time < self.total_time and not self.flow.is_finished(): + while passed_time <= self.total_time and not self.flow.is_finished(): percent = int((passed_time) / self.total_time * 100) description = self.get_action_description() @@ -544,6 +544,6 @@ def display(self) -> None: time.sleep(1) passed_time = int(time.time()) - start_time - if passed_time > self.total_time: + if passed_time >= self.total_time: self.write("\r\033[91m[" + "X" * 25 + self.get_action_description() + "X" * 25 + "] exceed\033[0m") self.write(self.time_exceeded_message) From 112dd32cede8b6fee4310bf4ab50c2b4aba13f3c Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Fri, 18 Oct 2024 10:09:40 +0300 Subject: [PATCH 2/2] Handle progress bar exceed in monitoring and status subcommands --- pleskdistup/main.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pleskdistup/main.py b/pleskdistup/main.py index 249b64d..679ec26 100644 --- a/pleskdistup/main.py +++ b/pleskdistup/main.py @@ -72,9 +72,15 @@ def show_status(status_file_path: PathType) -> None: print("Conversion process is not running.") return - print("Conversion process in progress:") status = files.get_last_lines(status_file_path, 1) - print(status[0]) + # This means progress bar exceeded and we should write last 5 lines of the status file + if status[0].startswith("****"): + status = files.get_last_lines(status_file_path, 5) + else: + print("Conversion process in progress:") + + for line in status: + print(line, end='') def monitor_status(status_file_path: PathType) -> None: @@ -83,13 +89,26 @@ def monitor_status(status_file_path: PathType) -> None: return with open(status_file_path, "r") as status: - status.readlines() + old_lines = status.readlines() + if old_lines[-1].startswith("****"): + for lines in old_lines[-5:]: + print(lines, end='') + return + while os.path.exists(status_file_path): line = status.readline().rstrip() + # If progress bar exceeds it will switch to the red color. In this case we could stop the monitoring process. + if line.startswith("\033[91m["): + print(line) + break + sys.stdout.write("\r" + line) sys.stdout.flush() time.sleep(1) + for line in status.readlines(): + print(line, end='') + def show_fail_motd(logfile_path: PathType, util_name: str) -> None: motd.add_finish_ssh_login_message(f"""