def _registerGrouping(self, shortName, targetReference, specification, context): '''Register a grouping entity with *shortName*. A grouping entity could be a Sequence, Shot etc. ''' # TODO: if targetReference == getRootEntityReference() then make a # project entity = self.getEntityById(targetReference) wrongDestinationMsg = ('Groupings can only be created under a Project ' 'or a Sequence.') createFunction = None if isinstance(entity, ftrack.Project): createFunction = entity.createSequence elif (isinstance(entity, ftrack.Task) and entity.getObjectType() == 'Sequence'): createFunction = entity.createShot if createFunction is None: raise FnAssetAPI.exceptions.RegistrationError( wrongDestinationMsg, targetReference) # For a grouping, the 'resolved string' is to be considered the name # if not overriden by a name hint. # TODO: Store the shortName somewhere as it is needed to pass back to # resolve later. Currently resolving using the name. name = specification.getField(FnAssetAPI.constants.kField_HintName, shortName) grouping = createFunction(name=name) # Upload thumbnail if provided. thumbnailPath = specification.getField('thumbnailPath', None) if thumbnailPath: grouping.createThumbnail(thumbnailPath) # Ensure correct tasks are created as well. # TODO: Make this configurable, possbily using task templates. compositingTaskType = ftrack.TaskType( ftrack_connect_foundry.constant.COMPOSITING_TASK_TYPE) grouping.createTask( ftrack_connect_foundry.constant.COMPOSITING_TASK_NAME, compositingTaskType) editingTaskType = ftrack.TaskType( ftrack_connect_foundry.constant.EDIT_TASK_TYPE) grouping.createTask(ftrack_connect_foundry.constant.EDIT_TASK_NAME, editingTaskType) # Return grouping id as currently don't know which task is applicable. # That is determined at registration when the host/specification is # known. return grouping.getEntityRef()
def findTask(task, newTaskType): """ Find the correct lighting or compositing task, get its assignee and send them a message. :param task: The task whose status has been changed :param newTaskType: Either 'Lighting' or 'Compositing' based on status change :return: None """ # Get the parent shot shot = task.getParent() project = task.getProject().getName() # Get the lighting task, If not send message to # general found = False for t in shot.getTasks(): if t.getType().getName().lower() == newTaskType.lower(): found = True break if found: # Get the user assigned to the task. If not send message to #general users = t.getUsers() message = "Project: {0}\nShot: {1}\nStatus: Ready for {2} ".format(project, shot.getName(), newTaskType) for user in users: slackUser = getSlackUsers(user.getUsername()) sendSlackMessage(slackUser, message) if not users: slackGroup = getSlackUsers(project) sendSlackMessage(slackGroup, message) else: tt = ftrack.TaskType(newTaskType) shot.createTask('Lighting', taskType=tt) message = "Project: {0}\nShot: {1}\nStatus: Ready for {2}\n" \ "Note: Task {2} was created as it did not exist".format(project, shot.getName(), newTaskType) slackGroup = getSlackUsers(project) sendSlackMessage(slackGroup, message)
def create_from_structure(self, parent, structure, projectFolder, assetFolder, createFolders): """Create *structure* under *parent*.""" level = structure[0] children = structure[1:] object_type = level['object_type'] if object_type == 'asset': try: asset_object = parent.create('Folder', 'Assets') except Exception: asset_object = ftrack.getFromPath([parent.getName(), 'Assets']) try: type_object = asset_object.create('Folder', level['type']) except Exception: type_object = ftrack.getFromPath([parent.getName(), 'Assets', level['type']]) projectFolder = os.path.join(projectFolder, 'assets', level['type'].lower()) self.createFoldersOnDisk(projectFolder, createFolders) for data in level['data']: if object_type == 'asset': try: new_object = type_object.create('Asset Build', data) except Exception: new_object = ftrack.getFromPath([parent.getName(), 'Assets', level['type'], data]) assetFolder = os.path.join(projectFolder, data.lower()) self.createFoldersOnDisk(assetFolder, createFolders) if object_type == 'task': taskType = ftrack.TaskType(id=data['typeid']) try: new_object = parent.createTask( TASK_TYPE_LOOKUP[data['typeid']], taskType ) new_object.set(data) taskFolder = os.path.join(assetFolder, str(taskType.getName()).lower()) except Exception: logging.info('Task {0} already exists. Doing nothing'.format( TASK_TYPE_LOOKUP[data['typeid']])) new_object = '' self.createFoldersOnDisk(taskFolder, createFolders) logging.debug( 'Created {new_object} on parent {parent}'.format( parent=parent, new_object=new_object ) ) if children: self.create_from_structure(new_object, children, projectFolder, assetFolder, createFolders)
def create_from_structure(self, parent, structure, projectFolder, tmpFolder): """Create *structure* under *parent*.""" level = structure[0] children = structure[1:] object_type = level['object_type'] for data in level['data']: if object_type == 'sequence': try: new_object = parent.createSequence(data) except Exception: logging.info( 'Sequence {0} already exists. Doing nothing'.format( data)) path = self.getPath(parent, data) new_object = ftrack.getSequence(path) projectFolder = os.path.join(projectFolder, data) if object_type == 'shot': try: new_object = parent.createShot(data) tmpFolder = os.path.join(projectFolder, data) self.createImgFolders(tmpFolder) except Exception: logging.info( 'Shot {0} already exists. Doing nothing'.format(data)) path = self.getPath(parent, data) new_object = ftrack.getShot(path) if object_type == 'task': taskType = ftrack.TaskType(id=data['typeid']) try: new_object = parent.createTask( TASK_TYPE_LOOKUP[data['typeid']], taskType) new_object.set(data) except Exception: logging.info( 'Task {0} already exists. Doing nothing'.format( TASK_TYPE_LOOKUP[data['typeid']])) new_object = '' logging.debug('Created {new_object} on parent {parent}'.format( parent=parent, new_object=new_object)) if children: self.create_from_structure(new_object, children, projectFolder, tmpFolder)
def _getTaskId(self, entity, specification, context): '''Return task reference for *entity*.''' taskType, taskName = self.getTaskTypeAndName(specification, entity, context) if (hasattr(entity, 'getObjectType') and entity.getObjectType() in ['Shot', 'Sequence']): ftrackTasks = entity.getTasks(taskTypes=[ taskType, ]) if len(ftrackTasks) > 0: task = ftrackTasks[0] reference = task.getEntityRef() else: taskTypeEntity = ftrack.TaskType(taskType) task = entity.createTask(taskName, taskTypeEntity) reference = task.getEntityRef() else: reference = entity.getEntityRef() return reference
def _showCreateDialog(self): '''Display create dialog and update navigator with result.''' dialog = CreateDialog(self._bridge, self, currentHref=self._currentBrowsingId) result = dialog.exec_() if result == 1: entity = self._bridge.getEntityById(dialog.currentHref) entityType = dialog.getEntityType() entityName = dialog.getEntityName() if entityType == 'seq': entity.createSequence(name=entityName) elif entityType == 'shot': entity.createShot(name=entityName) elif entityType == 'task': taskType = ftrack.TaskType(dialog.getTaskType()) entity.createTask(name=entityName, taskType=taskType) self._updateNavigator(entity.getEntityRef())
def create_from_structure(parent, structure, projectFolder, tmpFolder, createFolders, templateFolder): '''Create *structure* under *parent*.''' level = structure[0] children = structure[1:] object_type = level['object_type'] for data in level['data']: if object_type == 'sequence': new_object = parent.createSequence(data) projectFolder = os.path.join(projectFolder, data) if object_type == 'shot': new_object = parent.createShot(data) tmpFolder = os.path.join(projectFolder, data) createImgFolders(tmpFolder, createFolders) tmpFolder = os.path.join(tmpFolder, 'scene') createFoldersOnDisk(tmpFolder, createFolders) if object_type == 'task': taskType = ftrack.TaskType(id=data['typeid']) new_object = parent.createTask( TASK_TYPE_LOOKUP[data['typeid']], taskType ) new_object.set(data) folder = os.path.join(tmpFolder, str(taskType.getName()).lower()) createFoldersOnDisk(folder, createFolders) copyTemplateFiles(templateFolder, new_object, folder, parent.getName()) logging.debug( 'Created {new_object} on parent {parent}'.format( parent=parent, new_object=new_object ) ) if children: create_from_structure(new_object, children, projectFolder, tmpFolder, createFolders, templateFolder)
def getEntityById(self, identifier, throw=True): '''Return an entity represented by the given *identifier*. If *throw* is True then raise :py:exc:`FnAssetAPI.exceptions.InvalidEntityReference` if no entity can be found, otherwise return None. ''' entity = None if identifier != '': if 'ftrack://' in identifier: url = urlparse.urlparse(identifier) query = urlparse.parse_qs(url.query) entityType = query.get('entityType')[0] identifier = url.netloc try: return self._memoiser.cache.get(identifier) except KeyError: pass try: if entityType == 'component': entity = ftrack.Component(identifier) elif entityType == 'asset_version': entity = ftrack.AssetVersion(identifier) elif entityType == 'asset': entity = ftrack.Asset(identifier) elif entityType == 'show': entity = ftrack.Project(identifier) elif entityType == 'task': entity = ftrack.Task(identifier) elif entityType == 'tasktype': entity = ftrack.TaskType(identifier) except: pass else: ftrackObjectClasses = [ ftrack.Task, ftrack.Asset, ftrack.AssetVersion, ftrack.Component, ftrack.Project, ftrack.TaskType ] try: return self._memoiser.cache.get(identifier) except KeyError: pass for cls in ftrackObjectClasses: try: entity = cls(id=identifier) break except ftrack.FTrackError as error: if error.message.find('was not found') == -1: raise pass except Exception, error: FnAssetAPI.logging.log( 'Exception caught trying to create {0}: {1}'. format(cls.__name__, error), FnAssetAPI.logging.kError) raise