Snippets

Lucas Correia ftrack action sublime snippet

Updated by Lucas Correia

File ftrack_action.sublime-snippet Modified

  • Ignore whitespace
  • Hide word diff
     <content><![CDATA[
 # :coding: utf-8
 # :copyright: Copyright (c) 2015 ftrack
+import sys
+import argparse
+import logging
 
 import ftrack
 
         choices=loggingLevels.keys(),
         default='info'
     )
+    namespace = parser.parse_args(arguments)
 
     # Set up basic logging
     logging.basicConfig(level=loggingLevels[namespace.verbosity])
Created by Lucas Correia

File ftrack_action.sublime-snippet Added

  • Ignore whitespace
  • Hide word diff
+<snippet>
+    <content><![CDATA[
+# :coding: utf-8
+# :copyright: Copyright (c) 2015 ftrack
+
+import ftrack
+
+
+class ${1:MyAction}(ftrack.Action):
+    '''${1}.'''
+
+    #: Action identifier.
+    identifier = '${2:my-action}'
+
+    #: Action label.
+    label = '${3:My action}'
+
+    def launch(self, event):
+        '''Callback method for action.'''
+        selection = event['data'].get('selection', [])
+
+        ${4:pass}
+
+        return {
+            'success': True,
+            'message': 'Action completed successfully'
+        }
+
+
+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'
+    )
+
+    # Set up basic logging
+    logging.basicConfig(level=loggingLevels[namespace.verbosity])
+
+    # Subscribe to action.
+    ftrack.setup()
+    action = ${1}()
+    action.register()
+
+    # Wait for events
+    ftrack.EVENT_HUB.wait()
+
+
+if __name__ == '__main__':
+    raise SystemExit(main(sys.argv[1:]))
+
+    ]]></content>
+    <tabTrigger>ftrackaction</tabTrigger>
+    <scope>source.python</scope>
+    <description>Creates an ftrack action</description>
+</snippet>
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.