mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 21:32:15 +01:00
97 lines
2.3 KiB
Python
97 lines
2.3 KiB
Python
# :coding: utf-8
|
|
# :copyright: Copyright (c) 2017 ftrack
|
|
import sys
|
|
import argparse
|
|
import logging
|
|
import collections
|
|
import os
|
|
import json
|
|
import re
|
|
|
|
import ftrack_api
|
|
from pype.ftrack import BaseAction
|
|
from avalon import io, inventory, schema
|
|
|
|
|
|
ignore_me = True
|
|
|
|
|
|
class TestAction(BaseAction):
|
|
'''Edit meta data action.'''
|
|
|
|
#: Action identifier.
|
|
identifier = 'test.action'
|
|
#: Action label.
|
|
label = 'Test action'
|
|
#: Action description.
|
|
description = 'Test action'
|
|
#: priority
|
|
priority = 10000
|
|
|
|
def discover(self, session, entities, event):
|
|
''' Validation '''
|
|
discover = False
|
|
roleList = ['Pypeclub']
|
|
userId = event['source']['user']['id']
|
|
user = session.query('User where id is ' + userId).one()
|
|
|
|
for role in user['user_security_roles']:
|
|
if role['security_role']['name'] in roleList:
|
|
discover = True
|
|
break
|
|
|
|
return discover
|
|
|
|
def launch(self, session, entities, event):
|
|
self.log.info(event)
|
|
|
|
return True
|
|
|
|
|
|
def register(session, **kw):
|
|
'''Register plugin. Called when used as an plugin.'''
|
|
|
|
if not isinstance(session, ftrack_api.session.Session):
|
|
return
|
|
|
|
action_handler = TestAction(session)
|
|
action_handler.register()
|
|
|
|
|
|
def main(arguments=None):
|
|
'''Set up logging and register action.'''
|
|
if arguments is None:
|
|
arguments = []
|
|
|
|
parser = argparse.ArgumentParser()
|
|
# Allow setting of logging level from arguments.
|
|
loggingLevels = {}
|
|
for level in (
|
|
logging.NOTSET, logging.DEBUG, logging.INFO, logging.WARNING,
|
|
logging.ERROR, logging.CRITICAL
|
|
):
|
|
loggingLevels[logging.getLevelName(level).lower()] = level
|
|
|
|
parser.add_argument(
|
|
'-v', '--verbosity',
|
|
help='Set the logging output verbosity.',
|
|
choices=loggingLevels.keys(),
|
|
default='info'
|
|
)
|
|
namespace = parser.parse_args(arguments)
|
|
|
|
# Set up basic logging
|
|
logging.basicConfig(level=loggingLevels[namespace.verbosity])
|
|
|
|
session = ftrack_api.Session()
|
|
register(session)
|
|
|
|
# Wait for events
|
|
logging.info(
|
|
'Registered actions and listening for events. Use Ctrl-C to abort.'
|
|
)
|
|
session.event_hub.wait()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main(sys.argv[1:]))
|