Skip to content

Commit

Permalink
Merge pull request #33 from ynput/bugfix/refactor_settings_fix_31
Browse files Browse the repository at this point in the history
Refactor Settings and fix launch environment
  • Loading branch information
BigRoy authored Sep 2, 2024
2 parents 7ccbf64 + 6532896 commit 569f79e
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 378 deletions.
26 changes: 13 additions & 13 deletions Docs/Ayon_Docs/Admin_Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
> LakeFs keys (LakeFs is the data server we use to distribute Bin data) you can
> get those Keys on our Discord server just ask one of the Ynput staff for them.
> the settings are the following:
> `ayon+settings://ayon_usd/LakeFs_Settings/access_key_id` and
> `ayon+settings://ayon_usd/LakeFs_Settings/secret_access_key`
> `ayon+settings://ayon_usd/lakefs/access_key_id` and
> `ayon+settings://ayon_usd/lakefs/secret_access_key`
USD is a modern, open-source, scene description and file format developed by
Pixar Animation Studios. It's an Extensive and extendable C++Lib that is used
Expand Down Expand Up @@ -42,22 +42,22 @@ need to touch them tho.

#### LakeFs Config

**LakeFs Settings:** `ayon+settings://ayon_usd/LakeFs_Settings`\
**LakeFs Settings:** `ayon+settings://ayon_usd/lakefs`\
LakeFs is the backend of our bin distribution system the addon will use the
specified server to download the resolvers and AyonUsdLibs from LakeFs.

**LakeFs Server Uri:**
`ayon+settings://ayon_usd/LakeFs_Settings/ayon_usd_lake_fs_server_repo`\
`ayon+settings://ayon_usd/lakefs/server_repo`\
this is the Uri used to host the LakeFs server. the Ynput server can be found at
`https://lake.ayon.cloud`

**LakeFs Repository Uri:**
`ayon+settings://ayon_usd/LakeFs_Settings/ayon_usd_lake_fs_server_repo`\
`ayon+settings://ayon_usd/lakefs/server_repo`\
this is a LakeFs internal link that also specifies the branch your downloading
from.\
this can be great if you want to pin your pipeline to a specific release.

**Asset Resolvers:** `ayon+settings://ayon_usd/LakeFs_Settings/asset_resolvers`\
**Asset Resolvers:** `ayon+settings://ayon_usd/lakefs/asset_resolvers`\
allows you to associate a specific Application name with a specific resolver.\
we always set up all the resolvers we compile but if you have special App_Names
in your Applications then you might want to add an App Alias.\
Expand All @@ -66,32 +66,32 @@ it as an alias for the Hou19.5 entry because they share the same resolver.

#### Usd Resolver Config

`ayon+settings://ayon_usd/Ayon_UsdResolver_Settings`
`ayon+settings://ayon_usd/ayon_usd_resolver`

**Log Lvl** `ayon+settings://ayon_usd/Ayon_UsdResolver_Settings/ayon_log_lvl`
**Log Lvl** `ayon+settings://ayon_usd/ayon_usd_resolver/ayon_log_lvl`
control the log lvl of the AyonUsdResolver. It is advised to have this at Warn
or Critical as Logging will impact the performance.

**File Logger Enabled**
`ayon+settings://ayon_usd/Ayon_UsdResolver_Settings/ayon_file_logger_enabled`
`ayon+settings://ayon_usd/ayon_usd_resolver/ayon_file_logger_enabled`
AyonUsdResolver includes a file logger if needed.

**Logging Keys**
`ayon+settings://ayon_usd/Ayon_UsdResolver_Settings/ayon_logger_logging_keys`
`ayon+settings://ayon_usd/ayon_usd_resolver/ayon_logger_logging_keys`
AyonUsdResolver Logger has a few predefined logging keys that can be enabled for
Debugging. it is advised to only do this with Developer bundles as it can expose
AYON Server data. it will also generate quite a big output.

**File Logger Path**
`ayon+settings://ayon_usd/Ayon_UsdResolver_Settings/file_logger_file_path` The
`ayon+settings://ayon_usd/ayon_usd_resolver/file_logger_file_path` The
Ayon File Logger needs an output path this needs to be a relative or absolute
path to a folder.

#### UsdLib Config:

`ayon+settings://ayon_usd/Usd_Settings`
`ayon+settings://ayon_usd/usd`

