implemented ILaunchHookPaths interface

This commit is contained in:
iLLiCiTiT 2020-12-22 10:47:05 +01:00
parent d4f18fedba
commit 3fec8b293a
2 changed files with 49 additions and 0 deletions

View file

@ -5,6 +5,7 @@ from .base import (
ITrayAction,
ITrayService,
IPluginPaths,
ILaunchHookPaths,
ModulesManager,
TrayModulesManager
)
@ -45,6 +46,7 @@ __all__ = (
"ITrayAction",
"ITrayService",
"IPluginPaths",
"ILaunchHookPaths",
"ModulesManager",
"TrayModulesManager",

View file

@ -84,6 +84,19 @@ class IPluginPaths:
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)
class ITrayModule:
"""Module has special procedures when used in Pype Tray.
@ -421,6 +434,40 @@ class ModulesManager:
).format(expected_keys, " | ".join(msg_items)))
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):
# Define order of modules in menu