+# :copyright: Copyright (c) 2015 ftrack
+def get_entity(entityId, entityType):
+ '''Return entity based on *entityId* and *entityType*.'''
+ if entityType == ftrack.Project._type:
+ entity = ftrack.Project(entityId)
+ elif entityType == ftrack.Task._type:
+ entity = ftrack.Task(entityId)
+ elif entityType == 'assetversion':
+ entity = ftrack.AssetVersion(entityId)
+ u'Entity ({0}, {1}) not a valid type, skipping..'
+ .format(entityId, entityType)
+class EditMetaData(ftrack.Action):
+ identifier = 'ftrack.edit.meta.data'
+ label = 'Edit metadata'
+ def discover(self, event):
+ '''Return if action is valid.'''
+ selection = event['data']['selection']
+ # If selection contains more than one item return early since
+ # metadata cannot be edited for several entites at the same time.
+ self.logger.info('Got selection: {0}'.format(selection))
+ if (len(selection) != 1):
+ selection[0]['entityId'], selection[0]['entityType']
+ 'actionIdentifier': self.identifier
+ def launch(self, event):
+ '''Launch edit meta data action.'''
+ selection = event['data']['selection']
+ input_values = event['data']['values']
+ selection[0]['entityId'], selection[0]['entityType']
+ for key in input_values.keys():
+ entity.setMeta(key, input_values[key])
+ metaKeys = entity.metaKeys()
+ for metaKey in metaKeys:
+ 'value': entity.getMeta(metaKey)
+ 'value': '*No metadata found on entity.*'
+def main(arguments=None):
+ '''Set up logging and register action.'''
+ parser = argparse.ArgumentParser()
+ # Allow setting of logging level from arguments.
+ logging.NOTSET, logging.DEBUG, logging.INFO, logging.WARNING,
+ logging.ERROR, logging.CRITICAL
+ loggingLevels[logging.getLevelName(level).lower()] = level
+ help='Set the logging output verbosity.',
+ choices=loggingLevels.keys(),
+ namespace = parser.parse_args(arguments)
+ logging.basicConfig(level=loggingLevels[namespace.verbosity])
+ action = EditMetaData()
+ ftrack.EVENT_HUB.wait()
+if __name__ == '__main__':
+ raise SystemExit(main(sys.argv[1:]))