Skip to content

abstract_provider

AbstractProvider

Bases: ABC

Source code in client/ayon_sitesync/providers/abstract_provider.py
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
class AbstractProvider(ABC):
    CODE = ""
    LABEL = ""

    _log = None

    def __init__(self, project_name, site_name, tree=None, presets=None):
        self.presets = None
        self.active = False
        self.site_name = site_name

        self.presets = presets

        super(AbstractProvider, self).__init__()

    @property
    def log(self):
        if self._log is None:
            self._log = Logger.get_logger(self.__class__.__name__)
        return self._log

    @abstractmethod
    def is_active(self):
        """
            Returns True if provider is activated, eg. has working credentials.
        Returns:
            (boolean)
        """

    @abstractmethod
    def upload_file(
        self,
        source_path,
        target_path,
        addon,
        project_name,
        file,
        repre_status,
        site,
        overwrite=False
    ):
        """
            Copy file from 'source_path' to 'target_path' on provider.
            Use 'overwrite' boolean to rewrite existing file on provider

        Args:
            source_path (string): absolute path on provider
            target_path (string): absolute path with or without name of the file
            addon (SiteSyncAddon): addon instance to call update_db on
            project_name (str):
            file (dict): info about uploaded file (matches structure from db)
            repre_status (dict): complete representation containing
                sync progress
            site (str): site name
            overwrite (boolean): replace existing file
        Returns:
            (string) file_id of created/modified file ,
                throws FileExistsError, FileNotFoundError exceptions
        """
        pass

    @abstractmethod
    def download_file(
        self,
        source_path,
        local_path,
        addon,
        project_name,
        file,
        repre_status,
        site,
        overwrite=False
    ):
        """
            Download file from provider into local system

        Args:
            source_path (string): absolute path on provider
            local_path (string): absolute path with or without name of the file
            addon (SiteSyncAddon): addon instance to call update_db on
            project_name (str):
            file (dict): info about uploaded file (matches structure from db)
            repre_status (dict): complete representation containing
                sync progress
            site (str): site name
            overwrite (boolean): replace existing file
        Returns:
            (string) file_id of created/modified file ,
                throws FileExistsError, FileNotFoundError exceptions
        """
        pass

    @abstractmethod
    def delete_file(self, path):
        """
            Deletes file from 'path'. Expects path to specific file.

        Args:
            path (string): absolute path to particular file

        Returns:
            None
        """
        pass

    @abstractmethod
    def list_folder(self, folder_path):
        """
            List all files and subfolders of particular path non-recursively.
        Args:
            folder_path (string): absolut path on provider

        Returns:
            (list)
        """
        pass

    @abstractmethod
    def create_folder(self, folder_path):
        """
            Create all nonexistent folders and subfolders in 'path'.

        Args:
            path (string): absolute path

        Returns:
            (string) folder id of lowest subfolder from 'path'
        """
        pass

    @abstractmethod
    def get_tree(self):
        """
            Creates folder structure for providers which do not provide
            tree folder structure (GDrive has no accessible tree structure,
            only parents and their parents)
        """
        pass

    @abstractmethod
    def get_roots_config(self, anatomy=None):
        """
            Returns root values for path resolving

            Takes value from Anatomy which takes values from Settings
            overridden by Local Settings

        Returns:
            (dict) - {"root": {"root": "/My Drive"}}
                     OR
                     {"root": {"root_ONE": "value", "root_TWO":"value}}
            Format is importing for usage of python's format ** approach
        """
        pass

    def resolve_path(self, path, root_config=None, anatomy=None):
        """
            Replaces all root placeholders with proper values

            Args:
                path(string): root[work]/folder...
                root_config (dict): {'work': "c:/..."...}
                anatomy (Anatomy): object of Anatomy
            Returns:
                (string): proper url
        """
        if not root_config:
            root_config = self.get_roots_config(anatomy)

        if root_config:
            root_config = {"root": root_config.get("root") or root_config}

        try:
            if not root_config:
                raise KeyError

            path = path.format(**root_config)
        except KeyError:
            try:
                path = anatomy.fill_root(path)
            except KeyError:
                msg = "Error in resolving local root from anatomy"
                self.log.error(msg)
                raise ValueError(msg)
        except IndexError:
            msg = "Path {} contains unfillable placeholder"
            self.log.error(msg)
            raise ValueError(msg)

        return path

