Integrating up through commit 90f050496

This commit is contained in:
alexpete
2021-04-07 14:03:29 -07:00
parent 8f2ed080a9
commit c2cbd430fe
2694 changed files with 285622 additions and 176874 deletions
@@ -0,0 +1,16 @@
# coding:utf-8
#!/usr/bin/python
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# -- This line is 75 characters -------------------------------------------
# define api package for each IDE supported
__all__ = ['check']
@@ -0,0 +1,18 @@
# coding:utf-8
#!/usr/bin/python
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# -- This line is 75 characters -------------------------------------------
# define api package for each IDE supported
__all__ = ['running_state', 'maya_app']
# maya_app, named such to avoid namespace collisions with maya dcc app api
@@ -0,0 +1,157 @@
# coding:utf-8
#!/usr/bin/python
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# -- This line is 75 characters -------------------------------------------
# -- Standard Python modules --
import sys
import os
import inspect
import logging as _logging
# -- External Python modules --
# none
# -- Extension Modules --
import azpy
from azpy.env_bool import env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
# --------------------------------------------------------------------------
# -- Global Definitions --
_DCCSI_DCC_APP = None
# set up global space, logging etc.
_G_DEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
_MODULENAME = 'azpy.dev.utils.check.maya_app'
_LOGGER = _logging.getLogger(_MODULENAME)
# -------------------------------------------------------------------------
###########################################################################
## These mini-functions need to be defined, before they are called
# -------------------------------------------------------------------------
# run this, if we are in Maya
def set_dcc_app(dcc_app='maya'):
"""
azpy.dev.utils.check.maya.set_dcc_app()
this will set global _DCCSI_DCC_APP = 'maya'
and os.environ["DCCSI_DCC_APP"] = 'maya'
"""
_DCCSI_DCC_APP = dcc_app
_LOGGER.info('Setting DCCSI_DCC_APP to: {0}'.format(dcc_app))
return _DCCSI_DCC_APP
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def clear_dcc_app(dcc_app=False):
"""
azpy.dev.utils.check.maya.set_dcc_app()
this will set global _DCCSI_DCC_APP = False
and os.environ["DCCSI_DCC_APP"] = False
"""
_DCCSI_DCC_APP = dcc_app
_LOGGER.info('Setting DCCSI_DCC_APP to: {0}'.format(dcc_app))
return _DCCSI_DCC_APP
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def validate_state(DCCSI_DCC_APP=_DCCSI_DCC_APP):
'''
This will detect if we are running in Maya or not,
then will call either, set_dcc_app('maya') or clear_dcc_app(dcc_app=False)
'''
if _G_DEBUG:
_LOGGER.debug(autolog())
try:
import maya.cmds as cmds
DCCSI_DCC_APP = set_dcc_app('maya')
except ImportError as e:
_LOGGER.warning('Can not perform: import maya.cmds as cmds')
DCCSI_DCC_APP = clear_dcc_app()
else:
try:
if cmds.about(batch=True):
DCCSI_DCC_APP = set_dcc_app('maya')
except AttributeError as e:
_LOGGER.warning("maya.cmds module isn't fully loaded/populated, "
"(cmds populates only in batch, maya.standalone, or maya GUI)")
# NO Maya
DCCSI_DCC_APP=clear_dcc_app()
return DCCSI_DCC_APP
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def autolog():
'''Automatically log the current function details.'''
# Get the previous frame in the stack, otherwise it would
# be this function!!!
func = inspect.currentframe().f_back.f_back.f_code
# Dump the message + the name of this function to the log.
output = ('{module} AUTOLOG:\r'
'Called from::\n{0}():\r'
'In file: {1},\r'
'At line: {2}\n'
''.format(func.co_name,
func.co_filename,
func.co_firstlineno,
module=_MODULENAME))
return output
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
# run the check on import
_DCCSI_DCC_APP = validate_state()
# -------------------------------------------------------------------------
###########################################################################
# Main Code Block, runs this script as main (testing)
# -------------------------------------------------------------------------
if __name__ == '__main__':
# there are not really tests to run here due to this being a list of
# constants for shared use.
_G_DEBUG = True
_DCCSI_DEV_MODE = True
_LOGGER.setLevel(_logging.DEBUG) # force debugging
## reduce cyclical azpy imports
## it only has a basic logger configured, add log to console
#_handler = _logging.StreamHandler(sys.stdout)
#_handler.setLevel(_logging.DEBUG)
#FRMT_LOG_LONG = "[%(name)s][%(levelname)s] >> %(message)s (%(asctime)s; %(filename)s:%(lineno)d)"
#_formatter = _logging.Formatter(FRMT_LOG_LONG)
#_handler.setFormatter(_formatter)
#_LOGGER.addHandler(_handler)
#_LOGGER.debug('Loading: {0}.'.format({_MODULENAME}))
# happy print
from azpy.constants import STR_CROSSBAR
_LOGGER.info(STR_CROSSBAR)
_LOGGER.info('{} ... Running script as __main__'.format(_MODULENAME))
_LOGGER.info(STR_CROSSBAR)
_DCCSI_DCC_APP = validate_state()
_LOGGER.info('Is Maya Running? _DCCSI_DCC_APP = {}'.format(_DCCSI_DCC_APP))
@@ -0,0 +1,257 @@
# coding:utf-8
#!/usr/bin/python
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# -- This line is 75 characters -------------------------------------------
# -- Standard Python modules --
import sys
import os
import logging as _logging
# -- External Python modules --
# none
# -- Extension Modules --
# none (yet)
# --------------------------------------------------------------------------
# -- Global Definitions --
_DCCSI_DCC_APP = None
_MODULENAME = 'azpy.dev.utils.check.running_state'
_LOGGER = _logging.getLogger(_MODULENAME)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# First Class
class CheckRunningState(object):
"""
< To Do: document Class >
"""
# Class Variables
DCCSI_DCC_APP = None
def __init__(self, *args, **kwargs):
'''
CheckRunningState Class Initialization
< To Do: Need to document >
Input Attributes:
-----------------
self. -> SCALAR: Description.
Default =
Keyword Arguments:
------------------
self. -> STRING: Description.
Default =
self. -> OBJECT: Description.
Default =
Additional Attributes:
----------------------
self. -> BOOLEAN: Description.
Default =
Documentation last updated: Month. Day, Year - Author
'''
# -- Default Values --
# top level storage for whether or not we are running
# in a DCC tool interpreter
self._dcc_py = False
# basic python info
# if these can't run, we are in a bad state anyway
self._python = sys.version
self._py_version_info = sys.version_info
# -- Input Checks --
self.check_known()
# ---------------------------------------------------------------------
# --method-------------------------------------------------------------
def check_known(self):
# -- init --
# first let's check if any of these DCC apps are running
# 0 - maya first
CheckRunningState.DCCSI_DCC_APP = self.maya_running()
# 1 - then max
if not CheckRunningState.DCCSI_DCC_APP:
CheckRunningState.DCCSI_DCC_APP = self.max_running()
else:
_LOGGER.warning('DCCSI_DCC_APP is already set: {}'.format(CheckRunningState.DCCSI_DCC_APP))
# 2 - then blender
if not CheckRunningState.DCCSI_DCC_APP:
CheckRunningState.DCCSI_DCC_APP = self.blender_running()
else:
_LOGGER.warning('DCCSI_DCC_APP is already set: {}'.format(CheckRunningState.DCCSI_DCC_APP))
# store checks for DCC info
if CheckRunningState.DCCSI_DCC_APP:
self.dcc_py = True
# store check for is maya running headless
if CheckRunningState.DCCSI_DCC_APP == 'maya':
self.maya_headless = self.is_maya_headless()
# set a envar other modules can easily check
if CheckRunningState.DCCSI_DCC_APP:
os.environ['DCCSI_DCC_APP'] = CheckRunningState.DCCSI_DCC_APP
# ---------------------------------------------------------------------
#--properties----------------------------------------------------------
@property
def python(self):
return self._python
@python.setter
def python(self, value):
self._python = value
return self._python
@property
def py_version_info(self):
return self._py_version_info
@py_version_info.setter
def py_version_info(self, value):
self._py_version_info = value
return self._py_version_info
@property
def dcc_app(self):
return self._dcc_py
@dcc_app.setter
def dcc_app(self, value):
self._dcc_py = value
return self._dcc_py
@property
def maya_headless(self):
return self._maya_headless
@maya_headless.setter
def maya_headless(self, value):
self._maya_headless = value
return self._maya_headless
# template property
# @property
# def foo(self):
# return self._foo
# @foo.setter
# def foo(self, value):
#self._foo = value
# return self._foo
# --properties----------------------------------------------------------
# --method-------------------------------------------------------------
def maya_running(self):
"""< To Do: Need to document >"""
try:
import azpy.dev.utils.check.maya_app as check_dcc
DCCSI_DCC_APP = check_dcc.validate_state()
except ImportError as e:
_LOGGER.info('Not Implemented: azpy.dev.utils.check.maya_app')
if DCCSI_DCC_APP:
CheckRunningState.DCCSI_DCC_APP = check_dcc.validate_state()
os.environ["DCCSI_DCC_APP"] = str(DCCSI_DCC_APP)
return CheckRunningState.DCCSI_DCC_APP
#----------------------------------------------------------------------
# --method-------------------------------------------------------------
def is_maya_headless(self):
"""< To Do: Need to document >"""
if self.maya_app:
import maya.cmds as mc
try:
if mc.about(batch=True):
return True
else:
return False
except Exception as e:
# cmds module isn't fully loaded/populated
# (which only happens in batch, maya.standalone, or maya GUI)
# no maya
return False
else:
return False
# --method-------------------------------------------------------------
# --method-------------------------------------------------------------
def max_running(self):
"""
< To Do: implement >
"""
try:
import azpy.dev.utils.check.max_app as check_dcc
CheckRunningState.DCCSI_DCC_APP = check_dcc.validate_state()
except ImportError as e:
_LOGGER.info('Not Implemented: azpy.dev.utils.check.max')
if CheckRunningState.DCCSI_DCC_APP:
CheckRunningState.DCCSI_DCC_APP = check_dcc.validate_state()
os.environ["DCCSI_DCC_APP"] = str(CheckRunningState.DCCSI_DCC_APP)
return CheckRunningState.DCCSI_DCC_APP
#----------------------------------------------------------------------
# --method-------------------------------------------------------------
def blender_running(self):
"""
< To Do: implement >
"""
try:
import azpy.dev.utils.check.blender_app as check_dcc
CheckRunningState.DCCSI_DCC_APP = check_dcc.validate_state()
except ImportError as e:
_LOGGER.info('Not Implemented: azpy.dev.utils.check.blender')
if CheckRunningState.DCCSI_DCC_APP:
CheckRunningState.DCCSI_DCC_APP = check_dcc.validate_state()
os.environ["DCCSI_DCC_APP"] = str(CheckRunningState.DCCSI_DCC_APP)
return CheckRunningState.DCCSI_DCC_APP
#----------------------------------------------------------------------
#==========================================================================
# Class Test
#==========================================================================
if __name__ == '__main__':
_G_DEBUG = True
_DCCSI_DEV_MODE = True
_LOGGER.setLevel(_logging.DEBUG) # force debugging
# -- Extend Logger
#_handler = _logging.StreamHandler(sys.stdout)
# _handler.setLevel(_logging.DEBUG)
#FRMT_LOG_LONG = "[%(name)s][%(levelname)s] >> %(message)s (%(asctime)s; %(filename)s:%(lineno)d)"
#_formatter = _logging.Formatter(FRMT_LOG_LONG)
# _handler.setFormatter(_formatter)
# _LOGGER.addHandler(_handler)
#_LOGGER.debug('Loading: {0}.'.format({_MODULENAME}))
# happy print
from azpy.constants import STR_CROSSBAR
_LOGGER.info(STR_CROSSBAR)
_LOGGER.info('{} ... Running script as __main__'.format(_MODULENAME))
_LOGGER.info(STR_CROSSBAR)
foo = CheckRunningState()
_LOGGER.info('DCCSI_DCC_APP: {}'.format(foo.DCCSI_DCC_APP))