+# :copyright: Copyright (c) 2019 ftrack
+logger = logging.getLogger(__name__)
+def callback(session, event):
+ '''Dynamic enumerator callback.'''
+ logger.info(u'Running callback for event: {}'.format(event))
+ attribute_name = event['data']['attributeName']
+ if attribute_name == 'asset_build':
+ entityId = event['data']['recordData']['entity']['entityId']
+ # Query AssetBuild entities on the same project as the entity being
+ asset_builds = session.query(
+ 'select name from AssetBuild where project_id in (select project_id from TypedContext where id is "{}")'.format(
+ { 'name': item['name'], 'value': item['name'] }
+ for item in asset_builds
+ logger.exception('Failed to get options')
+def register(session, **kw):
+ '''Register plugin. Called when used as an plugin.'''
+ # 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.Session):
+ session.event_hub.subscribe(
+ 'topic=ftrack.dynamic-enumerator', functools.partial(callback, session)
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.INFO)
+ session = ftrack_api.Session()
+ logging.info('Registered event listener and listening for events. Use Ctrl-C to abort.')
+ session.event_hub.wait()