Utilties¶
Environment handling¶
- addToEnv(env, newPaths)¶
Adds the specified environment paths to the environment variable if the path doesn’t already exist.
- removeFromEnv(env, values)¶
Removes the specified values from the environment variable.
The comparison is an exact match between os.pathsep.
- isInMaya(executable=None)¶
Determines if the current running executable is maya.exe
- Returns
True if running maya.exe
- Return type
- isMayapy(executable=None)¶
Determines if the current running executable is mayapy.exe
- Returns
True if running mayapy.exe
- Return type
- isMayaBatch(executable=None)¶
Determines if the current running executable is mayabatch.exe
- Returns
True if running mayapy.exe
- Return type
- isMaya(executable=None)¶
Combination of isMayapy, isInMaya and isMayaBatch
- Parameters
executable – True if running maya and it’s variants
- Returns
- Return type
- isIn3dsmax(executable=None)¶
Determines if the current running executable is 3dsmax.exe
- Returns
True if running 3dsmax.exe
- Return type
- isInMotionBuilder(executable=None)¶
Determines if the current running executable is motionbuilder.exe
- Returns
True if running motionbuilder.exe
- Return type
- isInHoudini(executable=None)¶
Determines if the current running executable is houdini.exe
- Returns
True if running houdini.exe
- Return type
- isInBlender(executable=None)¶
Determines if the current running executable is blender
- Returns
True if running blender.exe
- Return type
- application()¶
Returns the currently running application
- Returns
returns one of the following: maya 3dsmax motionbuilder houdini standalone
- Return type
- machineInfo()¶
Returns basic information about the current pc that this code is running on
- Returns
- {‘OSRelease’: ‘7’,
’OSVersion’: ‘Windows-7-6.1.7601-SP1’, ‘executable’: ‘C:Program FilesAutodeskMaya2018binmaya.exe’, ‘machineType’: ‘AMD64’, ‘node’: ‘COMPUTERNAME’, ‘processor’: ‘Intel64 Family 6 Model 44 Stepping 2, GenuineIntel’, ‘pythonVersion’: ‘2.7.11 (default, Jul 1 2016, 02:08:48) [MSC v.1900 64 bit (AMD64)]’, ‘syspaths’: list(str), ‘env’: dict(os.environ) }
- Return type
- user(lower=True)¶
Returns the current user name
- isPy3()¶
Is python 3 or greater
- Returns
bool
Filesystem¶
- ensureFolderExists(path, permissions=509, placeHolder=False)¶
if the folder doesnt exist then one will be created. Function built due to version control mishaps with uncommited empty folders, this folder can generate a place holder file.
- loadJson(filePath)¶
This procedure loads and returns the data of a json file
- Return type{dict}
the content of the file
- saveJson(data, filepath, **kws)¶
This procedure saves given data to a json file
- zipdir(directory, outputPath, filters=())¶
Creates a zip file from a given directory recursively.
Use ‘filters’ to supply a fnmatch expression to exclude a directory or files.
Processes¶
- subprocessCheckOutput(*args, **kwargs)¶
called subprocess.Popen with communicate()
- checkOutput(*args, **kwargs)¶
Helper function that handles sub processing safely on win32 which requires extra flags
- class Singleton¶
Bases:
type
Singleton metaclass that overrides the __call__ method and always returns a single class instance of the cls.
This module deals with module paths, importing and the like.
- importModule(modulePath, name=None)¶
Imports the modulePath, if ModulePath is a dottedPath then the function will use importlib otherwise it’s expected that modulePath is the absolute path to the source file. If the name arg is not provided then the basename without the extension will be used.
- iterModules(path, exclude=None)¶
Iterate of the modules of a given folder path
- Parameters
path – str, The folder path to iterate
exclude – list, a list of files to exclude
- Returns
iterator
- iterMembers(module, predicate=None)¶
Iterates the members of the module, use predicte to restrict to a type
:param module:Object, the module object to iterate :param predicate: inspect.class :return:iterator
- isDottedPath(path)¶
Determines if the path is a dotted path. Bit of a hack
- Parameters
path – str
- Returns
bool
- iterSubclassesFromModule(module, classType)¶
Iterates all classes within a module object returning subclasses of type classType.
- asDottedPath(path)¶
Returns a dotted path relative to the python path.
import sys currentPath = os.path.expanduser("someRandomPath") sys.path.append(currentPath) asDottedPath("someRandomPath/subfolder/subsubfolder.py") #result: subfolder.subsubfolder
- class CentralLogManager(*args, **kwargs)¶
Bases:
object
This class is a singleton object that globally handles logging, any log added will managed by the class.
- addLog(logger)¶
Adds logger to this manager instance
- Parameters
logger (
logging.Logger
) – the python logger instance.
- removeLog(loggerName)¶
Remove’s the logger instance by name
- Parameters
loggerName – The logger instance name.
- Type
loggerName: str
- changeLevel(loggerName, level)¶
Changes the logger instance level.
- addRotateHandler(loggerName, filePath)¶
- addShellHandler(loggerName)¶
- addNullHandler(loggerName)¶
- levelsDict()¶
Returns the stdlib logging levels as a dict.
The keys are the formal logging names and values are the logging constant value.
- Return type
dict[str: int]
- getLogger(name)¶
Returns the Zoo tools log name in the form of ‘zootools.*.*’
This is to ensure consistent logging names across all applications
- Parameters
name (str) – The logger name to format.
- Returns
- Return type
- globalLogLevelOverride(logger)¶
- reloadLoggerHierarchy()¶
- iterLoggers()¶
Iterates through all zootools loggers.
- Returns
generator(str, logging.Logger)
- rootLogger()¶
Retrieves the top most zootools logger instance in the zoo hierarchy
- setGlobalDebug(state)¶
Toggles the root zoo tools logger between DEBUG and INFO
This flush module is a hardcore deletion of modules that live in sys.modules dict
- flushUnder(dirpath)¶
Flushes all modules that live under the given directory
- Parameters
dirpath (str) – the name of the top most directory to search under.
- reloadZoo()¶
Reload all zoo modules from sys.modules This makes it trivial to make changes to plugin that have potentially complex reload dependencies.
import flush;flush.reloadZoo()
The above will force all zoo modules to be reloaded by loops over all base packages path in the environment variable “ZOO_BASE_PATHS” then calling flushUnder(basePath)