@ -541,6 +541,24 @@ def OrchestratorIsAdmin():
except :
return False
def OrchestratorIsInited ( ) - > bool :
""" Check if Orchestrator initial actions were processed
: return : True - orc is already inited ; False - else
: rtype : bool
"""
return Core . IsOrchestratorInitialized ( inGSettings = GSettingsGet ( ) )
def OrchestratorInitWait ( ) - > None :
""" Wait thread while orc will process initial action.
ATTENTION : DO NOT CALL THIS DEF IN THREAD WHERE ORCHESTRATOR MUST BE INITIALIZED - INFINITE LOOP
"""
lIntervalSecFloat = 0.5
while not OrchestratorIsInited ( ) :
time . sleep ( lIntervalSecFloat )
def OrchestratorRerunAsAdmin ( ) :
"""
Check if not admin - then rerun orchestrator as administrator
@ -553,10 +571,10 @@ def OrchestratorRerunAsAdmin():
else :
print ( f " !SKIPPED! Already run as administrator! " )
def OrchestratorPySearchInit ( inGlobPatternStr , inDefStr = None , inDefArgNameGSettingsStr = None ):
def OrchestratorPySearchInit ( inGlobPatternStr , inDefStr = None , inDefArgNameGSettingsStr = None , inAsyncInitBool = False ):
"""
Search the py files by the glob and do the safe init ( in try except ) . Also add inited module in sys . modules as imported ( module name = file name without extension ) .
You can init CP in async way !
. . code - block : : python
# USAGE VAR 1 (without the def auto call)
@ -580,14 +598,14 @@ def OrchestratorPySearchInit(inGlobPatternStr, inDefStr = None, inDefArgNameGSet
: param inGlobPatternStr : example " .. \\ * \\ * \\ *X64*.cmd "
: param inDefStr : OPTIONAL The string name of the def . For backward compatibility if you need to auto call some def from initialized module
: param inDefArgNameGSettingsStr : OPTIONAL The name of the GSettings argument in def ( if exists )
: param inAsyncInitBool : OPTIONAL True - init py modules in many threads - parallel execution . False ( default ) - sequence execution
: return : { " ModuleNameStr " : { " PyPathStr " : " " , " Module " : . . . } , . . . }
"""
lResultDict = { }
lPyPathStrList = glob . glob ( inGlobPatternStr ) # get the file list
lL = OrchestratorLoggerGet ( ) # get the logger
for lPyPathItemStr in lPyPathStrList :
# # # # # # # #
def __execute__ ( inResultDict , inPyPathItemStr , inDefStr = None , inDefArgNameGSettingsStr = None ) :
try :
lPyPathItemStr = inPyPathItemStr
lModuleNameStr = os . path . basename ( lPyPathItemStr ) [ 0 : - 3 ]
lTechSpecification = importlib . util . spec_from_file_location ( lModuleNameStr , lPyPathItemStr )
lTechModuleFromSpec = importlib . util . module_from_spec ( lTechSpecification )
@ -595,7 +613,7 @@ def OrchestratorPySearchInit(inGlobPatternStr, inDefStr = None, inDefArgNameGSet
lTechSpecificationModuleLoader = lTechSpecification . loader . exec_module ( lTechModuleFromSpec )
lItemDict = { " ModuleNameStr " : lModuleNameStr , " PyPathStr " : lPyPathItemStr , " Module " : lTechModuleFromSpec }
if lL : lL . info ( f " Py module { lModuleNameStr } has been successfully initialized. " )
l ResultDict[ lModuleNameStr ] = lItemDict
in ResultDict[ lModuleNameStr ] = lItemDict
# Backward compatibility to call def with gsettings when init
if inDefStr is not None and inDefStr is not " " :
lDef = getattr ( lTechModuleFromSpec , inDefStr )
@ -605,6 +623,22 @@ def OrchestratorPySearchInit(inGlobPatternStr, inDefStr = None, inDefArgNameGSet
lDef ( * * lArgDict )
except Exception as e :
if lL : lL . exception ( f " Exception when init the .py file { os . path . abspath ( lPyPathItemStr ) } " )
# # # # # # # #
lResultDict = { }
lPyPathStrList = glob . glob ( inGlobPatternStr ) # get the file list
lL = OrchestratorLoggerGet ( ) # get the logger
for lPyPathItemStr in lPyPathStrList :
if inAsyncInitBool == True :
# ASYNC EXECUTION
lThreadInit = threading . Thread ( target = __execute__ , kwargs = {
" inResultDict " : lResultDict , " inPyPathItemStr " : lPyPathItemStr ,
" inDefStr " : inDefStr , " inDefArgNameGSettingsStr " : inDefArgNameGSettingsStr } , daemon = True )
lThreadInit . start ( )
else :
# SYNC EXECUTION
__execute__ ( inResultDict = lResultDict , inPyPathItemStr = lPyPathItemStr , inDefStr = inDefStr , inDefArgNameGSettingsStr = inDefArgNameGSettingsStr )
return lResultDict
def OrchestratorSessionSave ( inGSettings = None ) :
@ -2015,6 +2049,7 @@ def RDPTemplateCreate(inLoginStr, inPasswordStr, inHostStr="127.0.0.1", inPortIn
"""
if inSharedDriveList is None : inSharedDriveList = [ " c " ]
if inPortInt is None : inPortInt = 3389
lRDPTemplateDict = { # Init the configuration item
" Host " : inHostStr , # Host address, example "77.77.22.22"
" Port " : str ( inPortInt ) , # RDP Port, example "3389"
@ -2573,7 +2608,6 @@ def GSettingsAutocleaner(inGSettings=None):
while True :
time . sleep ( inGSettings [ " Autocleaner " ] [ " IntervalSecFloat " ] ) # Wait for the next iteration
lL = inGSettings [ " Logger " ]
if lL : lL . info ( f " Autocleaner is running " ) # Info
lNowDatetime = datetime . datetime . now ( ) # Get now time
# Clean old items in Client > Session > TechnicalSessionGUIDCache
lTechnicalSessionGUIDCacheNew = { }