Skip to content

ayon_info

extract_ayon_info_to_file(dirpath, filename=None)

Extract all current info to a file.

It is possible to define only directory path. Filename is concatenated with AYON version, workstation site id and timestamp.

Parameters:

Name Type Description Default
dirpath str

Path to directory where file will be stored.

required
filename Optional[str]

Filename. If not defined, it is generated.

None

Returns:

Name Type Description
filepath str

Full path to file where data were extracted.

Source code in client/ayon_core/lib/ayon_info.py
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
def extract_ayon_info_to_file(dirpath, filename=None):
    """Extract all current info to a file.

    It is possible to define only directory path. Filename is concatenated
    with AYON version, workstation site id and timestamp.

    Args:
        dirpath (str): Path to directory where file will be stored.
        filename (Optional[str]): Filename. If not defined, it is generated.

    Returns:
        filepath (str): Full path to file where data were extracted.
    """
    if not filename:
        filename = "{}_{}.json".format(
            get_local_site_id(),
            datetime.datetime.now().strftime("%y%m%d%H%M%S")
        )
    filepath = os.path.join(dirpath, filename)
    data = get_all_current_info()
    if not os.path.exists(dirpath):
        os.makedirs(dirpath)

    with open(filepath, "w") as file_stream:
        json.dump(data, file_stream, indent=4)
    return filepath

get_all_current_info()

All information about current process in one dictionary.

Source code in client/ayon_core/lib/ayon_info.py
157
158
159
160
161
162
163
164
def get_all_current_info():
    """All information about current process in one dictionary."""

    return {
        "workstation": get_workstation_info(),
        "env": os.environ.copy(),
        "ayon": get_ayon_info(),
    }

get_ayon_launcher_version()

Get AYON launcher version.

Returns:

Name Type Description
str

Version string.

Source code in client/ayon_core/lib/ayon_info.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def get_ayon_launcher_version():
    """Get AYON launcher version.

    Returns:
        str: Version string.

    """
    version_filepath = os.path.join(os.environ["AYON_ROOT"], "version.py")
    if not os.path.exists(version_filepath):
        return None
    content = {}
    with open(version_filepath, "r") as stream:
        exec(stream.read(), content)
    return content["__version__"]

get_settings_variant()

Get AYON settings variant.

Returns:

Name Type Description
str str

Settings variant.

Source code in client/ayon_core/lib/ayon_info.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def get_settings_variant() -> str:
    """Get AYON settings variant.

    Returns:
        str: Settings variant.

    """
    if is_dev_mode_enabled():
        return os.environ["AYON_BUNDLE_NAME"]

    if is_staging_enabled():
        return "staging"

    return "production"

get_workstation_info()

Basic information about workstation.

Source code in client/ayon_core/lib/ayon_info.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def get_workstation_info():
    """Basic information about workstation."""
    host_name = socket.gethostname()
    try:
        host_ip = socket.gethostbyname(host_name)
    except socket.gaierror:
        host_ip = "127.0.0.1"

    return {
        "hostname": host_name,
        "host_ip": host_ip,
        "username": getpass.getuser(),
        "system_name": platform.system(),
        "local_id": get_local_site_id()
    }

is_dev_mode_enabled()

Dev mode is enabled in AYON.

Returns:

Name Type Description
bool bool

True if dev mode is enabled.

Source code in client/ayon_core/lib/ayon_info.py
 99
100
101
102
103
104
105
106
def is_dev_mode_enabled() -> bool:
    """Dev mode is enabled in AYON.

    Returns:
        bool: True if dev mode is enabled.
    """

    return os.getenv("AYON_USE_DEV") == "1"

is_in_ayon_launcher_process()

Determine if current process is running from AYON launcher.

Returns:

Name Type Description
bool

True if running from AYON launcher.

Source code in client/ayon_core/lib/ayon_info.py
29
30
31
32
33
34
35
36
37
38
def is_in_ayon_launcher_process():
    """Determine if current process is running from AYON launcher.

    Returns:
        bool: True if running from AYON launcher.

    """
    ayon_executable_path = os.path.normpath(os.environ["AYON_EXECUTABLE"])
    executable_path = os.path.normpath(sys.executable)
    return ayon_executable_path == executable_path

is_in_tests()

Process is running in automatic tests mode.

Returns:

Name Type Description
bool bool

True if running in tests.

Source code in client/ayon_core/lib/ayon_info.py
89
90
91
92
93
94
95
96
def is_in_tests() -> bool:
    """Process is running in automatic tests mode.

    Returns:
        bool: True if running in tests.

    """
    return os.environ.get("AYON_IN_TESTS") == "1"

is_running_from_build()

Determine if current process is running from build or code.

Returns:

Name Type Description
bool

True if running from build.

Source code in client/ayon_core/lib/ayon_info.py
41
42
43
44
45
46
47
48
49
50
51
52
def is_running_from_build():
    """Determine if current process is running from build or code.

    Returns:
        bool: True if running from build.

    """
    executable_path = os.environ["AYON_EXECUTABLE"]
    executable_filename = os.path.basename(executable_path)
    if "python" in executable_filename.lower():
        return False
    return True

is_using_ayon_console()

AYON launcher console executable is used.

This function make sense only on Windows platform. For other platforms always returns True. True is also returned if process is running from code.

AYON launcher on windows has 2 executable files. First 'ayon_console.exe' works as 'python.exe' executable, the second 'ayon.exe' works as 'pythonw.exe' executable. The difference is way how stdout/stderr is handled (especially when calling subprocess).

Returns:

Name Type Description
bool

True if console executable is used.

Source code in client/ayon_core/lib/ayon_info.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def is_using_ayon_console():
    """AYON launcher console executable is used.

    This function make sense only on Windows platform. For other platforms
    always returns True. True is also returned if process is running from
    code.

    AYON launcher on windows has 2 executable files. First 'ayon_console.exe'
    works as 'python.exe' executable, the second 'ayon.exe' works as
    'pythonw.exe' executable. The difference is way how stdout/stderr is
    handled (especially when calling subprocess).

    Returns:
        bool: True if console executable is used.

    """
    if (
        platform.system().lower() != "windows"
        or is_running_from_build()
    ):
        return True
    executable_path = os.environ["AYON_EXECUTABLE"]
    executable_filename = os.path.basename(executable_path)
    return "ayon_console" in executable_filename