DiskAccessor prefix ignored by web UI
2 2

14 posts in this topic

Hello, 

I have built a custom locator plugin and am trying to use it to publish files to my project.  Everything is working brilliantly except for the DiskAccessor piece.  Although in code, the path to the component is being built correctly, the prefixes I'm specifying with my DiskAccessor are not appearing in the web UI.  I'm getting a partial path to the file in the UI, and the file is not being copied to the filesystem.  I'll include portions of my plugin code below.

In my Python terminal, when I test my code, I get accurate results:

location = session.query('Location where name is "lsmallwood.test"').one()

location.accessor.prefix

prints "/Volumes/MyCustomLocation/Assets" as expected.

If I have a FileComponent "c" which I've published, and I print out its path like so:

location.get_filesystem_path(c)

prints "/Volumes/MyCustomLocation/Assets/custom/path/to/asset/file" as expected.  However in the web UI, I'll only see "custom/path/to/asset/file".

Here's my plugin code.  Any ideas why the prefix I'm specifying with DiskAccessor isn't working?  Thanks a bunch!

def get_prefix():

    prefix = ''

    this_sys = platform.system()
    if this_sys == 'Windows':
        prefix = 'Z:\Assets'
    elif this_sys == 'Darwin':
        prefix = '/Volumes/MyCustomLocation/Assets/'
    else:
        print 'This location plugin is not configured for system {}'.format(this_sys)

    return prefix

