Skip to content

data_structures

AddonInfo dataclass

Object matching json payload from Server

Source code in common/ayon_common/distribution/data_structures.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
198
199
200
201
202
203
@dataclass
class AddonInfo:
    """Object matching json payload from Server"""
    name: str
    title: str
    versions: dict[str, AddonVersionInfo]
    description: Union[str, None] = None
    license: Union[str, None] = None
    authors: Union[str, None] = None

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> "AddonInfo":
        """Addon info by available versions.

        Args:
            data (dict[str, Any]): Addon information from server. Should
                contain information about every version under 'versions'.

        Returns:
            AddonInfo: Addon info with available versions.

        """
        # server payload contains info about all versions
        addon_name = data["name"]
        title = data.get("title") or addon_name

        src_versions = data.get("versions") or {}
        dst_versions = {
            addon_version: AddonVersionInfo.from_dict(
                addon_name, title, addon_version, version_data
            )
            for addon_version, version_data in src_versions.items()
        }
        return cls(
            name=addon_name,
            title=title,
            versions=dst_versions,
            description=data.get("description"),
            license=data.get("license"),
            authors=data.get("authors")
        )

from_dict(data) classmethod

Addon info by available versions.

Parameters:

Name Type Description Default
data dict[str, Any]

Addon information from server. Should contain information about every version under 'versions'.

required

Returns:

Name Type Description
AddonInfo AddonInfo

Addon info with available versions.

Source code in common/ayon_common/distribution/data_structures.py
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
198
199
200
201
202
203
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "AddonInfo":
    """Addon info by available versions.

    Args:
        data (dict[str, Any]): Addon information from server. Should
            contain information about every version under 'versions'.

    Returns:
        AddonInfo: Addon info with available versions.

    """
    # server payload contains info about all versions
    addon_name = data["name"]
    title = data.get("title") or addon_name

    src_versions = data.get("versions") or {}
    dst_versions = {
        addon_version: AddonVersionInfo.from_dict(
            addon_name, title, addon_version, version_data
        )
        for addon_version, version_data in src_versions.items()
    }
    return cls(
        name=addon_name,
        title=title,
        versions=dst_versions,
        description=data.get("description"),
        license=data.get("license"),
        authors=data.get("authors")
    )

AddonVersionInfo dataclass

Source code in common/ayon_common/distribution/data_structures.py
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
@dataclass
class AddonVersionInfo:
    version: str
    full_name: str
    title: str = None
    require_distribution: bool = False
    sources: list[SourceInfo] = field(default_factory=list)
    unknown_sources: list[dict[str, Any]] = field(default_factory=list)
    checksum: Union[str, None] = None
    checksum_algorithm: Union[str, None] = None

    @classmethod
    def from_dict(
        cls,
        addon_name: str,
        addon_title: str,
        addon_version: str,
        version_data: dict[str, Any],
    ) -> "AddonVersionInfo":
        """Addon version info.

        Args:
            addon_name (str): Name of addon.
            addon_title (str): Title of addon.
            addon_version (str): Version of addon.
            version_data (dict[str, Any]): Addon version information from
                server.

        Returns:
            AddonVersionInfo: Addon version info.

        """
        full_name = f"{addon_name}_{addon_version}"
        title = f"{addon_title} {addon_version}"

        source_info = version_data.get("clientSourceInfo")
        require_distribution = source_info is not None
        sources, unknown_sources = prepare_sources(
            source_info, f"Addon: '{title}'")
        checksum = version_data.get("checksum")
        if checksum is None:
            checksum = version_data.get("hash")

        return cls(
            version=addon_version,
            full_name=full_name,
            require_distribution=require_distribution,
            sources=sources,
            unknown_sources=unknown_sources,
            checksum=checksum,
            checksum_algorithm=version_data.get("checksumAlgorithm", "sha256"),
            title=title,
        )

from_dict(addon_name, addon_title, addon_version, version_data) classmethod

Addon version info.

Parameters:

Name Type Description Default
addon_name str

Name of addon.

required
addon_title str

Title of addon.

required
addon_version str

Version of addon.

required
version_data dict[str, Any]

Addon version information from server.

required

Returns:

Name Type Description
AddonVersionInfo AddonVersionInfo

Addon version info.

