<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import os . path , sys , glob , inspect <EOL> import maya <EOL> import maya . OpenMaya as om <EOL> import maya . utils <EOL> from pymel . util import picklezip , shellOutput , subpackages , refreshEnviron , namedtuple <EOL> import pymel . versions as versions <EOL> from pymel . mayautils import getUserPrefsDir <EOL> from pymel . versions import shortName , installName <EOL> import plogging <EOL> _logger = plogging . getLogger ( __name__ ) <EOL> try : <EOL> import cPickle as pickle <EOL> except : <EOL> _logger . warning ( "<STR_LIT>" ) <EOL> import pickle <EOL> isInitializing = False <EOL> finalizeEnabled = True <EOL> _finalizeCalled = False <EOL> pymelMayaPackage = hasattr ( maya . utils , '<STR_LIT>' ) or versions . current ( ) >= versions . v2011 <EOL> def _moduleJoin ( * args ) : <EOL> """<STR_LIT>""" <EOL> moduleDir = os . path . dirname ( os . path . dirname ( sys . modules [ __name__ ] . __file__ ) ) <EOL> return os . path . realpath ( os . path . join ( moduleDir , * args ) ) <EOL> def mayaStartupHasRun ( ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' in sys . modules or '<STR_LIT>' in sys . modules <EOL> def mayaStartupHasStarted ( ) : <EOL> """<STR_LIT>""" <EOL> return hasattr ( maya , '<STR_LIT>' ) <EOL> def setupFormatting ( ) : <EOL> import pprint <EOL> import maya . utils <EOL> def myResultCallback ( obj ) : <EOL> return pprint . pformat ( obj ) <EOL> maya . utils . formatGuiResult = myResultCallback <EOL> maya . utils . formatGuiResult . __module__ = '<STR_LIT>' <EOL> def mayaInit ( forversion = None ) : <EOL> """<STR_LIT>""" <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> setupFormatting ( ) <EOL> global isInitializing <EOL> aboutExists = False <EOL> try : <EOL> from maya . cmds import about <EOL> aboutExists = True <EOL> except ImportError : <EOL> pass <EOL> if aboutExists and mayaStartupHasStarted ( ) : <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> isInitializing = False <EOL> return False <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if not aboutExists and not sys . modules . has_key ( '<STR_LIT>' ) : <EOL> try : <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> import maya . standalone <EOL> maya . standalone . initialize ( name = "<STR_LIT>" ) <EOL> if versions . current ( ) < versions . v2009 : <EOL> refreshEnviron ( ) <EOL> except ImportError , e : <EOL> raise e , str ( e ) + "<STR_LIT>" <EOL> try : <EOL> from maya . cmds import about <EOL> except Exception : <EOL> _logger . error ( "<STR_LIT>" ) <EOL> raise <EOL> if not mayaStartupHasRun ( ) : <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> if about ( batch = True ) : <EOL> import maya . app . startup . batch <EOL> else : <EOL> import maya . app . startup . gui <EOL> isInitializing = True <EOL> return True <EOL> def initMEL ( ) : <EOL> if '<STR_LIT>' in os . environ or pymel_options . get ( '<STR_LIT>' , False ) : <EOL> _logger . info ( "<STR_LIT>" ) <EOL> return <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> mayaVersion = versions . installName ( ) <EOL> prefsDir = getUserPrefsDir ( ) <EOL> if prefsDir is None : <EOL> _logger . error ( "<STR_LIT>" ) <EOL> elif not os . path . isdir ( prefsDir ) : <EOL> _logger . error ( "<STR_LIT>" % prefsDir ) <EOL> startup = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> os . path . join ( prefsDir , '<STR_LIT>' ) if prefsDir else None , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> os . path . join ( prefsDir , '<STR_LIT>' ) if prefsDir else None , <EOL> os . path . join ( prefsDir , '<STR_LIT>' ) if prefsDir else None <EOL> ] <EOL> try : <EOL> for f in startup : <EOL> _logger . debug ( "<STR_LIT>" % f ) <EOL> if f is not None : <EOL> if os . path . isabs ( f ) and not os . path . exists ( f ) : <EOL> _logger . warning ( "<STR_LIT>" % f ) <EOL> else : <EOL> if isinstance ( f , unicode ) : <EOL> encoding = '<STR_LIT>' <EOL> else : <EOL> encoding = '<STR_LIT>' <EOL> import maya . mel <EOL> maya . mel . eval ( '<STR_LIT>' % f . encode ( encoding ) ) <EOL> except Exception , e : <EOL> _logger . error ( "<STR_LIT>" % ( f , e ) ) <EOL> try : <EOL> res = maya . mel . eval ( '<STR_LIT>' ) <EOL> if res != '<STR_LIT>' : <EOL> maya . mel . eval ( '<STR_LIT>' ) <EOL> except RuntimeError : pass <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> def initAE ( ) : <EOL> try : <EOL> pkg = __import__ ( '<STR_LIT>' ) <EOL> except ImportError : <EOL> return False <EOL> except Exception : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> return False <EOL> else : <EOL> for data in subpackages ( pkg ) : <EOL> pass <EOL> return True <EOL> def finalize ( ) : <EOL> global finalizeEnabled <EOL> global _finalizeCalled <EOL> if not finalizeEnabled or _finalizeCalled : <EOL> return <EOL> _logger . debug ( '<STR_LIT>' ) <EOL> _finalizeCalled = True <EOL> global isInitializing <EOL> if pymelMayaPackage and isInitializing : <EOL> assert '<STR_LIT>' in sys . modules , "<STR_LIT>" <EOL> import maya . app . startup . basic <EOL> maya . app . startup . basic . executeUserSetup ( ) <EOL> state = om . MGlobal . mayaState ( ) <EOL> if state == om . MGlobal . kLibraryApp : <EOL> initMEL ( ) <EOL> elif state == om . MGlobal . kInteractive : <EOL> initAE ( ) <EOL> def fixMayapy2011SegFault ( ) : <EOL> if versions . v2011 <= versions . current ( ) < versions . v2013 : <EOL> import platform <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> if om . MGlobal . mayaState ( ) == om . MGlobal . kLibraryApp : <EOL> import sys <EOL> import atexit <EOL> _orig_exit = sys . exit <EOL> if not hasattr ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sys . _orig_exit = _orig_exit <EOL> def exit ( status ) : <EOL> sys . _exit_status = status <EOL> _orig_exit ( status ) <EOL> sys . exit = exit <EOL> def hardExit ( ) : <EOL> import sys <EOL> atexit . _run_exitfuncs ( ) <EOL> try : <EOL> print "<STR_LIT>" <EOL> except Exception : <EOL> pass <EOL> import os <EOL> import sys <EOL> exitStatus = getattr ( sys , '<STR_LIT>' , None ) <EOL> if exitStatus is None : <EOL> last_value = getattr ( sys , '<STR_LIT>' , None ) <EOL> if last_value is not None : <EOL> if isinstance ( last_value , SystemExit ) : <EOL> try : <EOL> exitStatus = last_value . args [ <NUM_LIT:0> ] <EOL> except Exception : pass <EOL> if exitStatus is None : <EOL> exitStatus = <NUM_LIT:1> <EOL> if exitStatus is None : <EOL> exitStatus = <NUM_LIT:0> <EOL> os . _exit ( exitStatus ) <EOL> atexit . register ( hardExit ) <EOL> def encodeFix ( ) : <EOL> if mayaInit ( ) : <EOL> from maya . cmds import about <EOL> mayaEncode = about ( cs = True ) <EOL> pyEncode = sys . getdefaultencoding ( ) <EOL> if mayaEncode != pyEncode : <EOL> if not about ( b = True ) : <EOL> import maya . utils <EOL> try : <EOL> import maya . app . baseUI <EOL> import codecs <EOL> sys . stdin = codecs . getreader ( mayaEncode ) ( maya . app . baseUI . StandardInput ( ) ) <EOL> sys . stdout = codecs . getwriter ( mayaEncode ) ( maya . utils . Output ( ) ) <EOL> sys . stderr = codecs . getwriter ( mayaEncode ) ( maya . utils . Output ( error = <NUM_LIT:1> ) ) <EOL> except ImportError : <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> def _dump ( data , filename , protocol = - <NUM_LIT:1> ) : <EOL> with open ( filename , mode = '<STR_LIT:wb>' ) as file : <EOL> pickle . dump ( data , file , protocol ) <EOL> def _load ( filename ) : <EOL> with open ( filename , mode = '<STR_LIT:rb>' ) as file : <EOL> res = pickle . load ( file ) <EOL> return res <EOL> class PymelCache ( object ) : <EOL> NAME = '<STR_LIT>' <EOL> DESC = '<STR_LIT>' <EOL> COMPRESSED = True <EOL> USE_VERSION = True <EOL> def read ( self ) : <EOL> newPath = self . path ( ) <EOL> if self . COMPRESSED : <EOL> func = picklezip . load <EOL> else : <EOL> func = _load <EOL> _logger . debug ( self . _actionMessage ( '<STR_LIT>' , '<STR_LIT>' , newPath ) ) <EOL> try : <EOL> return func ( newPath ) <EOL> except Exception , e : <EOL> self . _errorMsg ( '<STR_LIT>' , '<STR_LIT>' , newPath , e ) <EOL> def write ( self , data ) : <EOL> newPath = self . path ( ) <EOL> if self . COMPRESSED : <EOL> func = picklezip . dump <EOL> else : <EOL> func = _dump <EOL> _logger . info ( self . _actionMessage ( '<STR_LIT>' , '<STR_LIT:to>' , newPath ) ) <EOL> try : <EOL> func ( data , newPath , <NUM_LIT:2> ) <EOL> except Exception , e : <EOL> self . _errorMsg ( '<STR_LIT>' , '<STR_LIT:to>' , newPath , e ) <EOL> def path ( self ) : <EOL> if self . USE_VERSION : <EOL> if hasattr ( self , '<STR_LIT:version>' ) : <EOL> short_version = str ( self . version ) <EOL> else : <EOL> short_version = shortName ( ) <EOL> else : <EOL> short_version = '<STR_LIT>' <EOL> newPath = _moduleJoin ( '<STR_LIT>' , self . NAME + short_version ) <EOL> if self . COMPRESSED : <EOL> newPath += '<STR_LIT>' <EOL> else : <EOL> newPath += '<STR_LIT>' <EOL> return newPath <EOL> @ classmethod <EOL> def _actionMessage ( cls , action , direction , location ) : <EOL> '''<STR_LIT>''' <EOL> description = cls . DESC <EOL> if description : <EOL> description = '<STR_LIT:U+0020>' + description <EOL> return "<STR_LIT>" % ( action , description , direction , location ) <EOL> @ classmethod <EOL> def _errorMsg ( cls , action , direction , path , error ) : <EOL> '''<STR_LIT>''' <EOL> actionMsg = cls . _actionMessage ( action , direction , path ) <EOL> _logger . error ( "<STR_LIT>" % ( actionMsg , error ) ) <EOL> import traceback <EOL> _logger . debug ( traceback . format_exc ( ) ) <EOL> class SubItemCache ( PymelCache ) : <EOL> '''<STR_LIT>''' <EOL> _CACHE_NAMES = [ ] <EOL> ITEM_TYPES = { } <EOL> STORAGE_TYPES = { } <EOL> DEFAULT_TYPE = dict <EOL> def __init__ ( self ) : <EOL> for name in self . _CACHE_NAMES : <EOL> self . initVal ( name ) <EOL> def cacheNames ( self ) : <EOL> return tuple ( self . _CACHE_NAMES ) <EOL> def initVal ( self , name ) : <EOL> itemType = self . itemType ( name ) <EOL> if itemType is None : <EOL> val = None <EOL> else : <EOL> val = itemType ( ) <EOL> setattr ( self , name , val ) <EOL> def itemType ( self , name ) : <EOL> return self . ITEM_TYPES . get ( name , self . DEFAULT_TYPE ) <EOL> def build ( self ) : <EOL> """<STR_LIT>""" <EOL> data = self . load ( ) <EOL> if data is None : <EOL> self . rebuild ( ) <EOL> self . save ( ) <EOL> def rebuild ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def update ( self , obj , cacheNames = None ) : <EOL> '''<STR_LIT>''' <EOL> if cacheNames is None : <EOL> cacheNames = self . cacheNames ( ) <EOL> if isinstance ( obj , dict ) : <EOL> for key , val in obj . iteritems ( ) : <EOL> setattr ( self , key , val ) <EOL> elif isinstance ( obj , ( list , tuple ) ) : <EOL> if len ( obj ) != len ( cacheNames ) : <EOL> raise ValueError ( '<STR_LIT>' % ( len ( obj ) , len ( cacheNames ) ) ) <EOL> for newVal , name in zip ( obj , cacheNames ) : <EOL> setattr ( self , name , newVal ) <EOL> else : <EOL> for cacheName in cacheNames : <EOL> setattr ( self , cacheName , getattr ( obj , cacheName ) ) <EOL> def load ( self ) : <EOL> '''<STR_LIT>''' <EOL> data = self . read ( ) <EOL> if data is not None : <EOL> data = list ( data ) <EOL> if self . STORAGE_TYPES : <EOL> for name in self . STORAGE_TYPES : <EOL> index = self . _CACHE_NAMES . index ( name ) <EOL> val = data [ index ] <EOL> val = self . itemType ( name ) ( val ) <EOL> data [ index ] = val <EOL> data = tuple ( data ) <EOL> self . update ( data , cacheNames = self . _CACHE_NAMES ) <EOL> return data <EOL> def save ( self , obj = None ) : <EOL> '''<STR_LIT>''' <EOL> if obj is not None : <EOL> self . update ( obj ) <EOL> data = self . contents ( ) <EOL> if self . STORAGE_TYPES : <EOL> newData = [ ] <EOL> for name , val in zip ( self . _CACHE_NAMES , data ) : <EOL> if name in self . STORAGE_TYPES : <EOL> val = self . STORAGE_TYPES [ name ] ( val ) <EOL> newData . append ( val ) <EOL> data = tuple ( newData ) <EOL> self . write ( data ) <EOL> def contents ( self ) : <EOL> return tuple ( getattr ( self , x ) for x in self . cacheNames ( ) ) <EOL> def getConfigFile ( ) : <EOL> return plogging . getConfigFile ( ) <EOL> def parsePymelConfig ( ) : <EOL> import ConfigParser <EOL> types = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> defaults = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> config = ConfigParser . ConfigParser ( defaults ) <EOL> config . read ( getConfigFile ( ) ) <EOL> d = { } <EOL> for option in config . options ( '<STR_LIT>' ) : <EOL> getter = getattr ( config , '<STR_LIT>' + types . get ( option , '<STR_LIT>' ) ) <EOL> d [ option ] = getter ( '<STR_LIT>' , option ) <EOL> return d <EOL> pymel_options = parsePymelConfig ( ) </s>
