-
Notifications
You must be signed in to change notification settings - Fork 1
/
construct_entity_type.py
45 lines (32 loc) · 1.37 KB
/
construct_entity_type.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# :coding: utf-8
# :copyright: Copyright (c) 2014 ftrack
import logging
import ftrack_api.entity.factory
class Factory(ftrack_api.entity.factory.StandardFactory):
"""Entity class factory."""
def create(self, schema, bases=None):
"""Create and return entity class from *schema*."""
# Optionally change bases for class to be generated.
cls = super(Factory, self).create(schema, bases=bases)
# Further customise cls before returning.
return cls
def register(session):
"""Register plugin with *session*."""
logger = logging.getLogger("ftrack_plugin:construct_entity_type.register")
# Validate that session is an instance of ftrack_api.Session. If not, assume
# that register is being called from an old or incompatible API and return
# without doing anything.
if not isinstance(session, ftrack_api.Session):
logger.debug(
"Not subscribing plugin as passed argument {0!r} is not an "
"ftrack_api.Session instance.".format(session)
)
return
factory = Factory()
def construct_entity_type(event):
"""Return class to represent entity type specified by *event*."""
schema = event["data"]["schema"]
return factory.create(schema)
session.event_hub.subscribe(
"topic=ftrack.api.session.construct-entity-type", construct_entity_type
)