create_folder(folder_path) abstractmethod

Create all nonexistent folders and subfolders in 'path'.

Parameters:

Name Type Description Default
path string

absolute path

required

Returns:

Type Description

(string) folder id of lowest subfolder from 'path'

Source code in client/ayon_sitesync/providers/abstract_provider.py
125
126
127
128
129
130
131
132
133
134
135
136
@abstractmethod
def create_folder(self, folder_path):
    """
        Create all nonexistent folders and subfolders in 'path'.

    Args:
        path (string): absolute path

    Returns:
        (string) folder id of lowest subfolder from 'path'
    """
    pass

delete_file(path) abstractmethod

Deletes file from 'path'. Expects path to specific file.

Parameters:

Name Type Description Default
path string

absolute path to particular file

required

Returns:

Type Description

None

Source code in client/ayon_sitesync/providers/abstract_provider.py
100
101
102
103
104
105
106
107
108
109
110
111
@abstractmethod
def delete_file(self, path):
    """
        Deletes file from 'path'. Expects path to specific file.

    Args:
        path (string): absolute path to particular file

    Returns:
        None
    """
    pass

download_file(source_path, local_path, addon, project_name, file, repre_status, site, overwrite=False) abstractmethod

Download file from provider into local system

Parameters:

Name Type Description Default
source_path string

absolute path on provider

required
local_path string

absolute path with or without name of the file

required
addon SiteSyncAddon

addon instance to call update_db on

required
project_name str
required
file dict

info about uploaded file (matches structure from db)

required
repre_status dict

complete representation containing sync progress

required
site str

site name

required
overwrite boolean

replace existing file

False

Returns: (string) file_id of created/modified file , throws FileExistsError, FileNotFoundError exceptions

Source code in client/ayon_sitesync/providers/abstract_provider.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@abstractmethod
def download_file(
    self,
    source_path,
    local_path,
    addon,
    project_name,
    file,
    repre_status,
    site,
    overwrite=False
):
    """
        Download file from provider into local system

    Args:
        source_path (string): absolute path on provider
        local_path (string): absolute path with or without name of the file
        addon (SiteSyncAddon): addon instance to call update_db on
        project_name (str):
        file (dict): info about uploaded file (matches structure from db)
        repre_status (dict): complete representation containing
            sync progress
        site (str): site name
        overwrite (boolean): replace existing file
    Returns:
        (string) file_id of created/modified file ,
            throws FileExistsError, FileNotFoundError exceptions
    """
    pass

get_roots_config(anatomy=None) abstractmethod

Returns root values for path resolving

Takes value from Anatomy which takes values from Settings
overridden by Local Settings

Returns:

Type Description

(dict) - {"root": {"root": "/My Drive"}} OR {"root": {"root_ONE": "value", "root_TWO":"value}}

Format is importing for usage of python's format ** approach

Source code in client/ayon_sitesync/providers/abstract_provider.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@abstractmethod
def get_roots_config(self, anatomy=None):
    """
        Returns root values for path resolving

        Takes value from Anatomy which takes values from Settings
        overridden by Local Settings

    Returns:
        (dict) - {"root": {"root": "/My Drive"}}
                 OR
                 {"root": {"root_ONE": "value", "root_TWO":"value}}
        Format is importing for usage of python's format ** approach
    """
    pass

get_tree() abstractmethod

Creates folder structure for providers which do not provide tree folder structure (GDrive has no accessible tree structure, only parents and their parents)

Source code in client/ayon_sitesync/providers/abstract_provider.py
138
139
140
141
142
143
144
145
@abstractmethod
def get_tree(self):
    """
        Creates folder structure for providers which do not provide
        tree folder structure (GDrive has no accessible tree structure,
        only parents and their parents)
    """
    pass

is_active() abstractmethod

Returns True if provider is activated, eg. has working credentials.

Returns: (boolean)

Source code in client/ayon_sitesync/providers/abstract_provider.py
29
30
31
32
33
34
35
@abstractmethod
def is_active(self):
    """
        Returns True if provider is activated, eg. has working credentials.
    Returns:
        (boolean)
    """

list_folder(folder_path) abstractmethod

List all files and subfolders of particular path non-recursively.

Args: folder_path (string): absolut path on provider

Returns:

Type Description

(list)

Source code in client/ayon_sitesync/providers/abstract_provider.py
113
114
115
116
117
118
119
120
121
122
123
@abstractmethod
def list_folder(self, folder_path):
    """
        List all files and subfolders of particular path non-recursively.
    Args:
        folder_path (string): absolut path on provider

    Returns:
        (list)
    """
    pass

resolve_path(path, root_config=None, anatomy=None)

Replaces all root placeholders with proper values

Parameters:

Name Type Description Default
path(string)

root[work]/folder...

required
root_config dict

{'work': "c:/..."...}

None
anatomy Anatomy

object of Anatomy

None

Returns: (string): proper url

Source code in client/ayon_sitesync/providers/abstract_provider.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def resolve_path(self, path, root_config=None, anatomy=None):
    """
        Replaces all root placeholders with proper values

        Args:
            path(string): root[work]/folder...
            root_config (dict): {'work': "c:/..."...}
            anatomy (Anatomy): object of Anatomy
        Returns:
            (string): proper url
    """
    if not root_config:
        root_config = self.get_roots_config(anatomy)

    if root_config:
        root_config = {"root": root_config.get("root") or root_config}

    try:
        if not root_config:
            raise KeyError

        path = path.format(**root_config)
    except KeyError:
        try:
            path = anatomy.fill_root(path)
        except KeyError:
            msg = "Error in resolving local root from anatomy"
            self.log.error(msg)
            raise ValueError(msg)
    except IndexError:
        msg = "Path {} contains unfillable placeholder"
        self.log.error(msg)
        raise ValueError(msg)

    return path

upload_file(source_path, target_path, addon, project_name, file, repre_status, site, overwrite=False) abstractmethod

Copy file from 'source_path' to 'target_path' on provider.
Use 'overwrite' boolean to rewrite existing file on provider

Parameters:

Name Type Description Default
source_path string

absolute path on provider

required
target_path string

absolute path with or without name of the file

required
addon SiteSyncAddon

addon instance to call update_db on

required
project_name str
required
file dict

info about uploaded file (matches structure from db)

required
repre_status dict

complete representation containing sync progress

required
site str

site name

required
overwrite boolean

replace existing file

False

Returns: (string) file_id of created/modified file , throws FileExistsError, FileNotFoundError exceptions

Source code in client/ayon_sitesync/providers/abstract_provider.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@abstractmethod
def upload_file(
    self,
    source_path,
    target_path,
    addon,
    project_name,
    file,
    repre_status,
    site,
    overwrite=False
):
    """
        Copy file from 'source_path' to 'target_path' on provider.
        Use 'overwrite' boolean to rewrite existing file on provider

    Args:
        source_path (string): absolute path on provider
        target_path (string): absolute path with or without name of the file
        addon (SiteSyncAddon): addon instance to call update_db on
        project_name (str):
        file (dict): info about uploaded file (matches structure from db)
        repre_status (dict): complete representation containing
            sync progress
        site (str): site name
        overwrite (boolean): replace existing file
    Returns:
        (string) file_id of created/modified file ,
            throws FileExistsError, FileNotFoundError exceptions
    """
    pass