diff --git a/ramalama/common.py b/ramalama/common.py index 7ecafe9e..a5732858 100644 --- a/ramalama/common.py +++ b/ramalama/common.py @@ -290,6 +290,7 @@ def get_gpu(): if igpu_num: os.environ["INTEL_VISIBLE_DEVICES"] = str(igpu_num) + def get_env_vars(): prefixes = ("ASAHI_", "CUDA_", "HIP_", "HSA_", "INTEL_") env_vars = {k: v for k, v in os.environ.items() if k.startswith(prefixes)} diff --git a/ramalama/http_client.py b/ramalama/http_client.py index d923b8de..c1496108 100644 --- a/ramalama/http_client.py +++ b/ramalama/http_client.py @@ -18,9 +18,7 @@ def init(self, url, headers, output_file, progress, response_str=None): output_file_partial = output_file + ".partial" self.file_size = self.set_resume_point(output_file_partial) - self.printed = False self.urlopen(url, headers) - self.total_to_download = int(self.response.getheader('content-length', 0)) if response_str is not None: response_str.append(self.response.read().decode('utf-8')) @@ -39,9 +37,6 @@ def init(self, url, headers, output_file, progress, response_str=None): if output_file: os.rename(output_file_partial, output_file) - if self.printed: - print("\n") - def urlopen(self, url, headers): headers["Range"] = f"bytes={self.file_size}-" request = urllib.request.Request(url, headers=headers) @@ -70,11 +65,14 @@ def perform_download(self, file, progress): if progress: accumulated_size += size if time.time() - last_update_time >= 0.1: - self.now_downloaded += accumulated_size self.update_progress(accumulated_size) accumulated_size = 0 last_update_time = time.time() + if accumulated_size: + self.update_progress(accumulated_size) + print("\033[K", end="\r") + def human_readable_time(self, seconds): hrs = int(seconds) // 3600 mins = (int(seconds) % 3600) // 60 @@ -141,7 +139,6 @@ def update_progress(self, chunk_size): progress_bar_width = self.calculate_progress_bar_width(progress_prefix, progress_suffix) progress_bar = self.generate_progress_bar(progress_bar_width, percentage) self.print_progress(progress_prefix, progress_bar, progress_suffix) - self.printed = True def calculate_speed(self, now_downloaded, start_time): now = time.time()