mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
tqdm remote.azure
This commit is contained in:
@@ -40,6 +40,11 @@ class Tqdm(tqdm):
|
||||
self.set_description(desc, refresh=False)
|
||||
self.update(n)
|
||||
|
||||
def update_to(self, current, total=None):
|
||||
if total:
|
||||
self.total = total
|
||||
self.update(current - self.n)
|
||||
|
||||
@classmethod
|
||||
def truncate(cls, s, max_len=10, end=True, fill="..."):
|
||||
"""
|
||||
|
||||
+13
-17
@@ -15,7 +15,7 @@ except ImportError:
|
||||
BlockBlobService = None
|
||||
|
||||
from dvc.utils.compat import urlparse
|
||||
from dvc.progress import progress
|
||||
from dvc.progress import Tqdm
|
||||
from dvc.config import Config
|
||||
from dvc.remote.base import RemoteBASE
|
||||
from dvc.path_info import CloudURLInfo
|
||||
@@ -25,14 +25,6 @@ from dvc.utils.http import open_url
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Callback(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __call__(self, current, total):
|
||||
progress.update_target(self.name, current, total)
|
||||
|
||||
|
||||
class RemoteAZURE(RemoteBASE):
|
||||
scheme = Schemes.AZURE
|
||||
path_cls = CloudURLInfo
|
||||
@@ -124,18 +116,22 @@ class RemoteAZURE(RemoteBASE):
|
||||
def _upload(
|
||||
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||
):
|
||||
cb = None if no_progress_bar else Callback(name)
|
||||
self.blob_service.create_blob_from_path(
|
||||
to_info.bucket, to_info.path, from_file, progress_callback=cb
|
||||
)
|
||||
desc = Tqdm.truncate(name, 10) if name else None
|
||||
with Tqdm(desc=desc, disable=no_progress_bar) as pbar:
|
||||
self.blob_service.create_blob_from_path(
|
||||
to_info.bucket, to_info.path, from_file,
|
||||
progress_callback=pbar.update_to
|
||||
)
|
||||
|
||||
def _download(
|
||||
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
||||
):
|
||||
cb = None if no_progress_bar else Callback(name)
|
||||
self.blob_service.get_blob_to_path(
|
||||
from_info.bucket, from_info.path, to_file, progress_callback=cb
|
||||
)
|
||||
desc = Tqdm.truncate(name, 10) if name else None
|
||||
with Tqdm(desc=desc, disable=no_progress_bar) as pbar:
|
||||
self.blob_service.get_blob_to_path(
|
||||
from_info.bucket, from_info.path, to_file,
|
||||
progress_callback=pbar.update_to
|
||||
)
|
||||
|
||||
def open(self, path_info, mode="r", encoding=None):
|
||||
get_url = lambda: self._generate_download_url(path_info) # noqa: E731
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class RemoteHTTP(RemoteBASE):
|
||||
# leave = total > self.CHUNK_SIZE * 100
|
||||
|
||||
with Tqdm(total=total, leave=leave, bytes=True,
|
||||
desc=Tqdm.truncate(to_file, 10),
|
||||
desc=Tqdm.truncate(to_file),
|
||||
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