Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdrive: download: stream & add progress #3722

Merged
merged 6 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions dvc/remote/gdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ def __init__(self, cred_location):
super().__init__(message)


def _extract(exc, field):
from pydrive2.files import ApiRequestError

assert isinstance(exc, ApiRequestError)

# https://cloud.google.com/storage/docs/json_api/v1/status-codes#errorformat
return (
exc.error["errors"][0].get(field, "") if "errors" in exc.error else ""
)


def _gdrive_retry(func):
def should_retry(exc):
from pydrive2.files import ApiRequestError
Expand All @@ -68,7 +57,7 @@ def should_retry(exc):
result = True

if error_code == 403:
result = _extract(exc, "reason") in [
result = exc.GetField("reason") in [
"userRateLimitExceeded",
"rateLimitExceeded",
]
Expand Down Expand Up @@ -396,14 +385,11 @@ def _gdrive_download_file(
param = {"id": item_id}
# it does not create a file on the remote
gdrive_file = self._drive.CreateFile(param)
bar_format = (
"Downloading {desc:{ncols_desc}.{ncols_desc}}... "
+ Tqdm.format_sizeof(int(gdrive_file["fileSize"]), "B", 1024)
)

with Tqdm(
bar_format=bar_format, desc=progress_desc, disable=no_progress_bar
):
gdrive_file.GetContentFile(to_file)
desc=progress_desc, disable=no_progress_bar, bytes=True,
) as pbar:
gdrive_file.GetContentFile(to_file, callback=pbar.update_to)

@_gdrive_retry
def _gdrive_delete_file(self, item_id):
Expand All @@ -420,7 +406,7 @@ def _gdrive_delete_file(self, item_id):
if (
http_error_code == 403
and self._list_params["corpora"] == "drive"
and _extract(exc, "location") == "file.permissions"
and exc.GetField("location") == "file.permissions"
):
raise DvcException(
"Insufficient permissions to {}. You should have {} "
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run(self):
# Extra dependencies for remote integrations

gs = ["google-cloud-storage==1.19.0"]
gdrive = ["pydrive2>=1.4.10"]
gdrive = ["pydrive2>=1.4.11"]
s3 = ["boto3>=1.9.201"]
azure = ["azure-storage-blob==2.1.0"]
oss = ["oss2==2.6.1"]
Expand Down