From fe2157aa08f2ce91e914c20b805338aa222fb93c Mon Sep 17 00:00:00 2001 From: Scott Rohrer Date: Sun, 6 Oct 2024 11:19:03 -0400 Subject: [PATCH] Support Dropbox root_namespace_id for Team Spaces --- luigi/contrib/dropbox.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/luigi/contrib/dropbox.py b/luigi/contrib/dropbox.py index 76760b8688..3a4a3310f7 100644 --- a/luigi/contrib/dropbox.py +++ b/luigi/contrib/dropbox.py @@ -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): """ :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") @@ -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)) + self.token = token self.conn = conn @@ -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): """ Create an Dropbox Target for storing data in a dropbox.com account @@ -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 """ @@ -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) self.format = format or luigi.format.get_default_format() def __str__(self):