|
6 | 6 | import threading
|
7 | 7 | import sys
|
8 | 8 | import multiprocessing
|
9 |
| -import queue |
10 | 9 | from pathlib import Path
|
11 | 10 | from functools import partial
|
12 | 11 |
|
@@ -88,35 +87,39 @@ def brand_ascii():
|
88 | 87 |
|
89 | 88 | output_lock = threading.Lock()
|
90 | 89 |
|
91 |
| -# Define a thread-safe queue to store processed files |
92 |
| -processed_queue = queue.Queue() |
| 90 | +def print_remaining_time(processed_files, total_files, start_time): |
| 91 | + elapsed_time = time.time() - start_time |
| 92 | + if processed_files.value > 0: |
| 93 | + avg_processing_time_per_file = elapsed_time / processed_files.value |
| 94 | + remaining_files = total_files - processed_files.value |
| 95 | + remaining_time = remaining_files * avg_processing_time_per_file |
| 96 | + if remaining_time < 1: |
| 97 | + print(f" | Remaining time: {Color.GREEN}{int(remaining_time * 1000)} ms{Color.RESET}", end='') |
| 98 | + elif remaining_time < 60: |
| 99 | + print(f" | Remaining time: {Color.YELLOW}{int(remaining_time)} s{Color.RESET}", end='') |
| 100 | + elif remaining_time < 3600: |
| 101 | + print(f" | Remaining time: {Color.ORANGE}{int(remaining_time / 60)} min(s){Color.RESET}\r", end='') |
| 102 | + else: |
| 103 | + print(f" | Remaining time: {Color.RED}{int(remaining_time / 3600)} hour(s){Color.RESET}", end='') |
93 | 104 |
|
94 | 105 |
|
95 | 106 | def print_progress_bar_with_time(processed_files, total_files, start_time):
|
96 | 107 | with output_lock:
|
97 | 108 | progress = min(processed_files.value / total_files, 1.0) # Ensure progress doesn't exceed 100%
|
98 | 109 | bar_length = 50
|
99 | 110 | filled_length = int(bar_length * progress)
|
100 |
| - bar = '=' * filled_length + '-' * (bar_length - filled_length) |
| 111 | + gap_length = 1 # Adjust gap length as needed |
| 112 | + if filled_length < bar_length: # If progress is less than 100% |
| 113 | + gap_bar = f'{Color.GREY} {Color.RESET}' * gap_length |
| 114 | + else: |
| 115 | + gap_bar = '' |
| 116 | + filled_bar = f'{Color.GREEN}━{Color.RESET}' * filled_length |
| 117 | + unfilled_bar = f'{Color.GREY}━{Color.RESET}' * (bar_length - filled_length - gap_length) |
| 118 | + bar = filled_bar + gap_bar + unfilled_bar |
101 | 119 | percentage = progress * 100
|
102 | 120 | sys.stdout.write('\rProcessing: [{:<50}] {:.2f}%'.format(bar, percentage))
|
103 | 121 | sys.stdout.flush()
|
104 |
| - |
105 |
| - # Calculate remaining time |
106 |
| - if progress > 0: |
107 |
| - elapsed_time = time.time() - start_time |
108 |
| - remaining_files = total_files - processed_files.value |
109 |
| - if processed_files.value > 0: |
110 |
| - avg_time_per_file = elapsed_time / processed_files.value |
111 |
| - remaining_time = remaining_files * avg_time_per_file |
112 |
| - if remaining_time < 60: |
113 |
| - remaining_time_str = f"{int(remaining_time)} s" |
114 |
| - elif remaining_time < 3600: |
115 |
| - remaining_time_str = f"{int(remaining_time / 60)} min" |
116 |
| - else: |
117 |
| - remaining_time_str = f"{int(remaining_time / 3600)} h" |
118 |
| - sys.stdout.write(f' | Remaining time: {remaining_time_str}') |
119 |
| - sys.stdout.flush() |
| 122 | + print_remaining_time(processed_files, total_files, start_time) |
120 | 123 |
|
121 | 124 |
|
122 | 125 | def count_total_files(directory):
|
@@ -298,14 +301,14 @@ def process_mode(directory_or_file, config):
|
298 | 301 |
|
299 | 302 | def confirm_upgrade():
|
300 | 303 | while True:
|
301 |
| - user_input = input("Are you sure you want to upgrade pydvpl? (y, yes / n, no): ").strip().lower() |
| 304 | + user_input = input("Are you sure you want to upgrade pydvpl? 'yes' (y) or 'no' (n): ").strip().lower() |
302 | 305 | if user_input in ['yes', 'y']:
|
303 | 306 | return True
|
304 | 307 | elif user_input in ['no', 'n']:
|
305 | 308 | return False
|
306 | 309 | else:
|
307 | 310 | print("Invalid input. Please enter 'yes' (y) or 'no' (n).")
|
308 |
| - sys.exit(1) # Exit the script if invalid input is provided |
| 311 | + sys.exit(1) |
309 | 312 |
|
310 | 313 |
|
311 | 314 |
|
@@ -433,8 +436,10 @@ def print_elapsed_time(elapsed_time):
|
433 | 436 | print(f"\nProcessing took {Color.GREEN}{int(elapsed_time * 1000)} ms{Color.RESET}\n")
|
434 | 437 | elif elapsed_time < 60:
|
435 | 438 | print(f"\nProcessing took {Color.YELLOW}{int(elapsed_time)} s{Color.RESET}\n")
|
| 439 | + elif elapsed_time < 3600: |
| 440 | + print(f"\nProcessing took {Color.ORANGE}{int(elapsed_time / 60)} min(s){Color.RESET}\n") |
436 | 441 | else:
|
437 |
| - print(f"\nProcessing took {Color.RED}{int(elapsed_time / 60)} min{Color.RESET}\n") |
| 442 | + print(f"\nProcessing took {Color.RED}{int(elapsed_time / 3600)} hour(s){Color.RESET}\n") |
438 | 443 |
|
439 | 444 |
|
440 | 445 | def cli():
|
|
0 commit comments