mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
add progress.Tqdm(truncate)
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user