Skip to content

Commit 75f8b9c

Browse files
committed
start to clean up gdrive
1 parent ecdc608 commit 75f8b9c

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

Diff for: dvc/remote/gdrive/__init__.py renamed to dvc/remote/gdrive.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from funcy import retry, compose, decorator, wrap_with
99
from funcy.py3 import cat
1010

11-
from dvc.remote.gdrive.utils import TrackFileReadProgress, FOLDER_MIME_TYPE
11+
from dvc.progress import Tqdm
1212
from dvc.scheme import Schemes
1313
from dvc.path_info import CloudURLInfo
1414
from dvc.remote.base import RemoteBASE
@@ -17,6 +17,7 @@
1717
from dvc.utils import tmp_fname
1818

1919
logger = logging.getLogger(__name__)
20+
FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"
2021

2122

2223
class GDriveRetriableError(DvcException):
@@ -96,21 +97,25 @@ def gdrive_upload_file(
9697
return item
9798

9899
def upload_file(self, item, no_progress_bar, from_file, progress_name):
99-
with open(from_file, "rb") as opened_file:
100-
if not no_progress_bar:
101-
opened_file = TrackFileReadProgress(progress_name, opened_file)
102-
# PyDrive doesn't like content property setting for empty files
103-
# https://github.com/gsuitedevs/PyDrive/issues/121
104-
if os.stat(from_file).st_size:
105-
item.content = opened_file
106-
item.Upload()
100+
with open(from_file, "rb") as fobj:
101+
total = os.fstat(fobj.fileno()).st_size
102+
with Tqdm.wrapattr(
103+
fobj,
104+
"read",
105+
desc=progress_name,
106+
total=total,
107+
disable=no_progress_bar,
108+
) as opened_file:
109+
# PyDrive doesn't like content property setting for empty files
110+
# https://github.com/gsuitedevs/PyDrive/issues/121
111+
if total:
112+
item.content = opened_file
113+
item.Upload()
107114

108115
@gdrive_retry
109116
def gdrive_download_file(
110117
self, file_id, to_file, progress_name, no_progress_bar
111118
):
112-
from dvc.progress import Tqdm
113-
114119
gdrive_file = self.drive.CreateFile({"id": file_id})
115120
with Tqdm(
116121
desc=progress_name,

Diff for: dvc/remote/gdrive/utils.py

-25
This file was deleted.

0 commit comments

Comments
 (0)