diff --git a/dvc/progress.py b/dvc/progress.py index 3c483ccee..492692ced 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -40,6 +40,19 @@ class Tqdm(tqdm): self.set_description(desc, refresh=False) self.update(n) + @classmethod + def truncate(cls, s, max_len=10, end=True, fill="..."): + """ + Guarantee len(output) < max_lenself. + >>> truncate("hello", 4) + '...o' + """ + if len(s) <= max_len: + return s + if len(fill) > max_len: + return fill[-max_len:] if end else fill[:max_len] + i = max_len - len(fill) + return (fill + s[-i:]) if end else (s[:i] + fill) class Progress(tqdm): """ diff --git a/dvc/remote/http.py b/dvc/remote/http.py index e662b9b9c..15747e679 100644 --- a/dvc/remote/http.py +++ b/dvc/remote/http.py @@ -36,6 +36,7 @@ class RemoteHTTP(RemoteBASE): # leave = total > self.CHUNK_SIZE * 100 with Tqdm(total=total, leave=leave, bytes=True, + desc=Tqdm.truncate(to_file, 10), disable=no_progress_bar) as pbar: with open(to_file, "wb") as fd: for chunk in request.iter_content(chunk_size=self.CHUNK_SIZE):