Merge branch 'develop' into bugfix/fix_anatomy_format

This commit is contained in:
robin 2024-08-19 08:14:09 -04:00
commit 2ccadd8ed1
6 changed files with 102 additions and 59 deletions

View file

@ -12,12 +12,15 @@ from uuid import uuid4
from abc import ABC, abstractmethod
from typing import Optional
import appdirs
import ayon_api
from semver import VersionInfo
from ayon_core import AYON_CORE_ROOT
from ayon_core.lib import Logger, is_dev_mode_enabled
from ayon_core.lib import (
Logger,
is_dev_mode_enabled,
get_launcher_storage_dir,
)
from ayon_core.settings import get_studio_settings
from .interfaces import (
@ -327,10 +330,7 @@ def _load_ayon_addons(openpype_modules, modules_key, log):
addons_dir = os.environ.get("AYON_ADDONS_DIR")
if not addons_dir:
addons_dir = os.path.join(
appdirs.user_data_dir("AYON", "Ynput"),
"addons"
)
addons_dir = get_launcher_storage_dir("addons")
dev_mode_enabled = is_dev_mode_enabled()
dev_addons_info = {}

View file

@ -9,6 +9,8 @@ from .local_settings import (
AYONSettingsRegistry,
OpenPypeSecureRegistry,
OpenPypeSettingsRegistry,
get_launcher_local_dir,
get_launcher_storage_dir,
get_local_site_id,
get_ayon_username,
get_openpype_username,
@ -144,6 +146,8 @@ __all__ = [
"AYONSettingsRegistry",
"OpenPypeSecureRegistry",
"OpenPypeSettingsRegistry",
"get_launcher_local_dir",
"get_launcher_storage_dir",
"get_local_site_id",
"get_ayon_username",
"get_openpype_username",

View file

@ -3,6 +3,7 @@
import os
import json
import platform
import warnings
from datetime import datetime
from abc import ABC, abstractmethod
@ -30,6 +31,87 @@ import ayon_api
_PLACEHOLDER = object()
def _get_ayon_appdirs(*args):
return os.path.join(
appdirs.user_data_dir("AYON", "Ynput"),
*args
)
def get_ayon_appdirs(*args):
"""Local app data directory of AYON client.
Deprecated:
Use 'get_launcher_local_dir' or 'get_launcher_storage_dir' based on
use-case. Deprecation added 24/08/09 (0.4.4-dev.1).
Args:
*args (Iterable[str]): Subdirectories/files in local app data dir.
Returns:
str: Path to directory/file in local app data dir.
"""
warnings.warn(
(
"Function 'get_ayon_appdirs' is deprecated. Should be replaced"
" with 'get_launcher_local_dir' or 'get_launcher_storage_dir'"
" based on use-case."
),
DeprecationWarning
)
return _get_ayon_appdirs(*args)
def get_launcher_storage_dir(*subdirs: str) -> str:
"""Get storage directory for launcher.
Storage directory is used for storing shims, addons, dependencies, etc.
It is not recommended, but the location can be shared across
multiple machines.
Note:
This function should be called at least once on bootstrap.
Args:
*subdirs (str): Subdirectories relative to storage dir.
Returns:
str: Path to storage directory.
"""
storage_dir = os.getenv("AYON_LAUNCHER_STORAGE_DIR")
if not storage_dir:
storage_dir = _get_ayon_appdirs()
return os.path.join(storage_dir, *subdirs)
def get_launcher_local_dir(*subdirs: str) -> str:
"""Get local directory for launcher.
Local directory is used for storing machine or user specific data.
The location is user specific.
Note:
This function should be called at least once on bootstrap.
Args:
*subdirs (str): Subdirectories relative to local dir.
Returns:
str: Path to local directory.
"""
storage_dir = os.getenv("AYON_LAUNCHER_LOCAL_DIR")
if not storage_dir:
storage_dir = _get_ayon_appdirs()
return os.path.join(storage_dir, *subdirs)
class AYONSecureRegistry:
"""Store information using keyring.
@ -470,55 +552,17 @@ class JSONSettingRegistry(ASettingRegistry):
class AYONSettingsRegistry(JSONSettingRegistry):
"""Class handling AYON general settings registry.
Attributes:
vendor (str): Name used for path construction.
product (str): Additional name used for path construction.
Args:
name (Optional[str]): Name of the registry.
"""
def __init__(self, name=None):
self.vendor = "Ynput"
self.product = "AYON"
if not name:
name = "AYON_settings"
path = appdirs.user_data_dir(self.product, self.vendor)
path = get_launcher_storage_dir()
super(AYONSettingsRegistry, self).__init__(name, path)
def _create_local_site_id(registry=None):
"""Create a local site identifier."""
from coolname import generate_slug
if registry is None:
registry = AYONSettingsRegistry()
new_id = generate_slug(3)
print("Created local site id \"{}\"".format(new_id))
registry.set_item("localId", new_id)
return new_id
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 get_local_site_id():
"""Get local site identifier.
@ -529,7 +573,7 @@ def get_local_site_id():
if site_id:
return site_id
site_id_path = get_ayon_appdirs("site_id")
site_id_path = get_launcher_local_dir("site_id")
if os.path.exists(site_id_path):
with open(site_id_path, "r") as stream:
site_id = stream.read()

View file

@ -4,7 +4,7 @@ import collections
import ayon_api
from ayon_core.lib.local_settings import get_ayon_appdirs
from ayon_core.lib.local_settings import get_launcher_local_dir
FileInfo = collections.namedtuple(
@ -54,7 +54,7 @@ class ThumbnailsCache:
"""
if self._thumbnails_dir is None:
self._thumbnails_dir = get_ayon_appdirs("thumbnails")
self._thumbnails_dir = get_launcher_local_dir("thumbnails")
return self._thumbnails_dir
thumbnails_dir = property(get_thumbnails_dir)

View file

@ -2,11 +2,11 @@ import os
import json
import uuid
import appdirs
import arrow
from qtpy import QtWidgets, QtCore, QtGui
from ayon_core import style
from ayon_core.lib import get_launcher_local_dir
from ayon_core.resources import get_ayon_icon_filepath
from ayon_core.tools import resources
from ayon_core.tools.utils import (
@ -35,12 +35,8 @@ def get_reports_dir():
str: Path to directory where reports are stored.
"""
report_dir = os.path.join(
appdirs.user_data_dir("AYON", "Ynput"),
"publish_report_viewer"
)
if not os.path.exists(report_dir):
os.makedirs(report_dir)
report_dir = get_launcher_local_dir("publish_report_viewer")
os.makedirs(report_dir, exist_ok=True)
return report_dir
@ -576,8 +572,7 @@ class LoadedFilesWidget(QtWidgets.QWidget):
filepaths = []
for url in mime_data.urls():
filepath = url.toLocalFile()
ext = os.path.splitext(filepath)[-1]
if os.path.exists(filepath) and ext == ".json":
if os.path.exists(filepath):
filepaths.append(filepath)
self._add_filepaths(filepaths)
event.accept()

View file

@ -19,7 +19,7 @@ from ayon_core.lib import (
run_detached_process,
get_ayon_username,
)
from ayon_core.lib.local_settings import get_ayon_appdirs
from ayon_core.lib.local_settings import get_launcher_local_dir
class TrayState:
@ -146,7 +146,7 @@ def get_tray_storage_dir() -> str:
str: Tray storage directory where metadata files are stored.
"""
return get_ayon_appdirs("tray")
return get_launcher_local_dir("tray")
def _get_tray_info_filepath(