Source code in common/ayon_common/distribution/data_structures.py
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
@classmethod
def from_dict(
    cls,
    addon_name: str,
    addon_title: str,
    addon_version: str,
    version_data: dict[str, Any],
) -> "AddonVersionInfo":
    """Addon version info.

    Args:
        addon_name (str): Name of addon.
        addon_title (str): Title of addon.
        addon_version (str): Version of addon.
        version_data (dict[str, Any]): Addon version information from
            server.

    Returns:
        AddonVersionInfo: Addon version info.

    """
    full_name = f"{addon_name}_{addon_version}"
    title = f"{addon_title} {addon_version}"

    source_info = version_data.get("clientSourceInfo")
    require_distribution = source_info is not None
    sources, unknown_sources = prepare_sources(
        source_info, f"Addon: '{title}'")
    checksum = version_data.get("checksum")
    if checksum is None:
        checksum = version_data.get("hash")

    return cls(
        version=addon_version,
        full_name=full_name,
        require_distribution=require_distribution,
        sources=sources,
        unknown_sources=unknown_sources,
        checksum=checksum,
        checksum_algorithm=version_data.get("checksumAlgorithm", "sha256"),
        title=title,
    )

Bundle dataclass

Class representing bundle information.

Source code in common/ayon_common/distribution/data_structures.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
@dataclass
class Bundle:
    """Class representing bundle information."""

    name: str
    installer_version: Union[str, None]
    addon_versions: dict[str, str]
    dependency_packages: dict[PlatformName, Union[str, None]]
    is_production: bool
    is_staging: bool
    is_dev: bool
    active_dev_user: Union[str, None]
    addons_dev_info: dict[str, AddonDevInfo]
    is_project_bundle: Union[bool, None] = None

    @classmethod
    def from_dict(cls, data):
        addons_dev_info = {
            addon_name: AddonDevInfo(info["enabled"], info["path"])
            for addon_name, info in data.get("addonDevelopment", {}).items()
        }
        return cls(
            name=data["name"],
            installer_version=data.get("installerVersion"),
            addon_versions=data.get("addons", {}),
            dependency_packages=data.get("dependencyPackages", {}),
            is_production=data["isProduction"],
            is_staging=data["isStaging"],
            is_dev=data.get("isDev", False),
            is_project_bundle=data.get("isProject"),
            active_dev_user=data.get("activeUser"),
            addons_dev_info=addons_dev_info,
        )

DependencyItem dataclass

Object matching payload from Server about single dependency package

Source code in common/ayon_common/distribution/data_structures.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
@dataclass
class DependencyItem:
    """Object matching payload from Server about single dependency package"""
    filename: str
    platform_name: str
    checksum: str
    checksum_algorithm: str
    sources: list[SourceInfo]
    unknown_sources: list[dict[str, Any]]
    source_addons: dict[str, str]
    python_modules: dict[str, str]

    @classmethod
    def from_dict(cls, package: dict[str, Any]) -> "DependencyItem":
        filename = package["filename"]
        src_sources = package.get("sources") or []
        for source in src_sources:
            if source.get("type") == "server" and not source.get("filename"):
                source["filename"] = filename

        sources, unknown_sources = prepare_sources(
            src_sources, f"Dependency package '{filename}'")

        return cls(
            filename=filename,
            platform_name=package["platform"],
            sources=sources,
            unknown_sources=unknown_sources,
            checksum=package["checksum"],
            # Backwards compatibility
            checksum_algorithm=package.get("checksumAlgorithm", "sha256"),
            source_addons=package["sourceAddons"],
            python_modules=package["pythonModules"]
        )

convert_source(source)

Create source object from data information.

Parameters:

Name Type Description Default
source Dict[str, any]

Information about source.

required

Returns:

Type Description
Optional[SourceInfo]

Optional[SourceInfo]: Object with source information if type is known.

Source code in common/ayon_common/distribution/data_structures.py
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
def convert_source(source: dict[str, Any]) -> Optional[SourceInfo]:
    """Create source object from data information.

    Args:
        source (Dict[str, any]): Information about source.

    Returns:
        Optional[SourceInfo]: Object with source information if type is
            known.

    """
    source_type = source.get("type")
    if not source_type:
        return None

    if source_type == UrlType.FILESYSTEM.value:
        return LocalSourceInfo(
            type=source_type,
            path=MultiPlatformValue(**source["path"])
        )

    if source_type == UrlType.HTTP.value:
        return WebSourceInfo(
            type=source_type,
            url=source["url"],
            headers=source.get("headers"),
            filename=source.get("filename")
        )

    if source_type == UrlType.SERVER.value:
        return ServerSourceInfo(
            type=source_type,
            filename=source.get("filename"),
            path=source.get("path")
        )