Enhance logging and progress handling in SSH operations
- Updated the `_log_default` function to handle messages starting with `\r` for in-place updates. - Introduced `split_ssh_stream` to differentiate between line and progress events in SSH output. - Implemented `feed_ssh_log` to dispatch log messages based on event type. - Refactored `_stream_pty_output` to utilize the new logging and event handling functions. - Enhanced the `log` function in `term.py` to support progress updates, ensuring a cleaner output experience. - Updated `DownloadProgress` classes in `civitai_fetch.py` and `llamacpp_fetch.py` to print progress in place, improving user feedback during downloads.
This commit is contained in:
@@ -47,7 +47,7 @@ def progress_line(
|
||||
|
||||
|
||||
class DownloadProgress:
|
||||
"""Print size + speed about once per second (SSH readline-friendly)."""
|
||||
"""Print size + speed ~1Hz; \\r in place, newline on finish."""
|
||||
|
||||
def __init__(self, label: str, total: int | None) -> None:
|
||||
self.label = label
|
||||
@@ -67,14 +67,16 @@ class DownloadProgress:
|
||||
self._emit()
|
||||
|
||||
def finish(self) -> None:
|
||||
self._emit()
|
||||
# Final line with newline so the next log stays below the bar.
|
||||
self._emit(final=True)
|
||||
|
||||
def _emit(self) -> None:
|
||||
def _emit(self, *, final: bool = False) -> None:
|
||||
elapsed = max(time.monotonic() - self.t0, 0.001)
|
||||
print(
|
||||
progress_line(self.label, self.done, self.total, self.done / elapsed),
|
||||
flush=True,
|
||||
)
|
||||
line = progress_line(self.label, self.done, self.total, self.done / elapsed)
|
||||
if final:
|
||||
print(line, flush=True)
|
||||
else:
|
||||
print(line, end="\r", flush=True)
|
||||
|
||||
|
||||
def sha256_path(path: Path) -> str:
|
||||
|
||||
@@ -64,14 +64,15 @@ class DownloadProgress:
|
||||
self._emit()
|
||||
|
||||
def finish(self) -> None:
|
||||
self._emit()
|
||||
self._emit(final=True)
|
||||
|
||||
def _emit(self) -> None:
|
||||
def _emit(self, *, final: bool = False) -> None:
|
||||
elapsed = max(time.monotonic() - self.t0, 0.001)
|
||||
print(
|
||||
progress_line(self.label, self.done, self.total, self.done / elapsed),
|
||||
flush=True,
|
||||
)
|
||||
line = progress_line(self.label, self.done, self.total, self.done / elapsed)
|
||||
if final:
|
||||
print(line, flush=True)
|
||||
else:
|
||||
print(line, end="\r", flush=True)
|
||||
|
||||
|
||||
def download(url: str, dest: Path, headers: dict[str, str], *, label: str) -> None:
|
||||
|
||||
@@ -96,7 +96,9 @@ def pull_stream(name: str, label: str) -> None:
|
||||
if now - last_print >= 1.0 or done >= total:
|
||||
elapsed = max(now - t0, 0.001)
|
||||
speed = done / elapsed
|
||||
print(progress_line(label, done, total, speed), flush=True)
|
||||
line = progress_line(label, done, total, speed)
|
||||
end = "\n" if done >= total else "\r"
|
||||
print(line, end=end, flush=True)
|
||||
last_print = now
|
||||
elif status and status not in {"success"} and now - last_print >= 2.0:
|
||||
print(f"{label} {status}", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user