From 47e36bb432ee9b39650bb4be169f94fe20a913ed Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 16 Nov 2018 14:54:17 +0100 Subject: [PATCH] Sync to avalon exports all Custom Attributes in 'avalon' group without 'avalon_' in key --- pype/ftrack/actions/action_syncToAvalon.py | 59 ++++++++++++++-------- pype/ftrack/actions/action_test.py | 40 +++++++++------ pype/ftrack/login_dialog.py | 4 +- pype/ftrack/login_tools.py | 4 +- 4 files changed, 68 insertions(+), 39 deletions(-) diff --git a/pype/ftrack/actions/action_syncToAvalon.py b/pype/ftrack/actions/action_syncToAvalon.py index 56e8215e38..a5ee5ee49b 100644 --- a/pype/ftrack/actions/action_syncToAvalon.py +++ b/pype/ftrack/actions/action_syncToAvalon.py @@ -6,6 +6,7 @@ import logging import os import ftrack_api import json +import re from ftrack_action_handler import BaseAction from avalon import io, inventory, lib @@ -54,6 +55,7 @@ class SyncToAvalon(BaseAction): print("action <" + self.__class__.__name__ + "> is running") #TODO AVALON_PROJECTS, AVALON_ASSET, AVALON_SILO should be set up otherwise console log shows avalon debug + self.setAvalonAttributes(session) self.importable = [] # get from top entity in hierarchy all parent entities @@ -105,6 +107,12 @@ class SyncToAvalon(BaseAction): 'success': True, 'message': "Synchronization was successfull" } + def setAvalonAttributes(self, session): + self.custom_attributes = [] + all_avalon_attr = session.query('CustomAttributeGroup where name is "avalon"').one() + for cust_attr in all_avalon_attr['custom_attribute_configurations']: + if 'avalon_' not in cust_attr['key']: + self.custom_attributes.append(cust_attr) def getShotAsset(self, entity): if not (entity.entity_type in ['Task']): @@ -150,7 +158,6 @@ class SyncToAvalon(BaseAction): eLinks = [] ca_mongoid = 'avalon_mongo_id' - ca_tools = 'avalon_tools_env' # get needed info of entity and all parents for e in entity['link']: @@ -171,8 +178,28 @@ class SyncToAvalon(BaseAction): ## ----- PROJECT ------ # If project don't exists -> ELSE avalon_project = io.find_one({"type": "project", "name": entityProj["full_name"]}) + entity_type = entity.entity_type + + data = {} + data['ftrackId'] = entity['id'] + data['entityType'] = entity_type + + for cust_attr in self.custom_attributes: + if cust_attr['entity_type'].lower() in ['asset']: + data[cust_attr['key']] = entity['custom_attributes'][cust_attr['key']] + + elif cust_attr['entity_type'].lower() in ['show'] and entity_type.lower() == 'project': + data[cust_attr['key']] = entity['custom_attributes'][cust_attr['key']] + + elif cust_attr['entity_type'].lower() in ['task'] and entity_type.lower() != 'project': + # Put space between capitals (e.g. 'AssetBuild' -> 'Asset Build') + entity_type = re.sub(r"(\w)([A-Z])", r"\1 \2", entity_type) + # Get object id of entity type + ent_obj_type_id = session.query('ObjectType where name is "{}"'.format(entity_type)).one()['id'] + + if cust_attr['object_type_id'] == ent_obj_type_id: + data[cust_attr['key']] = entity['custom_attributes'][cust_attr['key']] - tools = entity['custom_attributes'][ca_tools] if entity.entity_type.lower() in ['project']: # Set project Config @@ -184,17 +211,13 @@ class SyncToAvalon(BaseAction): io.update_many({'type': 'project','name': entityProj['full_name']}, {'$set':{'config':config}}) + data['code'] = entity['name'] + # Store info about project (FtrackId) io.update_many({ 'type': 'project', - 'name': entity['full_name'] - }, { - '$set':{'data':{ - 'code':entity['name'], - 'ftrackId':entity['id'], - 'entityType':entity.entity_type, - 'tools':tools - }}}) + 'name': entity['full_name']}, + {'$set':{'data':data}}) projectId = io.find_one({"type": "project", "name": entityProj["full_name"]})["_id"] if ca_mongoid in entity['custom_attributes']: @@ -206,7 +229,7 @@ class SyncToAvalon(BaseAction): # Store project Id projectId = avalon_project["_id"] - + ## ----- ASSETS ------ # Presets: # TODO how to check if entity is Asset Library or AssetBuild? @@ -241,15 +264,11 @@ class SyncToAvalon(BaseAction): hierarchy = os.path.sep.join(folderStruct) - data = { - 'visualParent': parentId, - 'parents': folderStruct, - 'tasks': tasks, - 'hierarchy': hierarchy, - 'tools': tools, - 'ftrackId': entity['id'], - 'entityType': entity.entity_type - } + data['visualParent'] = parentId + data['parents'] = folderStruct + data['tasks'] = tasks + data['hierarchy'] = hierarchy + name = self.checkName(entity['name']) os.environ['AVALON_ASSET'] = name diff --git a/pype/ftrack/actions/action_test.py b/pype/ftrack/actions/action_test.py index a9f2aba0eb..7995443256 100644 --- a/pype/ftrack/actions/action_test.py +++ b/pype/ftrack/actions/action_test.py @@ -6,6 +6,7 @@ import logging import collections import os import json +import re import ftrack_api from ftrack_action_handler import BaseAction @@ -31,24 +32,33 @@ class TestAction(BaseAction): def launch(self, session, entities, event): - - for entity in entities: - index = 0 - name = entity['components'][index]['name'] - filetype = entity['components'][index]['file_type'] - path = entity['components'][index]['component_locations'][0]['resource_identifier'] - - # entity['components'][index]['component_locations'][0]['resource_identifier'] = r"C:\Users\jakub.trllo\Desktop\test\exr\int_c022_lighting_v001_main_AO.%04d.exr" - location = entity['components'][0]['component_locations'][0]['location'] - component = entity['components'][0] + entity = entities[0] - # print(location.get_filesystem_path(component)) + entity_type = entity.entity_type + data = {} + """ + custom_attributes = [] - # for k in p: - # print(100*"-") - # print(k) - # print(p[k]) + all_avalon_attr = session.query('CustomAttributeGroup where name is "avalon"').one() + for cust_attr in all_avalon_attr['custom_attribute_configurations']: + if 'avalon_' not in cust_attr['key']: + custom_attributes.append(cust_attr) + """ + for cust_attr in custom_attributes: + if cust_attr['entity_type'].lower() in ['asset']: + data[cust_attr['key']] = entity['custom_attributes'][cust_attr['key']] + + elif cust_attr['entity_type'].lower() in ['show'] and entity_type.lower() == 'project': + data[cust_attr['key']] = entity['custom_attributes'][cust_attr['key']] + + elif cust_attr['entity_type'].lower() in ['task'] and entity_type.lower() != 'project': + # Put space between capitals (e.g. 'AssetBuild' -> 'Asset Build') + entity_type = re.sub(r"(\w)([A-Z])", r"\1 \2", entity_type) + # Get object id of entity type + ent_obj_type_id = session.query('ObjectType where name is "{}"'.format(entity_type)).one()['id'] + if cust_attr['type_id'] == ent_obj_type_id: + data[cust_attr['key']] = entity['custom_attributes'][cust_attr['key']] return True diff --git a/pype/ftrack/login_dialog.py b/pype/ftrack/login_dialog.py index 622cfc21b5..8cfceb6d91 100644 --- a/pype/ftrack/login_dialog.py +++ b/pype/ftrack/login_dialog.py @@ -1,7 +1,7 @@ import sys import os import requests -from PyQt5 import QtCore, QtGui, QtWidgets +from app.vendor.Qt import QtCore, QtGui, QtWidgets from app import style from . import credentials, login_tools @@ -11,7 +11,7 @@ class Login_Dialog_ui(QtWidgets.QWidget): SIZE_W = 300 SIZE_H = 230 - loginSignal = QtCore.pyqtSignal(object, object, object) + loginSignal = QtCore.Signal(object, object, object) _login_server_thread = None inputs = [] buttons = [] diff --git a/pype/ftrack/login_tools.py b/pype/ftrack/login_tools.py index 719e6bac37..e38d3fa994 100644 --- a/pype/ftrack/login_tools.py +++ b/pype/ftrack/login_tools.py @@ -2,7 +2,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer from urllib import parse import webbrowser import functools -from PyQt5 import QtCore +from app.vendor.Qt import QtCore # class LoginServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): class LoginServerHandler(BaseHTTPRequestHandler): @@ -82,7 +82,7 @@ class LoginServerThread(QtCore.QThread): '''Login server thread.''' # Login signal. - loginSignal = QtCore.pyqtSignal(object, object, object) + loginSignal = QtCore.Signal(object, object, object) def start(self, url):