From 698c59c8ea0e76caed606fadd2b100a61b60b9d7 Mon Sep 17 00:00:00 2001 From: Milan Kolar Date: Wed, 10 Apr 2019 00:12:09 +0200 Subject: [PATCH] convert presets to pype2.0 way --- .../actions/action_create_cust_attrs.py | 4 +- pype/ftrack/lib/ftrack_app_handler.py | 2 + pype/plugins/maya/load/load_alembic.py | 12 ++---- pype/plugins/maya/load/load_ass.py | 20 +++------- pype/plugins/maya/load/load_camera.py | 11 ++---- pype/plugins/maya/load/load_fbx.py | 12 ++---- pype/plugins/maya/load/load_mayaascii.py | 12 ++---- pype/plugins/maya/load/load_model.py | 38 +++++-------------- pype/plugins/maya/load/load_rig.py | 11 ++---- .../plugins/maya/load/load_vdb_to_redshift.py | 13 ++----- pype/plugins/maya/load/load_vdb_to_vray.py | 12 ++---- pype/plugins/maya/load/load_vrayproxy.py | 13 ++----- pype/plugins/maya/load/load_yeti_cache.py | 11 ++---- pype/plugins/maya/load/load_yeti_rig.py | 12 ++---- 14 files changed, 55 insertions(+), 128 deletions(-) diff --git a/pype/ftrack/actions/action_create_cust_attrs.py b/pype/ftrack/actions/action_create_cust_attrs.py index fcd4569f6a..9f2564406a 100644 --- a/pype/ftrack/actions/action_create_cust_attrs.py +++ b/pype/ftrack/actions/action_create_cust_attrs.py @@ -6,7 +6,7 @@ import arrow import logging from pype.vendor import ftrack_api from pype.ftrack import BaseAction, get_ca_mongoid -from pypeapp.config import get_presets +from pypeapp import config """ This action creates/updates custom attributes. @@ -226,7 +226,7 @@ class CustomAttributes(BaseAction): self.process_attribute(data) def custom_attributes_from_file(self, session, event): - presets = get_presets()['ftrack']['ftrack_custom_attributes'] + presets = config.get_presets()['ftrack']['ftrack_custom_attributes'] for cust_attr_name in presets: try: diff --git a/pype/ftrack/lib/ftrack_app_handler.py b/pype/ftrack/lib/ftrack_app_handler.py index 7498db5b62..138b6d6459 100644 --- a/pype/ftrack/lib/ftrack_app_handler.py +++ b/pype/ftrack/lib/ftrack_app_handler.py @@ -201,6 +201,8 @@ class AppAction(BaseHandler): if parents: hierarchy = os.path.join(*parents) + application = avalonlib.get_application(os.environ["AVALON_APP_NAME"]) + data = { "root": os.environ.get("PYPE_STUDIO_PROJECTS_PATH"), "project": {"name": entity['project']['full_name'], diff --git a/pype/plugins/maya/load/load_alembic.py b/pype/plugins/maya/load/load_alembic.py index 9fd4aa2108..d3d85249c5 100644 --- a/pype/plugins/maya/load/load_alembic.py +++ b/pype/plugins/maya/load/load_alembic.py @@ -1,6 +1,6 @@ import pype.maya.plugin import os -import json +from pypeapp import config class AbcLoader(pype.maya.plugin.ReferenceLoader): @@ -36,14 +36,8 @@ class AbcLoader(pype.maya.plugin.ReferenceLoader): cmds.makeIdentity(groupName, apply=False, rotate=True, translate=True, scale=True) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) - + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: cmds.setAttr(groupName + ".useOutlinerColor", 1) diff --git a/pype/plugins/maya/load/load_ass.py b/pype/plugins/maya/load/load_ass.py index c268ce70c5..979d4b5767 100644 --- a/pype/plugins/maya/load/load_ass.py +++ b/pype/plugins/maya/load/load_ass.py @@ -2,7 +2,7 @@ from avalon import api import pype.maya.plugin import os import pymel.core as pm -import json +from pypeapp import config class AssProxyLoader(pype.maya.plugin.ReferenceLoader): @@ -50,13 +50,8 @@ class AssProxyLoader(pype.maya.plugin.ReferenceLoader): proxyShape.dso.set(path) proxyShape.aiOverrideShaders.set(0) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: @@ -165,13 +160,8 @@ class AssStandinLoader(api.Loader): label = "{}:{}".format(namespace, name) root = pm.group(name=label, empty=True) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get('ass') if c is not None: diff --git a/pype/plugins/maya/load/load_camera.py b/pype/plugins/maya/load/load_camera.py index 989e80e979..e9bf265b98 100644 --- a/pype/plugins/maya/load/load_camera.py +++ b/pype/plugins/maya/load/load_camera.py @@ -1,6 +1,6 @@ import pype.maya.plugin import os -import json +from pypeapp import config class CameraLoader(pype.maya.plugin.ReferenceLoader): @@ -35,13 +35,8 @@ class CameraLoader(pype.maya.plugin.ReferenceLoader): cameras = cmds.ls(nodes, type="camera") - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: diff --git a/pype/plugins/maya/load/load_fbx.py b/pype/plugins/maya/load/load_fbx.py index b580257334..14df300c3c 100644 --- a/pype/plugins/maya/load/load_fbx.py +++ b/pype/plugins/maya/load/load_fbx.py @@ -1,6 +1,6 @@ import pype.maya.plugin import os -import json +from pypeapp import config class FBXLoader(pype.maya.plugin.ReferenceLoader): @@ -36,13 +36,9 @@ class FBXLoader(pype.maya.plugin.ReferenceLoader): groupName="{}:{}".format(namespace, name)) groupName = "{}:{}".format(namespace, name) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: diff --git a/pype/plugins/maya/load/load_mayaascii.py b/pype/plugins/maya/load/load_mayaascii.py index 549d1dff4c..03a15b0524 100644 --- a/pype/plugins/maya/load/load_mayaascii.py +++ b/pype/plugins/maya/load/load_mayaascii.py @@ -1,5 +1,5 @@ import pype.maya.plugin -import json +from pypeapp import config import os @@ -36,13 +36,9 @@ class MayaAsciiLoader(pype.maya.plugin.ReferenceLoader): self[:] = nodes groupName = "{}:{}".format(namespace, name) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: diff --git a/pype/plugins/maya/load/load_model.py b/pype/plugins/maya/load/load_model.py index 16f3556de7..913d4d9e79 100644 --- a/pype/plugins/maya/load/load_model.py +++ b/pype/plugins/maya/load/load_model.py @@ -1,7 +1,8 @@ from avalon import api import pype.maya.plugin -import json import os +from pypeapp import config +reload(config) class ModelLoader(pype.maya.plugin.ReferenceLoader): @@ -21,18 +22,6 @@ class ModelLoader(pype.maya.plugin.ReferenceLoader): import maya.cmds as cmds from avalon import maya - try: - family = context["representation"]["context"]["family"] - except ValueError: - family = "model" - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) - with maya.maintained_selection(): groupName = "{}:{}".format(namespace, name) @@ -46,7 +35,9 @@ class ModelLoader(pype.maya.plugin.ReferenceLoader): cmds.makeIdentity(groupName, apply=False, rotate=True, translate=True, scale=True) - c = colors.get(family) + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] + c = colors.get('model') if c is not None: cmds.setAttr(groupName + ".useOutlinerColor", 1) cmds.setAttr(groupName + ".outlinerColor", @@ -89,14 +80,9 @@ class GpuCacheLoader(api.Loader): # Root group label = "{}:{}".format(namespace, name) root = cmds.group(name=label, empty=True) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get('model') if c is not None: cmds.setAttr(root + ".useOutlinerColor", 1) @@ -196,14 +182,8 @@ class AbcModelLoader(pype.maya.plugin.ReferenceLoader): cmds.makeIdentity(groupName, apply=False, rotate=True, translate=True, scale=True) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) - + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get('model') if c is not None: cmds.setAttr(groupName + ".useOutlinerColor", 1) diff --git a/pype/plugins/maya/load/load_rig.py b/pype/plugins/maya/load/load_rig.py index 1dcff45bb9..66b086c861 100644 --- a/pype/plugins/maya/load/load_rig.py +++ b/pype/plugins/maya/load/load_rig.py @@ -3,7 +3,7 @@ from maya import cmds import pype.maya.plugin from avalon import api, maya import os -import json +from pypeapp import config class RigLoader(pype.maya.plugin.ReferenceLoader): @@ -39,13 +39,8 @@ class RigLoader(pype.maya.plugin.ReferenceLoader): cmds.makeIdentity(groupName, apply=False, rotate=True, translate=True, scale=True) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: diff --git a/pype/plugins/maya/load/load_vdb_to_redshift.py b/pype/plugins/maya/load/load_vdb_to_redshift.py index 169c3bf34a..ee7c301b1b 100644 --- a/pype/plugins/maya/load/load_vdb_to_redshift.py +++ b/pype/plugins/maya/load/load_vdb_to_redshift.py @@ -1,7 +1,6 @@ from avalon import api import os -import json - +from pypeapp import config class LoadVDBtoRedShift(api.Loader): """Load OpenVDB in a Redshift Volume Shape""" @@ -55,13 +54,9 @@ class LoadVDBtoRedShift(api.Loader): # Root group label = "{}:{}".format(namespace, name) root = cmds.group(name=label, empty=True) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: diff --git a/pype/plugins/maya/load/load_vdb_to_vray.py b/pype/plugins/maya/load/load_vdb_to_vray.py index 58d6d1b56e..3b15b71e3e 100644 --- a/pype/plugins/maya/load/load_vdb_to_vray.py +++ b/pype/plugins/maya/load/load_vdb_to_vray.py @@ -1,5 +1,5 @@ from avalon import api -import json +from pypeapp import config import os @@ -47,13 +47,9 @@ class LoadVDBtoVRay(api.Loader): # Root group label = "{}:{}".format(namespace, name) root = cmds.group(name=label, empty=True) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: diff --git a/pype/plugins/maya/load/load_vrayproxy.py b/pype/plugins/maya/load/load_vrayproxy.py index a3a114440a..9b07dc7e30 100644 --- a/pype/plugins/maya/load/load_vrayproxy.py +++ b/pype/plugins/maya/load/load_vrayproxy.py @@ -1,6 +1,6 @@ from avalon.maya import lib from avalon import api -import json +from pypeapp import config import os import maya.cmds as cmds @@ -26,14 +26,6 @@ class VRayProxyLoader(api.Loader): except ValueError: family = "vrayproxy" - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) - asset_name = context['asset']["name"] namespace = namespace or lib.unique_namespace( asset_name + "_", @@ -54,6 +46,9 @@ class VRayProxyLoader(api.Loader): if not nodes: return + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] + c = colors.get(family) if c is not None: cmds.setAttr("{0}_{1}.useOutlinerColor".format(name, "GRP"), 1) diff --git a/pype/plugins/maya/load/load_yeti_cache.py b/pype/plugins/maya/load/load_yeti_cache.py index b19bed1393..dc976c0c98 100644 --- a/pype/plugins/maya/load/load_yeti_cache.py +++ b/pype/plugins/maya/load/load_yeti_cache.py @@ -9,6 +9,7 @@ from maya import cmds from avalon import api from avalon.maya import lib as avalon_lib, pipeline from pype.maya import lib +from pypeapp import config class YetiCacheLoader(api.Loader): @@ -54,13 +55,9 @@ class YetiCacheLoader(api.Loader): group_name = "{}:{}".format(namespace, name) group_node = cmds.group(nodes, name=group_name) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: diff --git a/pype/plugins/maya/load/load_yeti_rig.py b/pype/plugins/maya/load/load_yeti_rig.py index c821c6ca02..eb75ff6bdc 100644 --- a/pype/plugins/maya/load/load_yeti_rig.py +++ b/pype/plugins/maya/load/load_yeti_rig.py @@ -1,6 +1,6 @@ import pype.maya.plugin import os -import json +from pypeapp import config class YetiRigLoader(pype.maya.plugin.ReferenceLoader): @@ -27,13 +27,9 @@ class YetiRigLoader(pype.maya.plugin.ReferenceLoader): groupName="{}:{}".format(namespace, name)) groupName = "{}:{}".format(namespace, name) - preset_file = os.path.join( - os.environ.get('PYPE_STUDIO_TEMPLATES'), - 'presets', 'tools', - 'family_colors.json' - ) - with open(preset_file, 'r') as cfile: - colors = json.load(cfile) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] c = colors.get('yetiRig') if c is not None: