mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
implemented ILaunchHookPaths interface
This commit is contained in:
parent
d4f18fedba
commit
3fec8b293a
2 changed files with 49 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ from .base import (
|
||||||
ITrayAction,
|
ITrayAction,
|
||||||
ITrayService,
|
ITrayService,
|
||||||
IPluginPaths,
|
IPluginPaths,
|
||||||
|
ILaunchHookPaths,
|
||||||
ModulesManager,
|
ModulesManager,
|
||||||
TrayModulesManager
|
TrayModulesManager
|
||||||
)
|
)
|
||||||
|
|
@ -45,6 +46,7 @@ __all__ = (
|
||||||
"ITrayAction",
|
"ITrayAction",
|
||||||
"ITrayService",
|
"ITrayService",
|
||||||
"IPluginPaths",
|
"IPluginPaths",
|
||||||
|
"ILaunchHookPaths",
|
||||||
"ModulesManager",
|
"ModulesManager",
|
||||||
"TrayModulesManager",
|
"TrayModulesManager",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,19 @@ class IPluginPaths:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(ABCMeta)
|
||||||
|
class ILaunchHookPaths:
|
||||||
|
"""Module has launch hook paths to return.
|
||||||
|
|
||||||
|
Expected result is list of paths.
|
||||||
|
["path/to/launch_hooks_dir"]
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_launch_hook_paths(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(ABCMeta)
|
@six.add_metaclass(ABCMeta)
|
||||||
class ITrayModule:
|
class ITrayModule:
|
||||||
"""Module has special procedures when used in Pype Tray.
|
"""Module has special procedures when used in Pype Tray.
|
||||||
|
|
@ -421,6 +434,40 @@ class ModulesManager:
|
||||||
).format(expected_keys, " | ".join(msg_items)))
|
).format(expected_keys, " | ".join(msg_items)))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def collect_launch_hook_paths(self):
|
||||||
|
"""Helper to collect hooks from modules inherited ILaunchHookPaths.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: Paths to launch hook directories.
|
||||||
|
"""
|
||||||
|
str_type = type("")
|
||||||
|
expected_types = (list, tuple, set)
|
||||||
|
|
||||||
|
output = []
|
||||||
|
for module in self.get_enabled_modules():
|
||||||
|
# Skip module that do not inherit from `ILaunchHookPaths`
|
||||||
|
if not isinstance(module, ILaunchHookPaths):
|
||||||
|
continue
|
||||||
|
|
||||||
|
hook_paths = module.get_launch_hook_paths()
|
||||||
|
if not hook_paths:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Convert string to list
|
||||||
|
if isinstance(hook_paths, str_type):
|
||||||
|
hook_paths = [hook_paths]
|
||||||
|
|
||||||
|
# Skip invalid types
|
||||||
|
if not isinstance(hook_paths, expected_types):
|
||||||
|
self.log.warning((
|
||||||
|
"Result of `get_launch_hook_paths`"
|
||||||
|
" has invalid type {}. Expected {}"
|
||||||
|
).format(type(hook_paths), expected_types))
|
||||||
|
continue
|
||||||
|
|
||||||
|
output.extend(hook_paths)
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
class TrayModulesManager(ModulesManager):
|
class TrayModulesManager(ModulesManager):
|
||||||
# Define order of modules in menu
|
# Define order of modules in menu
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue