Skip to content

Commit

Permalink
Merge pull request #89 from plesk/stuck-progress-bar
Browse files Browse the repository at this point in the history
Stuck progress bar
  • Loading branch information
SandakovMM authored Oct 18, 2024
2 parents 4e03cf3 + 112dd32 commit e641e17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pleskdistup/common/src/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
25 changes: 22 additions & 3 deletions pleskdistup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"""
Expand Down

0 comments on commit e641e17

Please sign in to comment.