mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 21:32:15 +01:00
90 lines
1.8 KiB
Python
90 lines
1.8 KiB
Python
import os
|
|
import sys
|
|
import appdirs
|
|
|
|
IS_BUILT_APPLICATION = getattr(sys, "frozen", False)
|
|
|
|
|
|
def get_ayon_appdirs(*args):
|
|
"""Local app data directory of AYON client.
|
|
|
|
Args:
|
|
*args (Iterable[str]): Subdirectories/files in local app data dir.
|
|
|
|
Returns:
|
|
str: Path to directory/file in local app data dir.
|
|
"""
|
|
|
|
return os.path.join(
|
|
appdirs.user_data_dir("AYON", "Ynput"),
|
|
*args
|
|
)
|
|
|
|
|
|
def is_staging_enabled():
|
|
"""Check if staging is enabled.
|
|
|
|
Returns:
|
|
bool: True if staging is enabled.
|
|
"""
|
|
|
|
return os.getenv("AYON_USE_STAGING") == "1"
|
|
|
|
|
|
def _create_local_site_id():
|
|
"""Create a local site identifier.
|
|
|
|
Returns:
|
|
str: Randomly generated site id.
|
|
"""
|
|
|
|
from coolname import generate_slug
|
|
|
|
new_id = generate_slug(3)
|
|
|
|
print("Created local site id \"{}\"".format(new_id))
|
|
|
|
return new_id
|
|
|
|
|
|
def get_local_site_id():
|
|
"""Get local site identifier.
|
|
|
|
Site id is created if does not exist yet.
|
|
|
|
Returns:
|
|
str: Site id.
|
|
"""
|
|
|
|
# used for background syncing
|
|
site_id = os.environ.get("AYON_SITE_ID")
|
|
if site_id:
|
|
return site_id
|
|
|
|
site_id_path = get_ayon_appdirs("site_id")
|
|
if os.path.exists(site_id_path):
|
|
with open(site_id_path, "r") as stream:
|
|
site_id = stream.read()
|
|
|
|
if not site_id:
|
|
site_id = _create_local_site_id()
|
|
with open(site_id_path, "w") as stream:
|
|
stream.write(site_id)
|
|
return site_id
|
|
|
|
|
|
def get_ayon_launch_args(*args):
|
|
"""Launch arguments that can be used to launch ayon process.
|
|
|
|
Args:
|
|
*args (str): Additional arguments.
|
|
|
|
Returns:
|
|
list[str]: Launch arguments.
|
|
"""
|
|
|
|
output = [sys.executable]
|
|
if not IS_BUILT_APPLICATION:
|
|
output.append(sys.argv[0])
|
|
output.extend(args)
|
|
return output
|