Skip to content

utils

Use xstudio to open images and movies in the browser / loader UI.

XStudioExecutableCache

Simple cache for app paths.

Source code in client/ayon_xstudio/utils.py
 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
class XStudioExecutableCache:
    """Simple cache for app paths."""

    lifetime = 10

    def __init__(self) -> None:
        """Initialize instance."""
        self._cached_time: Optional[float] = None
        self._xstudio_paths: Optional[List[str]] = None
        self._xstudio_path: Optional[str] = None

    def is_cache_valid(self) -> bool:
        """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) -> Optional[List[str]]:
        """Get all paths to xStudio executable from settings.

        Returns:
            list[str]: Path to xStudio executables.
        """
        if not self.is_cache_valid():
            self._xstudio_paths = get_xstudio_paths_from_settings()
            self._cached_time = time.time()
        return self._xstudio_paths

    def get_path(self) -> Optional[str]:
        """Get path to xStudio executable.

        Returns:
            Union[str, None]: Path to xStudio executable or None.
        """
        if not self.is_cache_valid():
            self._xstudio_path = get_xstudio_executable_path(self.get_paths())
        return self._xstudio_path

__init__()

Initialize instance.

Source code in client/ayon_xstudio/utils.py
86
87
88
89
90
def __init__(self) -> None:
    """Initialize instance."""
    self._cached_time: Optional[float] = None
    self._xstudio_paths: Optional[List[str]] = None
    self._xstudio_path: Optional[str] = None

get_path()

Get path to xStudio executable.

Returns:

Type Description
Optional[str]

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

Source code in client/ayon_xstudio/utils.py
115
116
117
118
119
120
121
122
123
def get_path(self) -> Optional[str]:
    """Get path to xStudio executable.

    Returns:
        Union[str, None]: Path to xStudio executable or None.
    """
    if not self.is_cache_valid():
        self._xstudio_path = get_xstudio_executable_path(self.get_paths())
    return self._xstudio_path

get_paths()

Get all paths to xStudio executable from settings.

Returns:

Type Description
Optional[List[str]]

list[str]: Path to xStudio executables.

Source code in client/ayon_xstudio/utils.py
104
105
106
107
108
109
110
111
112
113
def get_paths(self) -> Optional[List[str]]:
    """Get all paths to xStudio executable from settings.

    Returns:
        list[str]: Path to xStudio executables.
    """
    if not self.is_cache_valid():
        self._xstudio_paths = get_xstudio_paths_from_settings()
        self._cached_time = time.time()
    return self._xstudio_paths

is_cache_valid()

Cache is valid.

Returns:

Name Type Description
bool bool

True if cache is valid, False otherwise.

Source code in client/ayon_xstudio/utils.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def is_cache_valid(self) -> bool:
    """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_base_xstudio_icon_url()

Get the base URL for the xStudio icon.

Returns:

Name Type Description
str str

The base URL for the xStudio icon.

Source code in client/ayon_xstudio/utils.py
16
17
18
19
20
21
22
def get_base_xstudio_icon_url() -> str:
    """Get the base URL for the xStudio icon.

    Returns:
        str: The base URL for the xStudio icon.
    """
    return f"addons/{ADDON_NAME}/{__version__}/public/xstudio.png"

get_xstudio_executable_path(paths=None, addon_settings=None)

Get the xStudio executable path.

Parameters:

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

Optional list of paths to check.

None
addon_settings Optional[Dict[str, Any]]

Optional addon settings dictionary.

None

Returns:

Type Description
Optional[str]

Optional[str]: Path to xStudio executable or None if not found.

Source code in client/ayon_xstudio/utils.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def get_xstudio_executable_path(
    paths: Optional[List[str]] = None,
    addon_settings: Optional[Dict[str, Any]] = None,
) -> Optional[str]:
    """Get the xStudio executable path.

    Args:
        paths: Optional list of paths to check.
        addon_settings: Optional addon settings dictionary.

    Returns:
        Optional[str]: Path to xStudio executable or None if not found.
    """
    if paths is None:
        paths = get_xstudio_paths_from_settings(addon_settings)

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

get_xstudio_icon_url(server_url=None)

Get the full URL for the xStudio icon.

Parameters:

Name Type Description Default
server_url Optional[str]

Optional server URL. If not provided, uses the default.

None

Returns:

Name Type Description
str str

The full URL for the xStudio icon.

Source code in client/ayon_xstudio/utils.py
25
26
27
28
29
30
31
32
33
34
35
def get_xstudio_icon_url(server_url: Optional[str] = None) -> str:
    """Get the full URL for the xStudio icon.

    Args:
        server_url: Optional server URL. If not provided, uses the default.

    Returns:
        str: The full URL for the xStudio icon.
    """
    server_url = server_url or ayon_api.get_base_url()
    return f"{server_url}/{get_base_xstudio_icon_url()}"

get_xstudio_paths_from_settings(addon_settings=None)

Get xStudio paths from addon settings.

Parameters:

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

Optional addon settings dictionary.

None

Returns:

Type Description
List[str]

List[str]: List of xStudio paths.

Source code in client/ayon_xstudio/utils.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def get_xstudio_paths_from_settings(
    addon_settings: Optional[Dict[str, Any]] = None,
) -> List[str]:
    """Get xStudio paths from addon settings.

    Args:
        addon_settings: Optional addon settings dictionary.

    Returns:
        List[str]: List of xStudio paths.
    """
    if addon_settings is None:
        addon_settings = ayon_api.get_addon_settings(ADDON_NAME, __version__)

    platform_name = platform.system().lower()
    xstudio_path_settings = {}
    if addon_settings is not None:
        xstudio_path_settings = addon_settings.get("xstudio_path", {})
    return xstudio_path_settings.get(platform_name, [])