def publish_geo(entity=None): """ copy publised model to lib """ if ui: publishFile = str(ui.publishVersionLabel.text()) pubEntity = path_info.PathInfo(publishFile) info = publish_info.TaskInfo(pubEntity) modelPublish = info.get('primaryOutput', 'publishFile') libPath = entity.libPath() libName = entity.libName(entity.step, entity.task_res(), ext=pubEntity.ext) dst = '{0}/{1}'.format(libPath, libName) # check file start = pub_utils.file_time(dst) result = file_utils.copy(modelPublish, dst) # check file export success end = pub_utils.file_time(dst) exportResult = pub_utils.is_file_new(start, end) if exportResult: return True, 'Success \n%s' % dst else: return False, 'Failed to copy \n%s' % dst else: return False, 'No ui information.'
def upload_media(entity=None, publishFile=None): """ upload mov file to version """ message = str() processStatus = False # get publish info if not publishFile: if ui: publishFile = str(ui.publishVersionLabel.text()) if publishFile: pubEntity = path_info.PathInfo(publishFile) info = publish_info.TaskInfo(pubEntity) heroMovFile = info.get('primaryOutput', 'heroMovFile') versionEntity = info.get('shotgun', 'version_entity') if os.path.exists(heroMovFile) and versionEntity: uploadFile = heroMovFile.replace('/', '\\') result = sg_process.upload_version_media(versionEntity, uploadFile) if result: message = 'Success %s' % result processStatus = True else: message = 'Failed to upload movie' logger.warning(message) else: message = 'Path %s not exists or versionEntity %s not found' % ( heroImgFile, versionEntity) logger.warning(message) return processStatus, message
def publish_version(entity=None, publishFile=None): """ create version in shotgun """ userEntity = None message = str() processStatus = False # get publish info if not publishFile: if ui: publishFile = str(ui.publishVersionLabel.text()) userEntity = ui.userWidget.read() if publishFile: pubEntity = path_info.PathInfo(publishFile) info = publish_info.TaskInfo(pubEntity) taskName = info.get('taskName', '') # create_version project = entity.project assetName = entity.name # find key data assetEntity = sg_process.get_one_asset(project, assetName) info.set('shotgun', 'asset_entity', assetEntity) projectEntity = assetEntity.get('project', None) info.set('shotgun', 'project_entity', projectEntity) taskEntity = sg_process.get_one_task(assetEntity, taskName) info.set('shotgun', 'task_entity', taskEntity) # if key data found if assetEntity and projectEntity and taskEntity: versionName = pubEntity.basename(ext=False) status = ui.statusWidget.get_task_status() description = '' playlistEntity = None result = sg_process.publish_version(projectEntity, assetEntity, taskEntity, userEntity, versionName, status, description, playlistEntity) message = 'Version creation not success' if result: info.set('shotgun', 'version_entity', result) processStatus = True message = 'Success %s' % result else: message = 'Data missing %s %s %s' % (assetEntity, projectEntity, taskEntity) logger.warning(message) processStatus = False else: message = 'No Publish File input' logger.warning(message) processStatus = False return processStatus, message
def summarized_info(*args): """ write published info from Task to Asset info """ # get publish info if ui: publishFile = str(ui.publishVersionLabel.text()) pubEntity = path_info.PathInfo(publishFile) taskInfo = publish_info.TaskInfo(pubEntity) assetInfo = publish_info.AssetInfo(pubEntity) data = assetInfo.read() taskDict = dict() # set # asset id assetEntity = taskInfo.get('shotgun', 'asset_entity') data.update({'assetID': assetEntity.get('id')}) # task id taskEntity = taskInfo.get('shotgun', 'task_entity') # publish file output = taskInfo.get('primaryOutput', 'publishFile') # hero file outputHero = taskInfo.get('primaryOutput', 'heroFile') # user versionEntity = taskInfo.get('shotgun', 'version_entity') user = str() if versionEntity: user = versionEntity.get('user', {}).get('name') # set dict taskDict = { pubEntity.taskName: { 'id': taskEntity.get('id'), 'output': output, 'user': user }, 'output': output, 'outputHero': outputHero, 'user': user } # set department if pubEntity.step in data.keys(): data[pubEntity.step].update(taskDict) else: data.update({pubEntity.step: taskDict}) assetInfo.setData(data) result = assetInfo.publish() return True, 'Success \npublish info %s' % result else: logger.warning('No ui information') return False, 'No ui information'
def export_abc(entity=None): """ export alembic geo """ status = False exportGrp = config.geoGrp res = entity.task_res() libPath = entity.libPath() publishResult = False if res: abcModel = entity.libName(entity.step, res, ext='abc') exportPath = '{0}/{1}'.format(libPath, abcModel) exportExt = os.path.splitext(exportPath)[-1] # check file start = pub_utils.file_time(exportPath) # export command abc_utils.exportABC(exportGrp, exportPath) # check file export success end = pub_utils.file_time(exportPath) exportResult = pub_utils.is_file_new(start, end) # write info if ui: publishFile = str(ui.publishVersionLabel.text()) pubEntity = path_info.PathInfo(publishFile) # publish publishPath = pubEntity.publishPath(publish='output') publishName = pubEntity.basename(ext=False) publishFileName = '%s/%s%s' % (publishPath, publishName, exportExt) file_utils.copy(exportPath, publishFileName) if os.path.exists(publishFileName): publishResult = True # write info info = publish_info.TaskInfo(pubEntity) info.set('secondaryOutput', 'abc', publishFileName) info.set('secondaryOutput', 'abcHero', exportPath) # successPublishFile = info.get('primaryOutput', 'publishFile') if exportResult: if publishResult: return True, 'Success %s\n%s' % (exportPath, publishFileName) else: return False, 'Failed to publish %s' % publishFileName else: return False, 'Failed to export Alembic %s' % exportPath else: return False, 'No res found'
def save_file(entity=None): """ save increment file to lock wip version """ errorMessage = [] if not entity: entity = path_info.PathInfo() if entity: logger.debug('start publishing ...') # get publish info publishFile, saveWorkFile, incrementSaveWorkFile, libFile = pub_utils.get_publish_info( entity) logger.debug('save work file %s' % saveWorkFile) logger.debug('publish version %s' % publishFile) logger.debug('save increment work file %s' % incrementSaveWorkFile) # start process files saveResult = None workResult = None # publish info pubEntity = path_info.PathInfo(publishFile) info = publish_info.TaskInfo(pubEntity) # save as saveResult = hook.save_file_as(incrementSaveWorkFile) info.set('work', 'incrementWorkFile', incrementSaveWorkFile) if saveResult: # copy to current work version (short cut for overwritten save) workResult = file_utils.copy(saveResult, saveWorkFile) info.set('work', 'workfile', saveWorkFile) if not saveResult: logger.error('Save to %s has failed' % incrementSaveWorkFile) errorMessage.append('Save to %s has failed' % incrementSaveWorkFile) if not workResult: logger.error('Overwrite work version %s has failed' % saveWorkFile) errorMessage.append('Overwrite work version %s has failed' % saveWorkFile) if errorMessage: return False, errorMessage else: return True, 'Success \n%s' % workResult
def set_task(entity=None, publishFile=None): """ change task status """ message = str() processStatus = False # get publish info if not publishFile: if ui: publishFile = str(ui.publishVersionLabel.text()) if publishFile: pubEntity = path_info.PathInfo(publishFile) info = publish_info.TaskInfo(pubEntity) taskEntity = info.get('shotgun', 'task_entity') taskName = info.get('taskName', '') # if no data in publish_info, query from shotgun if not taskEntity: logger.debug('taskEntity not found in publish_info') project = pubEntity.project assetName = pubEntity.name assetEntity = sg_process.get_one_asset(project, assetName) info.set('shotgun', 'asset_entity', assetEntity) taskEntity = sg_process.get_one_task(assetEntity, taskName) info.set('shotgun', 'task_entity', taskEntity) if taskEntity: status = ui.statusWidget.get_task_status() data = {'sg_status_list': status} result = sg_process.set_task_data(taskEntity.get('id'), data) processStatus = True message = 'Success %s' % result else: message = 'Failed to get taskEntity' return processStatus, message
def publish_image(entity=None): """ publish image or movie files """ mediaExts = ['.mov'] errorMessage = [] imgPublishes = [] if not entity: entity = path_info.PathInfo() if entity and ui: logger.debug('start publishing image ...') # get publish info publishFile = str(ui.publishVersionLabel.text()) pubEntity = path_info.PathInfo(publishFile) info = publish_info.TaskInfo(pubEntity) # successPublishFile = info.get('primaryOutput', 'publishFile') successPublishFile = publishFile # if publish success if successPublishFile: publishVer = path_info.find_version(successPublishFile) # _media path for hero preview mediaPath = entity.mediaPath() publishImgPath = entity.publishPath(publish='img') publishMovPath = entity.publishPath(publish='mov') publishName = entity.publishName() publishMediaVersion = entity.publishName(publishVer) # get publish items paths = ui.snapWidget.get_all_paths() heroImgSrc = None heroMovSrc = None copyDict = dict() for i, path in enumerate(paths): src = path.replace('\\', '/') extension = os.path.splitext(path)[-1] basename = '%s_%03d%s' % (publishMediaVersion, i + 1, extension) if extension in mediaExts: dst = '{0}/{1}'.format(publishMovPath, basename) if not heroMovSrc: heroMovSrc = src else: dst = '{0}/{1}'.format(publishImgPath, basename) if not heroImgSrc: heroImgSrc = src copyDict.update({src: dst}) # copy to publishes for src, dst in copyDict.iteritems(): try: file_utils.copy(src, dst) logger.debug('Copy to publish %s - %s' % (src, dst)) imgPublishes.append(dst) except Exception as e: errorMessage.append('Failed to copy %s-%s' % (src, dst)) info.set('primaryOutput', 'publishImgFiles', imgPublishes) # copy to heroImgSrc imgExt = os.path.splitext(heroImgSrc)[-1] heroImgDst = '%s/%s%s' % (mediaPath, publishName, imgExt) heroPreview = '%s/%s%s' % (mediaPath, entity.name, imgExt) if heroImgSrc: try: file_utils.copy(heroImgSrc, heroImgDst) logger.debug('Copy to hero %s - %s' % (heroImgSrc, heroImgDst)) imgPublishes.append(heroImgDst) info.set('primaryOutput', 'heroImgFile', str(heroImgDst)) except Exception as e: errorMessage.append('Failed to copy to hero %s-%s' % (heroImgSrc, heroImgDst)) # copy to preview file try: file_utils.copy(heroImgSrc, heroPreview) logger.debug('Copy to master %s - %s' % (heroImgSrc, heroPreview)) imgPublishes.append(heroPreview) except Exception as e: errorMessage.append('Failed to copy to master %s-%s' % (heroImgSrc, heroPreview)) # copy to heroMovSrc if heroMovSrc: movExt = os.path.splitext(heroMovSrc)[-1] heroMovDst = '%s/%s%s' % (mediaPath, publishName, movExt) try: file_utils.copy(heroMovSrc, heroMovDst) logger.debug('Copy to hero %s - %s' % (heroMovSrc, heroMovDst)) imgPublishes.append(heroMovDst) info.set('primaryOutput', 'heroMovFile', heroMovDst) except Exception as e: errorMessage.append('Failed to copy to hero %s-%s' % (heroMovSrc, heroMovDst)) else: # if not media, use image as upload media info.set('primaryOutput', 'heroMovFile', str(heroImgDst)) if errorMessage: return False, errorMessage else: return True, 'Success \n%s' % imgPublishes
def publish_file(entity=None): """ publish work file """ errorMessage = [] if not entity: entity = path_info.PathInfo() if entity: logger.debug('start publishing ...') # get publish info publishFile, saveWorkFile, incrementSaveWorkFile, libFile = pub_utils.get_publish_info( entity) logger.debug('save work file %s' % saveWorkFile) logger.debug('publish version %s' % publishFile) logger.debug('save increment work file %s' % incrementSaveWorkFile) # start process files saveResult = None publishResult = None workResult = None # publish info pubEntity = path_info.PathInfo(publishFile) info = publish_info.TaskInfo(pubEntity) # save as saveResult = hook.save_file_as(incrementSaveWorkFile) info.set('work', 'incrementWorkFile', incrementSaveWorkFile) if saveResult: # copy to publish publishResult = file_utils.copy(saveResult, publishFile) info.set('primaryOutput', 'publishFile', publishFile) # copy to hero # disable. Not all department export to lib, move to dept publish # publishHeroResult = file_utils.copy(saveResult, libFile) # info.set('primaryOutput', 'heroFile', libFile) # copy to current work version (short cut for overwritten save) workResult = file_utils.copy(saveResult, saveWorkFile) info.set('work', 'workfile', saveWorkFile) if not saveResult: logger.error('Save to %s has failed' % incrementSaveWorkFile) errorMessage.append('Save to %s has failed' % incrementSaveWorkFile) if not publishResult: logger.error('Publish to %s has failed' % publishFile) errorMessage.append('Publish to %s has failed' % publishFile) # if not publishHeroResult: # logger.error('Publish to hero %s has failed' % libFile) # errorMessage.append('Publish to %s has failed' % libFile) if not workResult: logger.error('Overwrite work version %s has failed' % saveWorkFile) errorMessage.append('Overwrite work version %s has failed' % saveWorkFile) if errorMessage: return False, errorMessage else: return True, 'Success \n%s' % publishResult