removed content of legacy_io

This commit is contained in:
Jakub Trllo 2024-02-08 19:10:49 +01:00
parent e02883dcd4
commit eedf736867

View file

@ -1,109 +1,36 @@
"""Wrapper around interactions with the database"""
import os
import sys
import logging
import functools
from . import schema
module = sys.modules[__name__]
from ayon_core.pipeline import get_current_project_name
Session = {}
_is_installed = False
log = logging.getLogger(__name__)
SESSION_CONTEXT_KEYS = (
# Name of current Project
"AVALON_PROJECT",
# Name of current Asset
"AVALON_ASSET",
# Name of current task
"AVALON_TASK",
# Name of current app
"AVALON_APP",
# Path to working directory
"AVALON_WORKDIR",
# Optional path to scenes directory (see Work Files API)
"AVALON_SCENEDIR"
log.warning(
"DEPRECATION WARNING: 'legacy_io' is deprecated and will be removed in"
" future versions of ayon-core addon."
"\nReading from Session won't give you updated information and changing"
" values won't affect global state of a process."
)
def session_data_from_environment(context_keys=False):
session_data = {}
if context_keys:
for key in SESSION_CONTEXT_KEYS:
value = os.environ.get(key)
session_data[key] = value or ""
else:
for key in SESSION_CONTEXT_KEYS:
session_data[key] = None
for key, default_value in (
# Name of Avalon in graphical user interfaces
# Use this to customise the visual appearance of Avalon
# to better integrate with your surrounding pipeline
("AVALON_LABEL", "Avalon"),
# Used during any connections to the outside world
("AVALON_TIMEOUT", "1000"),
# Name of database used in MongoDB
("AVALON_DB", "avalon"),
):
value = os.environ.get(key) or default_value
if value is not None:
session_data[key] = value
return session_data
return {}
def is_installed():
return module._is_installed
return False
def install():
"""Establish a persistent connection to the database"""
if is_installed():
return
session = session_data_from_environment(context_keys=True)
session["schema"] = "openpype:session-4.0"
try:
schema.validate(session)
except schema.ValidationError as e:
# TODO(marcus): Make this mandatory
log.warning(e)
Session.update(session)
module._is_installed = True
pass
def uninstall():
"""Close any connection to the database.
Deprecated:
This function does nothing should be removed.
"""
module._is_installed = False
pass
def requires_install(func):
@functools.wraps(func)
def decorated(*args, **kwargs):
if not is_installed():
install()
return func(*args, **kwargs)
return decorated
@requires_install
def active_project(*args, **kwargs):
return Session["AVALON_PROJECT"]
return get_current_project_name()
def current_project(*args, **kwargs):
return Session.get("AVALON_PROJECT")
return get_current_project_name()