Skip to content

Commit

Permalink
Merge pull request #767 from containers/progress-bar
Browse files Browse the repository at this point in the history
Progress bar fixes
  • Loading branch information
rhatdan authored Feb 8, 2025
2 parents b539762 + d52ac5f commit 738eda2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions ramalama/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
11 changes: 4 additions & 7 deletions ramalama/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 738eda2

Please # to comment.