Skip to content

utils

DJVExecutableCache

Source code in client/ayon_djv/utils.py
 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
class DJVExecutableCache:
    lifetime = 10

    def __init__(self):
        self._cached_time = None
        self._djv_paths = None
        self._djv_path = None

    def is_cache_valid(self):
        """Cache is valid.

        Returns:
            bool: True if cache is valid, False otherwise.
        """

        if self._cached_time is None:
            return False

        start = time.time()
        return (start - self._cached_time) <= self.lifetime

    def get_paths(self):
        """Get all paths to DJV executable from settings.

        Returns:
            list[str]: Path to DJV executables.
        """

        if not self.is_cache_valid():
            self._djv_paths = get_djv_paths_from_settings()
            self._cached_time = time.time()
        return self._djv_paths

    def get_path(self):
        """Get path to DJV executable.

        Returns:
            Union[str, None]: Path to DJV executable or None.
        """

        if not self.is_cache_valid():
            self._djv_path = get_djv_executable_path(self.get_paths())
        return self._djv_path

get_path()

Get path to DJV executable.

Returns:

Type Description

Union[str, None]: Path to DJV executable or None.

Source code in client/ayon_djv/utils.py
 97
 98
 99
100
101
102
103
104
105
106
def get_path(self):
    """Get path to DJV executable.

    Returns:
        Union[str, None]: Path to DJV executable or None.
    """

    if not self.is_cache_valid():
        self._djv_path = get_djv_executable_path(self.get_paths())
    return self._djv_path

get_paths()

Get all paths to DJV executable from settings.

Returns:

Type Description

list[str]: Path to DJV executables.

Source code in client/ayon_djv/utils.py
85
86
87
88
89
90
91
92
93
94
95
def get_paths(self):
    """Get all paths to DJV executable from settings.

    Returns:
        list[str]: Path to DJV executables.
    """

    if not self.is_cache_valid():
        self._djv_paths = get_djv_paths_from_settings()
        self._cached_time = time.time()
    return self._djv_paths

is_cache_valid()

Cache is valid.

Returns:

Name Type Description
bool

True if cache is valid, False otherwise.

Source code in client/ayon_djv/utils.py
72
73
74
75
76
77
78
79
80
81
82
83
def is_cache_valid(self):
    """Cache is valid.

    Returns:
        bool: True if cache is valid, False otherwise.
    """

    if self._cached_time is None:
        return False

    start = time.time()
    return (start - self._cached_time) <= self.lifetime

get_djv_executable_path(paths=None, addon_settings=None)

Parameters:

Name Type Description Default
paths Optional[list[str]]

List of paths to DJV executable.

None
addon_settings Optional[dict[str, Any]

Addon settings.

None

Returns:

Type Description

list[str]: List of available paths to DJV executable.

Source code in client/ayon_djv/utils.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def get_djv_executable_path(paths=None, addon_settings=None):
    """

    Args:
        paths (Optional[list[str]]): List of paths to DJV executable.
        addon_settings (Optional[dict[str, Any]): Addon settings.

    Returns:
        list[str]: List of available paths to DJV executable.
    """

    if paths is None:
        paths = get_djv_paths_from_settings(addon_settings)

    for path in paths:
        if path and os.path.exists(path):
            return path
    return None

get_djv_icon_url(server_url=None)

Get URL to DJV icon.

Parameters:

Name Type Description Default
server_url Optional[str]

AYON server URL.

None

Returns:

Name Type Description
str

URL where DJV icon is located.

Source code in client/ayon_djv/utils.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def get_djv_icon_url(server_url=None):
    """Get URL to DJV icon.

    Args:
        server_url (Optional[str]): AYON server URL.

    Returns:
        str: URL where DJV icon is located.
    """

    server_url = server_url or ayon_api.get_base_url()
    return "{}/addons/{}/{}/public/djv.png".format(
        server_url, ADDON_NAME, __version__
    )

get_djv_paths_from_settings(addon_settings=None)

Parameters:

Name Type Description Default
addon_settings Optional[dict[str, Any]

Addon settings.

None

Returns:

Type Description

list[str]: List to DJV executable paths. Paths are not validated.

Source code in client/ayon_djv/utils.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def get_djv_paths_from_settings(addon_settings=None):
    """

    Args:
        addon_settings (Optional[dict[str, Any]): Addon settings.

    Returns:
        list[str]: List to DJV executable paths. Paths are not validated.
    """

    if addon_settings is None:
        addon_settings = ayon_api.get_addon_settings(ADDON_NAME, __version__)

    platform_name = platform.system().lower()
    return addon_settings.get("djv_path", {}).get(platform_name, [])