**Tf_Debug** `ayon+settings://ayon_usd/Usd_Settings/usd_tf_debug`\
**Tf_Debug** `ayon+settings://ayon_usd/usd/usd_tf_debug`\
this allows you to set the UsdTfDebug env variable to get extra debug info from
the UsdLib.\
[Usd Survival Guide (Luca Sheller)](https://lucascheller.github.io/VFX-UsdSurvivalGuide/core/profiling/debug.html)\
Expand Down
4 changes: 1 addition & 3 deletions client/ayon_usd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

from .addon import USDAddon
from .utils import (
get_download_dir,
get_downloaded_usd_root,
get_download_dir
)
from .ayon_bin_client.ayon_bin_distro.util.zip import extract_zip_file

__all__ = (
"USDAddon",
"get_downloaded_usd_root",
"extract_zip_file",
"get_download_dir",
)
82 changes: 47 additions & 35 deletions client/ayon_usd/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
from ayon_core.addon import AYONAddon, ITrayAddon

from ayon_core import style
from ayon_core.settings import get_studio_settings

from . import config, utils
from .utils import ADDON_DATA_JSON_PATH, DOWNLOAD_DIR, USD_ADDON_ROOT_DIR
from .version import __version__

from .ayon_bin_client.ayon_bin_distro.gui import progress_ui
from .ayon_bin_client.ayon_bin_distro.work_handler import worker
Expand All @@ -24,8 +27,8 @@ class USDAddon(AYONAddon, ITrayAddon):
Cares about supplying USD Framework.
"""

name = config.ADDON_NAME
version = config.ADDON_VERSION
name = "ayon_usd"
version = __version__
_download_window = None

def tray_init(self):
Expand All @@ -36,7 +39,11 @@ def initialize(self, module_settings):
"""Initialize USD Addon."""
if not module_settings["ayon_usd"]["allow_addon_start"]:
raise SystemError(
"The experimental AyonUsd addon is currently activated, but you haven't yet acknowledged the user agreement indicating your understanding that this feature is experimental. Please go to the Studio settings and check the agreement checkbox."
"The experimental AyonUsd addon is currently activated, "
"but you haven't yet acknowledged the user agreement "
"indicating your understanding that this feature is "
"experimental. Please go to the Studio Settings and "
"check the agreement checkbox."
)
self.enabled = True
self._download_window = None
Expand All @@ -46,64 +53,69 @@ def tray_start(self):
Download USD if needed.
"""
super(USDAddon, self).tray_start()

if not os.path.exists(config.DOWNLOAD_DIR):
os.makedirs(config.DOWNLOAD_DIR, exist_ok=True)
if os.path.exists(str(config.DOWNLOAD_DIR) + ".zip"):
os.remove(str(config.DOWNLOAD_DIR) + ".zip")
if not os.path.exists(config.ADDON_DATA_JSON_PATH):
with open(config.ADDON_DATA_JSON_PATH, "w+") as data_json:
init_data = {}
init_data["ayon_usd_addon_first_init_utc"] = str(
datetime.now().astimezone(timezone.utc)
)
json.dump(
init_data,
data_json,
)

if not utils.is_usd_lib_download_needed():

os.makedirs(DOWNLOAD_DIR, exist_ok=True)

if not os.path.exists(ADDON_DATA_JSON_PATH):
now = datetime.now().astimezone(timezone.utc)
with open(ADDON_DATA_JSON_PATH, "w+") as json_file:
init_data = {
"ayon_usd_addon_first_init_utc": str(now)
}
json.dump(init_data, json_file)

settings = get_studio_settings()
if not utils.is_usd_lib_download_needed(settings):
print("usd is already downloaded")
return

lake_fs_usd_lib_path = f"{config.get_addon_settings_value(config.get_addon_settings(),config.ADDON_SETTINGS_LAKE_FS_REPO_URI)}{config.get_usd_lib_conf_from_lakefs()}"
lake_fs_usd_lib_path = config.get_lakefs_usdlib_path(settings)

# Get modified time on LakeFS
lake_fs = config.get_global_lake_instance(settings)
usd_lib_lake_fs_time_cest = (
config.get_global_lake_instance()
lake_fs
.get_element_info(lake_fs_usd_lib_path)
.get("Modified Time")
)
if not usd_lib_lake_fs_time_cest:
raise ValueError("could not find UsdLib time stamp on LakeFs server")
raise ValueError(
"Unable to find UsdLib date modified timestamp on "
f"LakeFs server: {lake_fs_usd_lib_path}"
)

with open(config.ADDON_DATA_JSON_PATH, "r+") as data_json:
addon_data_json = json.load(data_json)
with open(ADDON_DATA_JSON_PATH, "r+") as json_file:
addon_data_json = json.load(json_file)
addon_data_json["usd_lib_lake_fs_time_cest"] = usd_lib_lake_fs_time_cest

data_json.seek(0)
json_file.seek(0)
json.dump(
addon_data_json,
data_json,
json_file,
)
data_json.truncate()
json_file.truncate()

controller = worker.Controller()

usd_download_work_item = controller.construct_work_item(
func=config.get_global_lake_instance().clone_element,
func=lake_fs.clone_element,
kwargs={
"lake_fs_object_uir": lake_fs_usd_lib_path,
"dist_path": config.DOWNLOAD_DIR,
"dist_path": DOWNLOAD_DIR,
},
progress_title="Download UsdLib",
)

usd_zip_path = os.path.join(
DOWNLOAD_DIR,
os.path.basename(config.get_lakefs_usdlib_path(settings))
)
usd_lib_path = os.path.splitext(usd_zip_path)[0]
controller.construct_work_item(
func=zip.extract_zip_file,
kwargs={
"zip_file_path": config.USD_ZIP_PATH,
"dest_dir": config.USD_LIB_PATH,
"zip_file_path": usd_zip_path,
"dest_dir": usd_lib_path,
},
progress_title="Unzip UsdLib",
dependency_id=[usd_download_work_item.get_uuid()],
Expand All @@ -114,7 +126,7 @@ def tray_start(self):
close_on_finish=True,
auto_close_timeout=1,
delet_progress_bar_on_finish=False,
title=f"{config.ADDON_NAME}-Addon [UsdLib Download]",
title="ayon_usd-Addon [UsdLib Download]",
)
download_ui.setStyleSheet(style.load_stylesheet())
download_ui.start()
Expand All @@ -130,4 +142,4 @@ def tray_menu(self, tray_menu):

def get_launch_hook_paths(self):
"""Get paths to launch hooks."""
return [os.path.join(config.USD_ADDON_DIR, "hooks")]
return [os.path.join(USD_ADDON_ROOT_DIR, "hooks")]
Loading

0 comments on commit 569f79e

Please sign in to comment.