mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
tidy & avoid excessive requests
This commit is contained in:
+12
-10
@@ -29,15 +29,13 @@ class RemoteHTTP(RemoteBASE):
|
|||||||
|
|
||||||
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
request = self._request("GET", from_info.url, stream=True)
|
request = self._request("GET", from_info.url, stream=True)
|
||||||
total = self._content_length(from_info.url)
|
total = self._content_length(request)
|
||||||
if name is None:
|
|
||||||
name = from_info.url
|
|
||||||
|
|
||||||
with Tqdm(
|
with Tqdm(
|
||||||
total=total,
|
total=total,
|
||||||
leave=False,
|
leave=False,
|
||||||
bytes=True,
|
bytes=True,
|
||||||
desc_truncate=name,
|
desc_truncate=from_info.url if name is None else name,
|
||||||
disable=no_progress_bar,
|
disable=no_progress_bar,
|
||||||
) as pbar:
|
) as pbar:
|
||||||
with open(to_file, "wb") as fd:
|
with open(to_file, "wb") as fd:
|
||||||
@@ -46,7 +44,7 @@ class RemoteHTTP(RemoteBASE):
|
|||||||
fd.flush()
|
fd.flush()
|
||||||
pbar.update(len(chunk))
|
pbar.update(len(chunk))
|
||||||
# print completed progress bar for large file sizes
|
# print completed progress bar for large file sizes
|
||||||
if pbar.n > LARGE_FILE_SIZE:
|
if (total or pbar.n) > LARGE_FILE_SIZE:
|
||||||
Tqdm.write(str(pbar))
|
Tqdm.write(str(pbar))
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info):
|
||||||
@@ -61,15 +59,19 @@ class RemoteHTTP(RemoteBASE):
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _content_length(self, url):
|
def _content_length(self, url_or_request):
|
||||||
res = self._request("HEAD", url).headers.get("Content-Length")
|
headers = getattr(
|
||||||
|
url_or_request,
|
||||||
|
"headers",
|
||||||
|
self._request("HEAD", url_or_request).headers,
|
||||||
|
)
|
||||||
|
res = headers.get("Content-Length")
|
||||||
return int(res) if res else None
|
return int(res) if res else None
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
def get_file_checksum(self, path_info):
|
||||||
url = path_info.url
|
url = path_info.url
|
||||||
etag = self._request("HEAD", url).headers.get("ETag") or self._request(
|
headers = self._request("HEAD", url).headers
|
||||||
"HEAD", url
|
etag = headers.get("ETag") or headers.get("Content-MD5")
|
||||||
).headers.get("Content-MD5")
|
|
||||||
|
|
||||||
if not etag:
|
if not etag:
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
|
|||||||
Reference in New Issue
Block a user