<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import json <EOL> import imp <EOL> import inspect <EOL> import importlib <EOL> from collections import OrderedDict <EOL> import traceback <EOL> import FabricEngine . Core <EOL> import kraken <EOL> from kraken . core . profiler import Profiler <EOL> from kraken . plugins import getFabricClient <EOL> krakenSystemModuleDir = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) ) <EOL> krakenDir = os . path . abspath ( os . path . join ( krakenSystemModuleDir , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> os . environ [ '<STR_LIT>' ] = krakenDir <EOL> krakenExtsDir = os . path . join ( krakenDir , '<STR_LIT>' ) <EOL> if krakenExtsDir not in os . environ [ '<STR_LIT>' ] : <EOL> os . environ [ '<STR_LIT>' ] = krakenExtsDir + os . pathsep + os . environ [ '<STR_LIT>' ] <EOL> canvasPresetsDir = os . path . join ( krakenDir , '<STR_LIT>' ) <EOL> if '<STR_LIT>' in os . environ : <EOL> if canvasPresetsDir not in os . environ [ '<STR_LIT>' ] : <EOL> os . environ [ '<STR_LIT>' ] = canvasPresetsDir + os . pathsep + os . environ [ '<STR_LIT>' ] <EOL> else : <EOL> os . environ [ '<STR_LIT>' ] = canvasPresetsDir <EOL> class KrakenSystem ( object ) : <EOL> """<STR_LIT>""" <EOL> __instance = None <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( KrakenSystem , self ) . __init__ ( ) <EOL> self . client = None <EOL> self . typeDescs = None <EOL> self . registeredTypes = None <EOL> self . loadedExtensions = [ ] <EOL> self . registeredConfigs = OrderedDict ( ) <EOL> self . registeredComponents = OrderedDict ( ) <EOL> def loadCoreClient ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . client == None : <EOL> Profiler . getInstance ( ) . push ( "<STR_LIT>" ) <EOL> client = getFabricClient ( ) <EOL> if client is None : <EOL> client = FabricEngine . Core . createClient ( { '<STR_LIT>' : True } ) <EOL> self . client = client <EOL> self . loadExtension ( '<STR_LIT>' ) <EOL> Profiler . getInstance ( ) . pop ( ) <EOL> def getCoreClient ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . client is None : <EOL> self . loadCoreClient ( ) <EOL> return self . client <EOL> def loadExtension ( self , extension ) : <EOL> """<STR_LIT>""" <EOL> if extension not in self . loadedExtensions : <EOL> Profiler . getInstance ( ) . push ( "<STR_LIT>" + extension ) <EOL> self . client . loadExtension ( extension ) <EOL> self . registeredTypes = self . client . RT . types <EOL> self . typeDescs = self . client . RT . getRegisteredTypes ( ) <EOL> self . loadedExtensions . append ( extension ) <EOL> Profiler . getInstance ( ) . pop ( ) <EOL> def constructRTVal ( self , dataType , defaultValue = None ) : <EOL> """<STR_LIT>""" <EOL> self . loadCoreClient ( ) <EOL> klType = getattr ( self . registeredTypes , dataType ) <EOL> if defaultValue is not None : <EOL> if hasattr ( defaultValue , '<STR_LIT>' ) : <EOL> return defaultValue . _rtval <EOL> typeDesc = self . typeDescs [ dataType ] <EOL> if '<STR_LIT>' in typeDesc : <EOL> try : <EOL> value = klType . create ( ) <EOL> except : <EOL> try : <EOL> return klType ( ) <EOL> except Exception as e : <EOL> raise Exception ( "<STR_LIT>" + dataType ) <EOL> for i in xrange ( <NUM_LIT:0> , len ( typeDesc [ '<STR_LIT>' ] ) ) : <EOL> memberName = typeDesc [ '<STR_LIT>' ] [ i ] [ '<STR_LIT:name>' ] <EOL> memberType = typeDesc [ '<STR_LIT>' ] [ i ] [ '<STR_LIT:type>' ] <EOL> if memberName in defaultValue : <EOL> setattr ( value , memberName , self . constructRTVal ( memberType , getattr ( defaultValue , memberName ) ) ) <EOL> return value <EOL> else : <EOL> return klType ( defaultValue ) <EOL> else : <EOL> try : <EOL> return klType . create ( ) <EOL> except : <EOL> try : <EOL> return klType ( ) <EOL> except Exception as e : <EOL> raise Exception ( "<STR_LIT>" + dataType ) <EOL> def rtVal ( self , dataType , defaultValue = None ) : <EOL> """<STR_LIT>""" <EOL> return self . constructRTVal ( dataType , defaultValue ) <EOL> def isRTVal ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return str ( type ( value ) ) == "<STR_LIT>" <EOL> def getRTValTypeName ( self , rtval ) : <EOL> """<STR_LIT>""" <EOL> if ks . isRTVal ( rtval ) : <EOL> return json . loads ( rtval . type ( "<STR_LIT>" ) . jsonDesc ( "<STR_LIT>" ) . getSimpleType ( ) ) [ '<STR_LIT:name>' ] <EOL> else : <EOL> return "<STR_LIT:None>" <EOL> def registerConfig ( self , configClass ) : <EOL> """<STR_LIT>""" <EOL> configModulePath = configClass . __module__ + "<STR_LIT:.>" + configClass . __name__ <EOL> if configModulePath in self . registeredConfigs : <EOL> pass <EOL> self . registeredConfigs [ configModulePath ] = configClass <EOL> def getConfigClass ( self , className ) : <EOL> """<STR_LIT>""" <EOL> if className not in self . registeredConfigs : <EOL> raise Exception ( "<STR_LIT>" + className ) <EOL> return self . registeredConfigs [ className ] <EOL> def getConfigClassNames ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . registeredConfigs . keys ( ) <EOL> def registerComponent ( self , componentClass ) : <EOL> """<STR_LIT>""" <EOL> componentClassPath = componentClass . __module__ + "<STR_LIT:.>" + componentClass . __name__ <EOL> if componentClassPath in self . registeredComponents : <EOL> pass <EOL> self . registeredComponents [ componentClassPath ] = componentClass <EOL> def getComponentClass ( self , className ) : <EOL> """<STR_LIT>""" <EOL> if className not in self . registeredComponents : <EOL> raise Exception ( "<STR_LIT>" + className ) <EOL> return self . registeredComponents [ className ] <EOL> def getComponentClassNames ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . registeredComponents . keys ( ) <EOL> def loadComponentModules ( self ) : <EOL> """<STR_LIT>""" <EOL> for componentClassPath in self . registeredComponents : <EOL> componentModulePath = self . registeredComponents [ componentClassPath ] . __module__ <EOL> if componentModulePath in sys . modules : <EOL> del ( sys . modules [ componentModulePath ] ) <EOL> self . registeredComponents = { } <EOL> print "<STR_LIT>" <EOL> def __importDirRecursive ( path , parentModulePath = '<STR_LIT>' ) : <EOL> isSuccessful = True <EOL> contents = os . listdir ( path ) <EOL> moduleFilefound = False <EOL> for item in contents : <EOL> if os . path . isfile ( os . path . join ( path , item ) ) : <EOL> if item == "<STR_LIT>" : <EOL> if parentModulePath == '<STR_LIT>' : <EOL> modulePath = os . path . basename ( path ) <EOL> moduleParentFolder = os . path . split ( path ) [ <NUM_LIT:0> ] <EOL> if moduleParentFolder not in sys . path : <EOL> sys . path . append ( moduleParentFolder ) <EOL> else : <EOL> modulePath = parentModulePath + '<STR_LIT:.>' + os . path . basename ( path ) <EOL> moduleFilefound = True <EOL> if moduleFilefound : <EOL> print ( "<STR_LIT:U+0020>" + path + "<STR_LIT::>" ) <EOL> for i , item in enumerate ( contents ) : <EOL> if os . path . isfile ( os . path . join ( path , item ) ) : <EOL> if item . endswith ( "<STR_LIT>" ) and item != "<STR_LIT>" : <EOL> module = modulePath + "<STR_LIT:.>" + item [ : - <NUM_LIT:3> ] <EOL> try : <EOL> print "<STR_LIT:U+0020>" + module <EOL> importlib . import_module ( module ) <EOL> except ImportError , e : <EOL> isSuccessful = False <EOL> print "<STR_LIT>" <EOL> print e <EOL> for arg in e . args : <EOL> print arg <EOL> except Exception , e : <EOL> isSuccessful = False <EOL> print "<STR_LIT>" <EOL> for arg in e . args : <EOL> print arg <EOL> print "<STR_LIT:\n>" <EOL> for item in contents : <EOL> if os . path . isdir ( os . path . join ( path , item ) ) : <EOL> if moduleFilefound : <EOL> if not __importDirRecursive ( os . path . join ( path , item ) , modulePath ) : <EOL> isSuccessful = False <EOL> else : <EOL> if not __importDirRecursive ( os . path . join ( path , item ) ) : <EOL> isSuccessful = False <EOL> return isSuccessful <EOL> default_component_path = os . path . normpath ( os . path . join ( os . environ . get ( '<STR_LIT>' ) , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> isSuccessful = __importDirRecursive ( default_component_path ) <EOL> pathsVar = os . getenv ( '<STR_LIT>' ) <EOL> if pathsVar is not None : <EOL> pathsList = pathsVar . split ( os . pathsep ) <EOL> for path in pathsList : <EOL> if path == '<STR_LIT>' : <EOL> continue <EOL> if not os . path . exists ( path ) : <EOL> print "<STR_LIT>" + path <EOL> continue <EOL> if not __importDirRecursive ( path ) : <EOL> isSuccessful = False <EOL> return isSuccessful <EOL> @ classmethod <EOL> def getInstance ( cls ) : <EOL> """<STR_LIT>""" <EOL> if cls . __instance is None : <EOL> cls . __instance = KrakenSystem ( ) <EOL> return cls . __instance <EOL> ks = KrakenSystem . getInstance ( ) </s>
