Initialize global AYON api connection.
Create global connection in ayon_api module and set site id and client version. Is silently skipped if already happened.
Parameters:
Name | Type | Description | Default |
force | Optional[bool] | Force reinitialize connection. Defaults to False. | False |
Source code in client/ayon_core/lib/ayon_connection.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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 | def initialize_ayon_connection(force=False):
"""Initialize global AYON api connection.
Create global connection in ayon_api module and set site id
and client version.
Is silently skipped if already happened.
Args:
force (Optional[bool]): Force reinitialize connection.
Defaults to False.
"""
if not force and _Cache.initialized:
return
_Cache.initialized = True
ayon_api_version = (
semver.VersionInfo.parse(ayon_api.__version__).to_tuple()
)
# TODO remove mokey patching after when AYON api is safely updated
fix_before_1_0_2 = ayon_api_version < (1, 0, 2)
# Monkey patching to fix 'get_last_version_by_product_name'
if fix_before_1_0_2:
ayon_api.ServerAPI.get_last_versions = (
_new_get_last_versions
)
ayon_api.ServerAPI.get_last_version_by_product_id = (
_new_get_last_version_by_product_id
)
ayon_api.ServerAPI.get_last_version_by_product_name = (
_new_get_last_version_by_product_name
)
site_id = get_local_site_id()
version = os.getenv("AYON_VERSION")
if ayon_api.is_connection_created():
con = ayon_api.get_server_api_connection()
# Monkey patching to fix 'get_last_version_by_product_name'
if fix_before_1_0_2:
def _lvs_wrapper(*args, **kwargs):
return _new_get_last_versions(
con, *args, **kwargs
)
def _lv_by_pi_wrapper(*args, **kwargs):
return _new_get_last_version_by_product_id(
con, *args, **kwargs
)
def _lv_by_pn_wrapper(*args, **kwargs):
return _new_get_last_version_by_product_name(
con, *args, **kwargs
)
con.get_last_versions = _lvs_wrapper
con.get_last_version_by_product_id = _lv_by_pi_wrapper
con.get_last_version_by_product_name = _lv_by_pn_wrapper
con.set_site_id(site_id)
con.set_client_version(version)
else:
ayon_api.create_connection(site_id, version)
|