def register(session):

    logger = logging.getLogger('ftrack_plugin:configure_location.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

    logger.info('Registering configure-location plugin')


    def configure_locations(event):
        '''Configure locations for session.'''
        session = event['data']['session']
        # Find location(s) and customise instances.

        location = session.query('Location where name is "lsmallwood.test"').one()
        ftrack_api.mixin(location, ftrack_api.entity.location.UnmanagedLocationMixin)
        location.accessor = ftrack_api.accessor.disk.DiskAccessor(prefix=get_prefix())
        location.structure = CustomStructure()
        location.priority = 50

    session.event_hub.subscribe(
        "topic=ftrack.api.session.configure-location",
        configure_locations
    )


class CustomStructure(ftrack_api.structure.base.Structure):

    # My CustomStructure class is a copy of StandardStructure which has a very lightly 
    # modified variation of the get_resource_identifier procedure.

 

Share this post


Link to post
Share on other sites

As a temporary hack, just so I can try to keep making progress, I added the prefix in my CustomLocation class.  The full path now shows up in the web UI, but it still appears in red and the file is still not copied to the file system.

Any advice appreciated!

Cheers,

Lori

Share this post


Link to post
Share on other sites

So far I've just been trying to use the API.  Am I required to use the Connect method if I want to publish files?  I can't really tell from your example if I should be using the API method, the Connect method, or both.

Your custom_location_plugin code looks almost identical to mine, above.  My location plugin is getting registered successfully, and the paths are being built properly when I run the code interactively in a Python session.  However the files are not getting copied to the server, and the Web UI is not picking up the prefix.  Can you tell me where I"m going wrong?

 

Share this post


Link to post
Share on other sites

I was banging my head against the desk over this same problem yesterday. Through some random things I did I got it to work. Here is what I did that seems to make it go:

Try commenting out the ftrack_api.mixin(location, ftrack_api.entity.location.UnmanagedLocationMixin). I'm not 100% sure why this doesn't work but as soon as I did that I got the files to publish to the correct spot on my local file server.

Next, the resolver.py I think wasn't being found. I built connect from source and for some reason the built-in resolver was working - which is the bit that resolves the path from web to local I believe.  I threw it into a path that connect could pick up and it all started working. If only using the api maybe you need to get a resolver into your pythonpath?

Not sure if that will help you but thought I would post here for the next time I have to reinstall, ha!

Share this post


Link to post
Share on other sites

Thanks Anthony - I tried that but I'm having some real trouble installing ftrack_connect on my system.  I'm able to install the UI from this page: https://www.ftrack.com/en/portfolio/connect and run it.

Unfortunately I don't seem to be able to "import ftrack_connect" in a Python session, which is causing Mattias's example plugin to error.

I'll start a new topic with this new problem.  I'm still hoping for some clarification from Mattias about whether it's necessary to go through ftrack_connect or not.  It's not clear from the locations documentation that ftrack_connect is a requirement.

Thanks for your help!

 

Share this post


Link to post
Share on other sites

Hey, sorry for the confusion.

There are two things here - one is the location and publishing to it. The other one is the file path being red/not resolved in the web UI.

  • Publishing files to a location / custom location does not require ftrack Connect - it is done only through the ftrack API.  (If you want to use Connect and it's built in publisher, or use the integrations, you will need to make the location available to Connect/Integration. This can be accomplished by adding it as a plugin to Connect.)
  • Resolving paths in the web UI - this requires a script listening to the ftrack.location.request-resolve from the event hub. Connect already does this and will resolve any location that it knows about.

The link I gave here: https://bitbucket.org/ftrack/ftrack-example-location can be used as a boiler plate to make a Location and have it act as a plugin to Connect. This is not necessary if you just want to publish to it from a Script. But good if you intend to have your users run Connect to publish, start integrations and resolve paths.

Quote

Try commenting out the ftrack_api.mixin(location, ftrack_api.entity.location.UnmanagedLocationMixin). I'm not 100% sure why this doesn't work but as soon as I did that I got the files to publish to the correct spot on my local file server.

Using the unmanaged location means that the files are never copied to the new location - you just register them where they already are.

Share this post


Link to post
Share on other sites

Great, thanks for the clarification.  After much tweaking yesterday, I managed to get the files publishing to the right place and the web UI showing the proper location of the published files.  (I'm not sure which tweak eventually did the trick).  

I'd like to get both scenarios working - publish via a script and publishing to a custom location via connect.  I'm trying to get your connect plugin example working and am having a little trouble, I think with the pathing/env var setup.

I put your example connect_plugin_hook in a directory in my code repo and changed it to point to my custom configure_location code. I then modified the FTRACK_CONNECT_PLUGIN_PATH in the shell to point to that directory.  I also modified the FTRACK_EVENT_PLUGIN_PATH to point to my custom location code (which now works fine in a Python session).

When I launch ftrack-connect from that shell, I get an error: "No module named configure_location."  So, it's finding connect_plugin_hook, but not configure_location.

What env vars need to be populated in order for ftrack-connect to pick up both the connect hook and custom locations dev code?  Perhaps what I'm doing is not a valid workflow, and there's a better way to launch ftrack-connect from a dev environment.  Any tips?  I'm on a Mac.

Cheers!

Share this post


Link to post
Share on other sites

The FTRACK_CONNECT_PLUGIN_PATH should be set when launching connect if you want to change where it searches for plugins. The FTRACK_EVENT_PLUGIN_PATH is only recommended to set when you publish from your own scripts.

Quote

When I launch ftrack-connect from that shell, I get an error: "No module named configure_location."  So, it's finding connect_plugin_hook, but not configure_location.

You must add the path to sys path: https://bitbucket.org/ftrack/ftrack-example-location/src/114a8deeb307de10bc479c3cdeb0a857f842522d/hook/connect_plugin_hook.py?at=master&fileviewer=file-view-default#connect_plugin_hook.py-12

Share this post


Link to post
Share on other sites

I'm still having a bit of trouble getting the API and Connect to work in the same environment.  Here's what I've done so far:

- Put all my plugin code in the same directory in order to try to simplify things. This includes:

connect_plugin_hook.py -- modified LOCATION_DIRECTORY to point to the directory containing configure_location.py (i.e. the same directory as connect_plugin_hook)

configure_location.py -- contains the register code and a CustomStructure class derived from ftrack_api.base.structure.Structure.  The ftrack_api.mixin(...) line is commented out.

- I managed to get the ftrack-connect source code installed and have added the "/FtrackConnectLocation/ftrack-connect/lib" subdir to the PYTHONPATH

When I create an ftrack_api.Session in the Python session, I get a warning message:  'WARNING:ftrack_api.plugin.discover:Failed to load plugin from "/MyCodeLocation/connect_plugin_hook.py": No module named ftrack'. Should I be concerned?

When I publish code via the API, the file will be copied to the correct, custom location as defined by configure_location.py.  It will show up in the Web UI correctly only if ftrack-connect is running.

When I launch ftrack-connect from my modified shell (the one that has the ftrack-connect source code path in the PYTHONPATH), the location plugin does get registered successfully, and any published files go to the correct, custom location. However, the web UI is not reflecting the filesystem prefix -- just like if I'd published files via the API without ftrack-connect running.  Is that because I'm running ftrack-connect directly from a terminal prompt?  I wonder if there's some disconnect between ftrack-connect and the Web UI in that case.

Finally, I've noticed that if I create assets/assetversions in the API, those entities will not be reflected in the "Existing asset" drop down in ftrack-connect.  It seems to maintain a separate list of assets and versions them up separately, and independent of the assets published via the API.  Both streams of assets show up in the Web UI, which makes it look like there are duplicate asset versions published to a task.  Do you know what's going on there?

Is the fact that I'm launching ftrack-connect from a terminal prompt causing the screwiness?

Thanks!

 

Share this post


Link to post
Share on other sites

Hi @L Smallwood,
as far as I can understand you are trying to have some ftrack-connect plugins for custom location up and running while having ftrack connect up.

First thing first , locate the plugin directory clicking with right mouse button on the panel icon of ftrack and click -> Open Plugin Directory

once the folder is open , in there you can start adding your custom code .

I've attached some code that should try to register a custom location called "my.custom"

Hope it helps.

L.


p.s

please note , the code I provided is simpler than https://bitbucket.org/ftrack/ftrack-example-location/src/114a8deeb307de10bc479c3cdeb0a857f842522d/hook/connect_plugin_hook.py?at=master&fileviewer=file-view-default as retains the structure code in the same folder.

 


 

custom_location.tar.gz

Share this post


Link to post
Share on other sites

Hi Lorenzo,

Thanks for your message but unfortunately that doesn't address my specific problem.  The issue is that I'm trying to use the ftrack_api and ftrack-connect together, and they don't seem to want to cooperate.  See my post from March 2 - it describes the problem.

Has anyone here on this forum successfully used the API in conjunction with ftrack-connect functionality?

-- Lori

Share this post


Link to post
Share on other sites

Hi , sorry if didn't help.

>> When I create an ftrack_api.Session in the Python session, I get a warning message:  'WARNING:ftrack_api.plugin.discover:Failed to load plugin from "/MyCodeLocation/connect_plugin_hook.py": No module named ftrack'. Should I be concerned?

looks like you are somehow mixing legacy and new api?
ftrack_api -> new
ftrack -> legacy

Try removing legacy code, so you can get rid of one of the imports.

 >> However, the web UI is not reflecting the filesystem prefix 
looks like you have somehow customised the paths, so I'm wondering, are these hooks still available in connect:
https://bitbucket.org/ftrack/ftrack-connect/src/cd3096b1dad417e9a65cd41835f4fd3d5bb439ba/resource/hook/?at=master

in case you can try add some prints the resolve.py hook and see why does not build the path in the web ui.

>> Is the fact that I'm launching ftrack-connect from a terminal prompt causing the screwiness?

nope :)

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
2 2