mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
added 'ensure_is_process_ready' method to addon base class
This commit is contained in:
parent
5afed52bd9
commit
ec419f5569
1 changed files with 72 additions and 0 deletions
|
|
@ -67,6 +67,56 @@ MOVED_ADDON_MILESTONE_VERSIONS = {
|
|||
}
|
||||
|
||||
|
||||
class ProcessPreparationError(Exception):
|
||||
"""Exception that can be used when process preparation failed.
|
||||
|
||||
The message is showed to user (either as UI dialog or printed). If
|
||||
different error is raised a "generic" error message is showed to user
|
||||
with option to copy error message to clipboard.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ProcessContext:
|
||||
"""Context of child process.
|
||||
|
||||
Notes:
|
||||
This class is used to pass context to child process. It can be used
|
||||
to use different behavior of addon based on information in
|
||||
the context.
|
||||
The context can be enhanced in future versions.
|
||||
|
||||
Args:
|
||||
addon_name (Optional[str]): Addon name which triggered process.
|
||||
addon_version (Optional[str]): Addon version which triggered process.
|
||||
project_name (Optional[str]): Project name. Can be filled in case
|
||||
process is triggered for specific project. Some addons can have
|
||||
different behavior based on project.
|
||||
headless (Optional[bool]): Is process running in headless mode.
|
||||
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
addon_name: Optional[str] = None,
|
||||
addon_version: Optional[str] = None,
|
||||
project_name: Optional[str] = None,
|
||||
headless: Optional[bool] = None,
|
||||
**kwargs,
|
||||
):
|
||||
if headless is None:
|
||||
# TODO use lib function to get headless mode
|
||||
headless = os.getenv("AYON_HEADLESS_MODE") == "1"
|
||||
self.addon_name: Optional[str] = addon_name
|
||||
self.addon_version: Optional[str] = addon_version
|
||||
self.project_name: Optional[str] = project_name
|
||||
self.headless: bool = headless
|
||||
|
||||
if kwargs:
|
||||
unknown_keys = ", ".join([f'"{key}"' for key in kwargs.keys()])
|
||||
print(f"Unknown keys in ProcessContext: {unknown_keys}")
|
||||
|
||||
|
||||
# Inherit from `object` for Python 2 hosts
|
||||
class _ModuleClass(object):
|
||||
"""Fake module class for storing AYON addons.
|
||||
|
|
@ -588,7 +638,29 @@ class AYONAddon(object):
|
|||
Args:
|
||||
enabled_addons (list[AYONAddon]): Addons that are enabled.
|
||||
"""
|
||||
pass
|
||||
|
||||
def ensure_is_process_ready(
|
||||
self, process_context: ProcessContext
|
||||
):
|
||||
"""Make sure addon is prepared for a process.
|
||||
|
||||
This method is called when some action makes sure that addon has set
|
||||
necessary data. For example if user should be logged in
|
||||
and filled credentials in environment variables this method should
|
||||
ask user for credentials.
|
||||
|
||||
Implementation of this method is optional.
|
||||
|
||||
Note:
|
||||
The logic can be similar to logic in tray, but in tray not require
|
||||
to be logged in.
|
||||
|
||||
Args:
|
||||
process_context (ProcessContext): Context of child
|
||||
process.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_global_environments(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue