Skip to content

utils

ResumableError

Bases: Exception

Error which could be temporary, skip current loop, try next time

Source code in client/ayon_sitesync/utils.py
10
11
12
class ResumableError(Exception):
    """Error which could be temporary, skip current loop, try next time"""
    pass

SiteAlreadyPresentError

Bases: Exception

Representation has already site skeleton present.

Source code in client/ayon_sitesync/utils.py
15
16
17
class SiteAlreadyPresentError(Exception):
    """Representation has already site skeleton present."""
    pass

get_linked_representation_id(project_name, repre_entity, link_type, max_depth=None)

Returns list of linked ids of particular type (if provided).

One of representation document or representation id must be passed. Note: Representation links now works only from representation through version back to representations.

Todos

Missing depth query. Not sure how it did find more representations in depth, probably links to version? This function should probably live in sitesync addon?

Parameters:

Name Type Description Default
project_name str

Name of project where look for links.

required
repre_entity dict[str, Any]

Representation entity.

required
link_type str

Type of link (e.g. 'reference', ...).

required
max_depth int

Limit recursion level. Default: 0

None

Returns:

Type Description

List[ObjectId] Linked representation ids.

Source code in client/ayon_sitesync/utils.py
 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
def get_linked_representation_id(
    project_name,
    repre_entity,
    link_type,
    max_depth=None
):
    """Returns list of linked ids of particular type (if provided).

    One of representation document or representation id must be passed.
    Note:
        Representation links now works only from representation through
            version back to representations.

    Todos:
        Missing depth query. Not sure how it did find more representations
            in depth, probably links to version?
        This function should probably live in sitesync addon?

    Args:
        project_name (str): Name of project where look for links.
        repre_entity (dict[str, Any]): Representation entity.
        link_type (str): Type of link (e.g. 'reference', ...).
        max_depth (int): Limit recursion level. Default: 0

    Returns:
        List[ObjectId] Linked representation ids.
    """

    if not repre_entity:
        return []

    version_id = repre_entity["versionId"]
    if max_depth is None or max_depth == 0:
        max_depth = 1

    link_types = None
    if link_type:
        link_types = [link_type]

    # Store already found version ids to avoid recursion, and also to store
    #   output -> Don't forget to remove 'version_id' at the end!!!
    linked_version_ids = {version_id}
    # Each loop of depth will reset this variable
    versions_to_check = {version_id}
    for _ in range(max_depth):
        if not versions_to_check:
            break

        versions_links = get_versions_links(
            project_name,
            versions_to_check,
            link_types=link_types,
            link_direction="in")  # looking for 'in'puts for version

        versions_to_check = set()
        for links in versions_links.values():
            for link in links:
                # Care only about version links
                if link["entityType"] != "version":
                    continue
                entity_id = link["entityId"]
                linked_version_ids.add(entity_id)
                versions_to_check.add(entity_id)

    linked_version_ids.remove(version_id)
    if not linked_version_ids:
        return []
    representations = get_representations(
        project_name,
        version_ids=linked_version_ids,
        fields=["id"])
    return [
        repre["id"]
        for repre in representations
    ]

time_function(method)

Decorator to print how much time function took. For debugging. Depends on presence of 'log' object

Source code in client/ayon_sitesync/utils.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def time_function(method):
    """ Decorator to print how much time function took.
        For debugging.
        Depends on presence of 'log' object
    """

    def timed(*args, **kw):
        ts = time.time()
        result = method(*args, **kw)
        te = time.time()
        if "log_time" in kw:
            name = kw.get("log_name", method.__name__.upper())
            kw["log_time"][name] = int((te - ts) * 1000)
        else:
            log.debug("%r  %2.2f ms" % (method.__name__, (te - ts) * 1000))
        return result

    return timed