<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import re <EOL> import sys <EOL> import traceback <EOL> import pydoc <EOL> import inspect <EOL> from maya import cmds <EOL> _shellLogHandler = None <EOL> _guiLogHandler = None <EOL> appLoggerName = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def loadStringResourcesForModule ( moduleName ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> module = sys . modules [ moduleName ] <EOL> except : <EOL> raise RuntimeError ( '<STR_LIT>' % moduleName ) <EOL> modulePath , moduleFileName = os . path . split ( module . __file__ ) <EOL> moduleName , extension = os . path . splitext ( moduleFileName ) <EOL> resourceFileName = moduleName + '<STR_LIT>' <EOL> try : <EOL> baseVersionPath = os . path . join ( modulePath , resourceFileName ) <EOL> execfile ( baseVersionPath , { } ) <EOL> except : <EOL> raise RuntimeError ( '<STR_LIT>' % moduleName ) <EOL> if cmds . about ( uiLanguageIsLocalized = True ) : <EOL> scriptPath = cmds . about ( localizedResourceLocation = True ) <EOL> if scriptPath != '<STR_LIT>' : <EOL> localizedPath = os . path . join ( scriptPath , '<STR_LIT>' , resourceFileName ) <EOL> try : <EOL> execfile ( localizedPath , { } ) <EOL> except IOError : <EOL> pass <EOL> except Exception , err : <EOL> raise RuntimeError ( '<STR_LIT>' % ( moduleName , err ) ) <EOL> def getPossibleCompletions ( input ) : <EOL> """<STR_LIT>""" <EOL> import sys <EOL> import rlcompleter <EOL> completer = rlcompleter . Completer ( ) <EOL> listOfMatches = [ ] <EOL> try : <EOL> for index in xrange ( sys . maxint ) : <EOL> term = completer . complete ( input , index ) <EOL> if term is None : <EOL> break <EOL> if len ( listOfMatches ) and listOfMatches [ - <NUM_LIT:1> ] == term : <EOL> continue <EOL> listOfMatches . append ( term ) <EOL> except : <EOL> pass <EOL> return listOfMatches <EOL> def helpNonVerbose ( thing , title = '<STR_LIT>' , forceload = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> result = "<STR_LIT>" <EOL> try : <EOL> thingStr = thing . encode ( cmds . about ( codeset = True ) ) <EOL> except : <EOL> thingStr = str ( thing ) <EOL> try : <EOL> try : <EOL> object , name = pydoc . resolve ( thingStr , forceload ) <EOL> except : <EOL> thingObj = eval ( thingStr , sys . modules [ '<STR_LIT:__main__>' ] . __dict__ ) <EOL> object , name = pydoc . resolve ( thingObj , forceload ) <EOL> desc = pydoc . describe ( object ) <EOL> module = inspect . getmodule ( object ) <EOL> if name and '<STR_LIT:.>' in name : <EOL> desc += '<STR_LIT>' + name [ : name . rfind ( '<STR_LIT:.>' ) ] <EOL> elif module and module is not object : <EOL> desc += '<STR_LIT>' + module . __name__ <EOL> doc = None <EOL> text = pydoc . TextDoc ( ) <EOL> if not ( inspect . ismodule ( object ) or <EOL> inspect . isclass ( object ) or <EOL> inspect . isroutine ( object ) or <EOL> inspect . isgetsetdescriptor ( object ) or <EOL> inspect . ismemberdescriptor ( object ) or <EOL> isinstance ( object , property ) ) : <EOL> object = type ( object ) <EOL> desc += '<STR_LIT>' <EOL> elif module is cmds and inspect . isroutine ( object ) : <EOL> try : <EOL> if len ( object . __doc__ ) == <NUM_LIT:0> : <EOL> doc = cmds . help ( object . __name__ ) <EOL> except : <EOL> pass <EOL> if not doc : <EOL> doc = text . document ( object , name ) <EOL> result = pydoc . plain ( title % desc + '<STR_LIT>' + doc ) <EOL> result = "<STR_LIT:\n>" . join ( [ line for line in result . splitlines ( ) if line . strip ( ) ] ) <EOL> except : <EOL> pass <EOL> return result <EOL> class MayaGuiLogHandler ( logging . Handler ) : <EOL> """<STR_LIT>""" <EOL> def emit ( self , record ) : <EOL> from maya import OpenMaya <EOL> msg = self . format ( record ) <EOL> if record . levelno > logging . WARNING : <EOL> OpenMaya . MGlobal . displayError ( msg ) <EOL> elif record . levelno > logging . INFO : <EOL> OpenMaya . MGlobal . displayWarning ( msg ) <EOL> else : <EOL> OpenMaya . MGlobal . displayInfo ( msg ) <EOL> def guiLogHandler ( ) : <EOL> """<STR_LIT>""" <EOL> global _guiLogHandler <EOL> if _guiLogHandler is not None : <EOL> return _guiLogHandler <EOL> if _shellLogHandler is None : <EOL> shellLogHandler ( ) <EOL> _shellLogHandler . setLevel ( logging . CRITICAL ) <EOL> _guiLogHandler = MayaGuiLogHandler ( ) <EOL> format = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _guiLogHandler . setFormatter ( logging . Formatter ( format ) ) <EOL> log = logging . getLogger ( appLoggerName ) <EOL> log . addHandler ( _guiLogHandler ) <EOL> return _guiLogHandler <EOL> def shellLogHandler ( ) : <EOL> """<STR_LIT>""" <EOL> global _shellLogHandler <EOL> if _shellLogHandler is not None : <EOL> return _shellLogHandler <EOL> shellStream = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> shellStream = getattr ( sys , shellStream , sys . __stdout__ ) <EOL> _shellLogHandler = logging . StreamHandler ( shellStream ) <EOL> format = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _shellLogHandler . setFormatter ( logging . Formatter ( format ) ) <EOL> log = logging . getLogger ( appLoggerName ) <EOL> log . addHandler ( _shellLogHandler ) <EOL> log . setLevel ( logging . INFO ) <EOL> return _shellLogHandler <EOL> def _guiExceptHook ( exceptionType , exceptionObject , traceBack , detail = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return formatGuiException ( exceptionType , exceptionObject , traceBack , detail ) <EOL> except : <EOL> etype , value , tb = sys . exc_info ( ) <EOL> tbStack = traceback . extract_tb ( tb ) <EOL> del tb <EOL> tbLines = [ ] <EOL> tbLines . append ( "<STR_LIT>" ) <EOL> tbLines += traceback . format_list ( tbStack [ <NUM_LIT:1> : ] ) + traceback . format_exception_only ( etype , value ) <EOL> tbLines . append ( "<STR_LIT>" ) <EOL> tbLines += traceback . format_exception ( exceptionType , exceptionObject , traceBack ) <EOL> tbLines = _prefixTraceStack ( tbLines ) <EOL> return '<STR_LIT>' . join ( tbLines ) <EOL> def formatGuiException ( exceptionType , exceptionObject , traceBack , detail = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> exceptionMsg = unicode ( exceptionObject ) . strip ( ) <EOL> excLines = _decodeStack ( traceback . format_exception_only ( exceptionType , exceptionObject ) ) <EOL> if len ( excLines ) > <NUM_LIT:0> : <EOL> excLines [ - <NUM_LIT:1> ] = re . sub ( r'<STR_LIT>' , exceptionMsg , excLines [ - <NUM_LIT:1> ] ) <EOL> exceptionMsg = excLines [ - <NUM_LIT:1> ] . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] . strip ( ) <EOL> if detail == <NUM_LIT:0> : <EOL> result = exceptionType . __name__ + '<STR_LIT>' + exceptionMsg <EOL> else : <EOL> tbStack = traceback . extract_tb ( traceBack ) <EOL> tbStack = _fixConsoleLineNumbers ( tbStack ) <EOL> if detail == <NUM_LIT:1> : <EOL> if tbStack : <EOL> file , line , func , text = tbStack [ - <NUM_LIT:1> ] <EOL> result = u'<STR_LIT>' % ( exceptionType . __name__ , file , line , exceptionMsg ) <EOL> else : <EOL> result = exceptionMsg <EOL> else : <EOL> tbLines = _decodeStack ( traceback . format_list ( tbStack ) ) <EOL> if len ( tbStack ) > <NUM_LIT:0> : <EOL> tbLines . insert ( <NUM_LIT:0> , u'<STR_LIT>' ) <EOL> result = '<STR_LIT>' . join ( _prefixTraceStack ( [ exceptionMsg + '<STR_LIT:\n>' ] + tbLines + excLines ) ) <EOL> return result <EOL> _formatGuiException = formatGuiException <EOL> def _prefixTraceStack ( tbStack , prefix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> result = '<STR_LIT>' . join ( tbStack ) . rstrip ( ) . split ( '<STR_LIT:\n>' ) <EOL> size = len ( result ) - <NUM_LIT:1> <EOL> for i , line in enumerate ( result ) : <EOL> if i < size : <EOL> line += '<STR_LIT:\n>' <EOL> if i != <NUM_LIT:0> : <EOL> line = prefix + line <EOL> result [ i ] = line <EOL> return result <EOL> def _fixConsoleLineNumbers ( tbStack ) : <EOL> result = [ ] <EOL> for file , line , func , text in tbStack : <EOL> if file == '<STR_LIT>' : <EOL> line -= <NUM_LIT:1> <EOL> result . append ( ( file , line , func , text ) ) <EOL> return result <EOL> def _decodeStack ( tbStack ) : <EOL> encoding = cmds . about ( codeset = True ) <EOL> return [ s . decode ( encoding ) for s in tbStack ] <EOL> def _guiResultHook ( obj ) : <EOL> """<STR_LIT>""" <EOL> return formatGuiResult ( obj ) <EOL> def formatGuiResult ( obj ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , str ) or isinstance ( obj , unicode ) : <EOL> return obj <EOL> else : <EOL> return repr ( obj ) <EOL> _formatGuiResult = formatGuiResult </s>
