From 35e25feff8e3aa3dd2da6447fd2c4de1373cd5be Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 20 Apr 2020 18:52:07 +0200 Subject: [PATCH] `interface` and `_interface` moved to action handler --- pype/ftrack/lib/ftrack_action_handler.py | 42 ++++++++++++++++++++++++ pype/ftrack/lib/ftrack_base_handler.py | 28 ---------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/pype/ftrack/lib/ftrack_action_handler.py b/pype/ftrack/lib/ftrack_action_handler.py index af1a9d0811..81c6421f52 100644 --- a/pype/ftrack/lib/ftrack_action_handler.py +++ b/pype/ftrack/lib/ftrack_action_handler.py @@ -94,6 +94,48 @@ class BaseAction(BaseHandler): ''' return False + + def _interface(self, session, entities, event): + interface = self.interface(session, entities, event) + if not interface: + return + + if isinstance(interface, (tuple, list)): + return {"items": interface} + + if isinstance(interface, dict): + if ( + "items" in interface + or ("success" in interface and "message" in interface) + ): + return interface + + raise ValueError(( + "Invalid interface output expected key: \"items\" or keys:" + " \"success\" and \"message\". Got: \"{}\"" + ).format(str(interface))) + + raise ValueError( + "Invalid interface output type \"{}\"".format( + str(type(interface)) + ) + ) + + def interface(self, session, entities, event): + '''Return a interface if applicable or None + + *session* is a `ftrack_api.Session` instance + + *entities* is a list of tuples each containing the entity type and + the entity id. If the entity is a hierarchical you will always get the + entity type TypedContext, once retrieved through a get operation you + will have the "real" entity type ie. example Shot, Sequence + or Asset Build. + + *event* the unmodified original event + ''' + return None + def _launch(self, event): entities = self._translate_event(event) diff --git a/pype/ftrack/lib/ftrack_base_handler.py b/pype/ftrack/lib/ftrack_base_handler.py index 6bbbd2f487..911a8c7bb8 100644 --- a/pype/ftrack/lib/ftrack_base_handler.py +++ b/pype/ftrack/lib/ftrack_base_handler.py @@ -318,34 +318,6 @@ class BaseHandler(object): return False - def _interface(self, *args): - interface = self.interface(*args) - if interface: - if ( - 'items' in interface or - ('success' in interface and 'message' in interface) - ): - return interface - - return { - 'items': interface - } - - def interface(self, session, entities, event): - '''Return a interface if applicable or None - - *session* is a `ftrack_api.Session` instance - - *entities* is a list of tuples each containing the entity type and the entity id. - If the entity is a hierarchical you will always get the entity - type TypedContext, once retrieved through a get operation you - will have the "real" entity type ie. example Shot, Sequence - or Asset Build. - - *event* the unmodified original event - ''' - return None - def _handle_result(self, session, result, entities, event): '''Validate the returned result from the action callback''' if isinstance(result, bool):