Skip to content

Commit

Permalink
Support Dropbox root_namespace_id for Team Spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
smrohrer committed Oct 6, 2024
1 parent 829fc0c commit fe2157a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions luigi/contrib/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ class DropboxClient(FileSystem):
Dropbox client for authentication, designed to be used by the :py:class:`DropboxTarget` class.
"""

def __init__(self, token, user_agent="Luigi"):
def __init__(self, token, user_agent="Luigi", root_namespace_id=None):

Check warning on line 71 in luigi/contrib/dropbox.py

View check run for this annotation

Codecov / codecov/patch

luigi/contrib/dropbox.py#L71

Added line #L71 was not covered by tests
"""
:param str token: Dropbox Oauth2 Token. See :class:`DropboxTarget` for more information about generating a token
:param str root_namespace_id: Root namespace ID for interacting with Team Spaces
"""
if not token:
raise ValueError("The token parameter must contain a valid Dropbox Oauth2 Token")
Expand All @@ -80,6 +81,9 @@ def __init__(self, token, user_agent="Luigi"):
except Exception as e:
raise Exception("Cannot connect to Dropbox. Check your Internet connection and the token. \n" + repr(e))

if root_namespace_id:
conn = conn.with_path_root(dropbox.common.PathRoot.root(root_namespace_id))

Check warning on line 85 in luigi/contrib/dropbox.py

View check run for this annotation

Codecov / codecov/patch

luigi/contrib/dropbox.py#L84-L85

Added lines #L84 - L85 were not covered by tests

self.token = token
self.conn = conn

Expand Down Expand Up @@ -257,7 +261,7 @@ class DropboxTarget(FileSystemTarget):
A Dropbox filesystem target.
"""

def __init__(self, path, token, format=None, user_agent="Luigi"):
def __init__(self, path, token, format=None, user_agent="Luigi", root_namespace_id=None):

Check warning on line 264 in luigi/contrib/dropbox.py

View check run for this annotation

Codecov / codecov/patch

luigi/contrib/dropbox.py#L264

Added line #L264 was not covered by tests
"""
Create an Dropbox Target for storing data in a dropbox.com account
Expand Down Expand Up @@ -285,6 +289,7 @@ def __init__(self, path, token, format=None, user_agent="Luigi"):
:param str path: Remote path in Dropbox (starting with '/').
:param str token: a valid OAuth2 Dropbox token.
:param luigi.Format format: the luigi format to use (e.g. `luigi.format.Nop`)
:param str root_namespace_id: Root namespace ID for interacting with Team Spaces
"""
Expand All @@ -295,7 +300,7 @@ def __init__(self, path, token, format=None, user_agent="Luigi"):

self.path = path
self.token = token
self.client = DropboxClient(token, user_agent)
self.client = DropboxClient(token, user_agent, root_namespace_id)

Check warning on line 303 in luigi/contrib/dropbox.py

View check run for this annotation

Codecov / codecov/patch

luigi/contrib/dropbox.py#L303

Added line #L303 was not covered by tests
self.format = format or luigi.format.get_default_format()

def __str__(self):
Expand Down

0 comments on commit fe2157a

Please sign in to comment.