Jump to content

New API custom locations, structures and resolver tutorials?


Mike

Recommended Posts

Posted

Hello, are there any resources/tutorials for new api location, structure, and resolver migration? I've been waiting for the new API roll out to finally tackle these, but I'm not finding enough resources on the dev portal to successfully migrate.

I'm currently getting this error when my location tries to register:

2017-10-23 15:02:36,408 - ftrack_connect.ui.application.Application - ERROR - Error during login.
.......
......
.....
  File "path\to\mb_plugins\hook\location\mb_firstborn_location.py", line 65, in register
    session.event_hub.subscribe(
AttributeError: 'Registry' object has no attribute 'event_hub'

 

My new location plugin is below.  I'd also like to update my structure and resolver plugins (if that's possible yet).

import os
import sys
import platform

import ftrack_api
import ftrack_api.entity.location
import ftrack_api.accessor.disk


def configure_locations(event):
	'''Configure locations for session.'''

	session = event['data']['session']

	# Import custom structure plugin.
	RESOURCE_DIRECTORY = os.path.abspath(
		os.path.join(os.path.dirname(__file__), '..', '..', 'resource')
	)
	if RESOURCE_DIRECTORY not in sys.path:
		sys.path.append(RESOURCE_DIRECTORY)

	from pipeline_structures import structure_plugin

	# Location and prefix variables.
	studio = os.getenv('STUDIO').lower()
	site = os.getenv('SITE').lower()
	LOCATION = '{0}.{1}'.format(studio, site)

	# Get mount point.
	disk_name = session.query('Disk where name is "{0}"'.format(LOCATION)).one()

	platform_name = 'windows'
	if not platform.system().lower() == 'windows':
		platform_name = 'unix'

	disk_path = disk_name[platform_name]

	PREFIX = os.path.expandvars(disk_path)

	# Find location(s) and customise instances.
	#ftrack.ensureLocation(LOCATION) # I need an updated way to do this. I've noticed the session.ensure() method, is that it?
	location = session.query('Location where name is "studio.site"').one()
	#ftrack_api.mixin(location, ftrack_api.entity.location.UnmanagedLocationMixin) # Not sure what this does, do I need it?
	location.accessor = ftrack_api.accessor.disk.DiskAccessor(prefix=PREFIX)
	location.structure = structure_plugin.mbStructure()
	location.priority = 50


def register(session):
	'''Register plugin with *session*.'''
	session.event_hub.subscribe(
		'topic=ftrack.api.session.configure-location',
		configure_locations
	)

 

Posted

Hi Mike,

The resources we to move our to the new api are here: http://ftrack-python-api.rtd.ftrack.com/en/stable/release/migrating_from_old_api.html

As for this particular problem that you are facing; the register function is called with both new and old api, so you will want to exit early if it is not the new one:

 

def register(session, **kw):
    '''Register plugin.'''

    # Validate that session is an instance of ftrack_api.Session. If not,
    # assume that register is being called from an incompatible API
    # and return without doing anything.
    if not isinstance(session, ftrack_api.Session):
        # Exit to avoid registering this plugin again.
        return

    ...

 

  • 7 months later...
Posted

Thanks, Mattias.

 

Getting back into this. I'm not sure that the configure_locations function is being called. Do I need to subscribe to a different event? I don't see "configure-location" in the docs for the new API.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...