Skip to content

Commit adc8d45

Browse files
committed
vmupdate: print fetching info
1 parent e9395d8 commit adc8d45

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

vmupdate/agent/source/apt/apt_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class FetchProgress(apt.progress.base.AcquireProgress, Progress):
108108
def __init__(self, weight: int, log, refresh: bool = False):
109109
Progress.__init__(self, weight, log)
110110
self.action = "refresh" if refresh else "fetch"
111+
self.fetching_notified = False
111112

112113
def fail(self, item):
113114
"""
@@ -126,13 +127,19 @@ def pulse(self, _owner):
126127
This function returns a boolean value indicating whether the
127128
acquisition should be continued (True) or cancelled (False).
128129
"""
130+
if self.action == "fetch" and not self.fetching_notified:
131+
print(f"Fetching {self.total_items} packages "
132+
f"[{self._format_bytes(self.total_bytes)}]",
133+
flush=True)
134+
self.fetching_notified = True
129135
self.notify_callback(self.current_bytes / self.total_bytes * 100)
130136
return True
131137

132138
def start(self):
133139
"""Invoked when the Acquire process starts running."""
134140
self.log.info(f"{self.action.capitalize()} started.")
135-
print(f"{self.action.capitalize()}ing packages.", flush=True)
141+
if self.action == "refresh":
142+
print("Refreshing available packages.", flush=True)
136143
super().start()
137144
self.notify_callback(0)
138145

vmupdate/agent/source/common/progress_reporter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def notify_callback(self, percent):
6464
self._callback(_percent)
6565
self._last_percent = _percent
6666

67+
@staticmethod
68+
def _format_bytes(size):
69+
units = ["B", "KB", "MB", "GB", "TB", "PB"]
70+
factor = 1000
71+
for unit in units:
72+
if size < factor:
73+
return f"{size:.2f} {unit}"
74+
size /= factor
75+
return f"{size:.2f} {units[-1]}"
76+
6777

6878
class ProgressReporter:
6979
"""

vmupdate/agent/source/dnf/dnf5_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ def progress(
165165
:param downloaded: Number of bytes downloaded.
166166
"""
167167
if not self.fetching_notified:
168-
print(f"Fetching {self.count} packages", flush=True)
168+
print(f"Fetching {self.count} packages "
169+
f"[{self._format_bytes(self.bytes_to_fetch)}]",
170+
flush=True)
169171
self.fetching_notified = True
170172
self.bytes_fetched += downloaded - self.package_bytes[user_cb_data]
171173
if downloaded > self.package_bytes[user_cb_data]:

vmupdate/agent/source/dnf/dnf_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ def start(self, total_files, total_size, total_drpms=0):
182182
183183
"""
184184
self.log.info("Fetch started.")
185-
print("Fetching packages:", flush=True)
186185
self.bytes_to_fetch = total_size
186+
print(f"Fetching {total_files} packages "
187+
f"[{self._format_bytes(self.bytes_to_fetch)}]",
188+
flush=True)
187189
self.package_bytes = {}
188190
self.notify_callback(0)
189191

0 commit comments

Comments
 (0)