Skip to content

Commit 57111a7

Browse files
committed
gdrive: add support for teamDriveId
1 parent b7f9e73 commit 57111a7

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

dvc/remote/gdrive.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import posixpath
33
import logging
44
import threading
5+
import re
56

67
from funcy import retry, compose, decorator, wrap_with
78
from funcy.py3 import cat
@@ -68,6 +69,16 @@ def __init__(self, repo, config):
6869
super().__init__(repo, config)
6970
self.no_traverse = False
7071
self.path_info = self.path_cls(config[Config.SECTION_REMOTE_URL])
72+
73+
bucket = re.search(
74+
"{}://(.*)".format(self.scheme),
75+
config[Config.SECTION_REMOTE_URL],
76+
re.IGNORECASE,
77+
)
78+
self.bucket = (
79+
bucket.group(1).split("/")[0] if bucket else self.path_info.bucket
80+
)
81+
7182
self.config = config
7283
self.init_drive()
7384

@@ -144,7 +155,7 @@ def cache_root_dirs(self):
144155
cached_dirs = {}
145156
cached_ids = {}
146157
for dir1 in self.gdrive_list_item(
147-
"'{}' in parents and trashed=false".format(self.root_id)
158+
"'{}' in parents and trashed=false".format(self.remote_root_id)
148159
):
149160
remote_path = posixpath.join(self.path_info.path, dir1["title"])
150161
cached_dirs.setdefault(remote_path, []).append(dir1["id"])
@@ -227,7 +238,9 @@ def drive(self):
227238

228239
self._gdrive = GoogleDrive(gauth)
229240

230-
self.root_id = self.get_remote_id(self.path_info, create=True)
241+
self.remote_root_id = self.get_remote_id(
242+
self.path_info, create=True
243+
)
231244
self._cached_dirs, self._cached_ids = self.cache_root_dirs()
232245

233246
return self._gdrive
@@ -261,7 +274,7 @@ def get_remote_item(self, name, parents_ids):
261274
return next(iter(item_list), None)
262275

263276
def resolve_remote_item_from_path(self, path_parts, create):
264-
parents_ids = ["root"]
277+
parents_ids = [self.bucket]
265278
current_path = ""
266279
for path_part in path_parts:
267280
current_path = posixpath.join(current_path, path_part)

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ def run(self):
8484
# google-api-python-client is internal dependency of pydrive. After merge of
8585
# https://github.com/gsuitedevs/PyDrive/pull/180 into pydrive's master,
8686
# usage of google-api-python-client can be removed from DVC.
87-
gdrive = ["pydrive==1.3.1", "google-api-python-client>=1.2"]
87+
gdrive = [
88+
"pydrive @ git+https://github.com/gsuitedevs/PyDrive@master#egg=pydrive",
89+
"google-api-python-client>=1.2",
90+
]
8891
s3 = ["boto3>=1.9.201"]
8992
azure = ["azure-storage-blob==2.1.0"]
9093
oss = ["oss2==2.6.1"]

tests/unit/remote/test_gdrive.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from unittest import TestCase
2-
31
import pytest
42
import os
53

@@ -18,7 +16,7 @@ class Repo(object):
1816
tmp_dir = ""
1917

2018

21-
class TestRemoteGDrive(TestCase):
19+
class TestRemoteGDrive(object):
2220
CONFIG = {
2321
"url": "gdrive://root/data",
2422
"gdrive_client_id": "client",

0 commit comments

Comments
 (0)