@ -27,6 +27,7 @@ from . import SettingsTemplate # Settings template
import uuid # Generate uuid
import datetime # datetime
import math
import glob # search the files
#Единый глобальный словарь (З а основу взять из Settings.py)
gSettingsDict = None
@ -491,6 +492,60 @@ def OrchestratorRerunAsAdmin():
else :
print ( f " !SKIPPED! Already run as administrator! " )
def OrchestratorPySearchInit ( inGlobPatternStr , inDefStr = None , inDefArgNameGSettingsStr = None ) :
"""
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 ) .
. . code - block : : python
# USAGE VAR 1 (without the def auto call)
# Autoinit control panels starts with CP_
Orchestrator . OrchestratorPySearchInit ( inGlobPatternStr = " ControlPanel \\ CP_*.py " )
# USAGE VAR 2 (with the def auto call) - for the backward compatibility CP for the Orchestrator ver. < 1.2.7
# Autoinit control panels starts with CP_
Orchestrator . OrchestratorPySearchInit ( inGlobPatternStr = " ControlPanel \\ CP_*.py " , inDefStr = " SettingsUpdate " , inDefArgNameGSettingsStr = " inGSettings " )
# INFO: The code above will replace the code below
## !!! For Relative import !!! CP Version Check
try :
sys . path . insert ( 0 , os . path . abspath ( os . path . join ( r " " ) ) )
from ControlPanel import CP_VersionCheck
CP_VersionCheck . SettingsUpdate ( inGSettings = gSettings )
except Exception as e :
gSettings [ " Logger " ] . exception ( f " Exception when init CP. See below. " )
: 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 )
: return : { " ModuleNameStr " : { " PyPathStr " : " " , " Module " : . . . } , . . . }
"""
lResultDict = { }
lPyPathStrList = glob . glob ( inGlobPatternStr ) # get the file list
lL = OrchestratorLoggerGet ( ) # get the logger
for lPyPathItemStr in lPyPathStrList :
try :
lModuleNameStr = os . path . basename ( lPyPathItemStr ) [ 0 : - 3 ]
lTechSpecification = importlib . util . spec_from_file_location ( lModuleNameStr , lPyPathItemStr )
lTechModuleFromSpec = importlib . util . module_from_spec ( lTechSpecification )
sys . modules [ lModuleNameStr ] = lTechModuleFromSpec # Add initialized module in sys - python will not init this module enought
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. " )
lResultDict [ lModuleNameStr ] = lItemDict
# Backward compatibility to call def with gsettings when init
if inDefStr is not None and inDefStr is not " " :
lDef = getattr ( lTechModuleFromSpec , inDefStr )
lArgDict = { }
if inDefArgNameGSettingsStr is not None and inDefArgNameGSettingsStr is not " " :
lArgDict = { inDefArgNameGSettingsStr : GSettingsGet ( ) }
lDef ( * * lArgDict )
except Exception as e :
if lL : lL . exception ( f " Exception when init the .py file { os . path . abspath ( lPyPathItemStr ) } " )
return lResultDict
def OrchestratorSessionSave ( inGSettings = None ) :
"""
Orchestrator session save in file
@ -890,6 +945,12 @@ def WebUserUACHierarchyGet(inRequest):
from . import SettingsTemplate
GSettings = SettingsTemplate . Create ( inModeStr = " BASIC " )
# Modules alias for pyOpenRPA.Orchestrator and pyOpenRPA.Orchestrator.__Orchestrator__
lCurrentModule = sys . modules [ __name__ ]
if __name__ == " pyOpenRPA.Orchestrator " and " pyOpenRPA.Orchestrator.__Orchestrator__ " not in sys . modules :
sys . modules [ " pyOpenRPA.Orchestrator.__Orchestrator__ " ] = lCurrentModule
if __name__ == " pyOpenRPA.Orchestrator.__Orchestrator__ " and " pyOpenRPA.Orchestrator " not in sys . modules :
sys . modules [ " pyOpenRPA.Orchestrator " ] = lCurrentModule
def GSettingsGet ( inGSettings = None ) :
"""