mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
remove client and implement 'initialize_ayon_connection' to initialize ayon api
This commit is contained in:
parent
f69d77c54c
commit
06f124c7bf
10 changed files with 76 additions and 62 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
from .version import __version__
|
||||
|
||||
|
||||
AYON_CORE_ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ from abc import ABCMeta, abstractmethod
|
|||
|
||||
import six
|
||||
import appdirs
|
||||
import ayon_api
|
||||
|
||||
from ayon_core.lib import Logger, is_dev_mode_enabled
|
||||
from ayon_core.client import get_ayon_server_api_connection
|
||||
from ayon_core.settings import get_studio_settings
|
||||
|
||||
from .interfaces import (
|
||||
|
|
@ -147,8 +147,7 @@ def load_addons(force=False):
|
|||
|
||||
|
||||
def _get_ayon_bundle_data():
|
||||
con = get_ayon_server_api_connection()
|
||||
bundles = con.get_bundles()["bundles"]
|
||||
bundles = ayon_api.get_bundles()["bundles"]
|
||||
|
||||
bundle_name = os.getenv("AYON_BUNDLE_NAME")
|
||||
|
||||
|
|
@ -176,8 +175,7 @@ def _get_ayon_addons_information(bundle_info):
|
|||
|
||||
output = []
|
||||
bundle_addons = bundle_info["addons"]
|
||||
con = get_ayon_server_api_connection()
|
||||
addons = con.get_addons_info()["addons"]
|
||||
addons = ayon_api.get_addons_info()["addons"]
|
||||
for addon in addons:
|
||||
name = addon["name"]
|
||||
versions = addon.get("versions")
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import acre
|
|||
from ayon_core import AYON_CORE_ROOT
|
||||
from ayon_core.addon import AddonsManager
|
||||
from ayon_core.settings import get_general_environments
|
||||
from ayon_core.lib import initialize_ayon_connection
|
||||
|
||||
from .cli_commands import Commands
|
||||
|
||||
|
|
@ -243,6 +244,7 @@ def _set_addons_environments():
|
|||
|
||||
|
||||
def main(*args, **kwargs):
|
||||
initialize_ayon_connection()
|
||||
python_path = os.getenv("PYTHONPATH", "")
|
||||
split_paths = python_path.split(os.pathsep)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
from .utils import get_ayon_server_api_connection
|
||||
|
||||
|
||||
__all__ = (
|
||||
"get_ayon_server_api_connection",
|
||||
)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import ayon_api
|
||||
|
||||
|
||||
class _GlobalCache:
|
||||
initialized = False
|
||||
|
||||
|
||||
def get_ayon_server_api_connection():
|
||||
return ayon_api.get_server_api_connection()
|
||||
|
|
@ -15,7 +15,18 @@ python_version_dir = os.path.join(
|
|||
sys.path.insert(0, python_version_dir)
|
||||
site.addsitedir(python_version_dir)
|
||||
|
||||
|
||||
from .local_settings import (
|
||||
IniSettingRegistry,
|
||||
JSONSettingRegistry,
|
||||
AYONSecureRegistry,
|
||||
AYONSettingsRegistry,
|
||||
OpenPypeSecureRegistry,
|
||||
OpenPypeSettingsRegistry,
|
||||
get_local_site_id,
|
||||
get_ayon_username,
|
||||
get_openpype_username,
|
||||
)
|
||||
from .ayon_connection import initialize_ayon_connection
|
||||
from .events import (
|
||||
emit_event,
|
||||
register_event_callback
|
||||
|
|
@ -112,18 +123,6 @@ from .transcoding import (
|
|||
get_rescaled_command_arguments,
|
||||
)
|
||||
|
||||
from .local_settings import (
|
||||
IniSettingRegistry,
|
||||
JSONSettingRegistry,
|
||||
AYONSecureRegistry,
|
||||
AYONSettingsRegistry,
|
||||
OpenPypeSecureRegistry,
|
||||
OpenPypeSettingsRegistry,
|
||||
get_local_site_id,
|
||||
get_ayon_username,
|
||||
get_openpype_username,
|
||||
)
|
||||
|
||||
from .applications import (
|
||||
ApplicationLaunchFailed,
|
||||
ApplictionExecutableNotFound,
|
||||
|
|
@ -170,6 +169,18 @@ from .connections import (
|
|||
terminal = Terminal
|
||||
|
||||
__all__ = [
|
||||
"IniSettingRegistry",
|
||||
"JSONSettingRegistry",
|
||||
"AYONSecureRegistry",
|
||||
"AYONSettingsRegistry",
|
||||
"OpenPypeSecureRegistry",
|
||||
"OpenPypeSettingsRegistry",
|
||||
"get_local_site_id",
|
||||
"get_ayon_username",
|
||||
"get_openpype_username",
|
||||
|
||||
"initialize_ayon_connection",
|
||||
|
||||
"emit_event",
|
||||
"register_event_callback",
|
||||
|
||||
|
|
@ -228,16 +239,6 @@ __all__ = [
|
|||
"convert_ffprobe_fps_to_float",
|
||||
"get_rescaled_command_arguments",
|
||||
|
||||
"IniSettingRegistry",
|
||||
"JSONSettingRegistry",
|
||||
"AYONSecureRegistry",
|
||||
"AYONSettingsRegistry",
|
||||
"OpenPypeSecureRegistry",
|
||||
"OpenPypeSettingsRegistry",
|
||||
"get_local_site_id",
|
||||
"get_ayon_username",
|
||||
"get_openpype_username",
|
||||
|
||||
"ApplicationLaunchFailed",
|
||||
"ApplictionExecutableNotFound",
|
||||
"ApplicationNotFound",
|
||||
|
|
|
|||
34
client/ayon_core/lib/ayon_connection.py
Normal file
34
client/ayon_core/lib/ayon_connection.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import os
|
||||
|
||||
import ayon_api
|
||||
|
||||
from .local_settings import get_local_site_id
|
||||
|
||||
|
||||
class _Cache:
|
||||
initialized = False
|
||||
|
||||
|
||||
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
|
||||
site_id = get_local_site_id()
|
||||
version = os.getenv("AYON_VERSION")
|
||||
if ayon_api.is_connection_created():
|
||||
con = ayon_api.get_server_api_connection()
|
||||
con.set_site_id(site_id)
|
||||
con.set_client_version(version)
|
||||
else:
|
||||
ayon_api.create_connection(site_id, version)
|
||||
|
|
@ -26,8 +26,7 @@ except ImportError:
|
|||
|
||||
import six
|
||||
import appdirs
|
||||
|
||||
from ayon_core.client import get_ayon_server_api_connection
|
||||
import ayon_api
|
||||
|
||||
_PLACEHOLDER = object()
|
||||
|
||||
|
|
@ -556,10 +555,9 @@ def get_ayon_username():
|
|||
|
||||
Returns:
|
||||
str: Username.
|
||||
"""
|
||||
|
||||
con = get_ayon_server_api_connection()
|
||||
return con.get_user()["name"]
|
||||
"""
|
||||
return ayon_api.get_user()["name"]
|
||||
|
||||
|
||||
def get_openpype_username():
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ from pyblish.lib import MessageHandler
|
|||
from ayon_core import AYON_CORE_ROOT
|
||||
from ayon_core.host import HostBase
|
||||
from ayon_core.client import get_ayon_server_api_connection
|
||||
from ayon_core.lib import is_in_tests
|
||||
from ayon_core.lib.events import emit_event
|
||||
from ayon_core.lib import is_in_tests, initialize_ayon_connection, emit_event
|
||||
from ayon_core.addon import load_addons, AddonsManager
|
||||
from ayon_core.settings import get_project_settings
|
||||
|
||||
|
|
@ -157,6 +156,7 @@ def install_host(host):
|
|||
|
||||
def install_ayon_plugins(project_name=None, host_name=None):
|
||||
# Make sure modules are loaded
|
||||
initialize_ayon_connection()
|
||||
load_addons()
|
||||
|
||||
log.info("Registering global plug-ins..")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import collections
|
|||
import copy
|
||||
import time
|
||||
|
||||
from ayon_core.client import get_ayon_server_api_connection
|
||||
import ayon_api
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -46,8 +46,7 @@ class _AyonSettingsCache:
|
|||
@classmethod
|
||||
def _use_bundles(cls):
|
||||
if _AyonSettingsCache.use_bundles is None:
|
||||
con = get_ayon_server_api_connection()
|
||||
major, minor, _, _, _ = con.get_server_version_tuple()
|
||||
major, minor, _, _, _ = ayon_api.get_server_version_tuple()
|
||||
use_bundles = True
|
||||
if (major, minor) < (0, 3):
|
||||
use_bundles = False
|
||||
|
|
@ -69,8 +68,7 @@ class _AyonSettingsCache:
|
|||
_AyonSettingsCache.variant = variant
|
||||
|
||||
# Set the variant to global ayon api connection
|
||||
con = get_ayon_server_api_connection()
|
||||
con.set_default_settings_variant(variant)
|
||||
ayon_api.set_default_settings_variant(variant)
|
||||
return _AyonSettingsCache.variant
|
||||
|
||||
@classmethod
|
||||
|
|
@ -81,23 +79,21 @@ class _AyonSettingsCache:
|
|||
def get_value_by_project(cls, project_name):
|
||||
cache_item = _AyonSettingsCache.cache_by_project_name[project_name]
|
||||
if cache_item.is_outdated:
|
||||
con = get_ayon_server_api_connection()
|
||||
if cls._use_bundles():
|
||||
value = con.get_addons_settings(
|
||||
value = ayon_api.get_addons_settings(
|
||||
bundle_name=cls._get_bundle_name(),
|
||||
project_name=project_name,
|
||||
variant=cls._get_variant()
|
||||
)
|
||||
else:
|
||||
value = con.get_addons_settings(project_name)
|
||||
value = ayon_api.get_addons_settings(project_name)
|
||||
cache_item.update_value(value)
|
||||
return cache_item.get_value()
|
||||
|
||||
@classmethod
|
||||
def _get_addon_versions_from_bundle(cls):
|
||||
con = get_ayon_server_api_connection()
|
||||
expected_bundle = cls._get_bundle_name()
|
||||
bundles = con.get_bundles()["bundles"]
|
||||
bundles = ayon_api.get_bundles()["bundles"]
|
||||
bundle = next(
|
||||
(
|
||||
bundle
|
||||
|
|
@ -117,8 +113,7 @@ class _AyonSettingsCache:
|
|||
if cls._use_bundles():
|
||||
addons = cls._get_addon_versions_from_bundle()
|
||||
else:
|
||||
con = get_ayon_server_api_connection()
|
||||
settings_data = con.get_addons_settings(
|
||||
settings_data = ayon_api.get_addons_settings(
|
||||
only_values=False,
|
||||
variant=cls._get_variant()
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue