# Test new processor in progress - need new setings template

dev-linux
Ivan Maslov 4 years ago
parent 67e3d3fd22
commit 239a2c6c83

@ -0,0 +1,3 @@
cd %~dp0
..\..\Resources\WPy64-3720\python-3.7.2.amd64\python.exe -m jupyterlab
pause >nul

@ -0,0 +1,159 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Init the configuration GSettings"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"lSettingsDirStr = r\"..\\..\\..\\OpenRPA_Creds\\Orchestrator\\Settings\" # Set Gsettings dir path str\n",
"import sys\n",
"sys.path.append(lSettingsDirStr) # Add path with settings in search dir for .py modules\n",
"sys.path.insert(0,r\"..\") # Add path to sources - to import from experimental pyOpenRPA\n",
"import SettingsOrchestratorExample\n",
"gSettings = SettingsOrchestratorExample.Settings()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run the orchestrator"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-10-11 00:32:27,869 - Orchestrator - INFO - Link the gSettings in submodules\n",
"2020-10-11 00:32:27,878 - Orchestrator - WARNING - Backward compatibility (v1.1.13 to v1.1.14): Add default 'Autocleaner' structure\n",
"2020-10-11 00:32:27,880 - Orchestrator - WARNING - Backward compatibility (v1.1.13 to v1.1.14): Add default 'Client' structure\n",
"2020-10-11 00:32:27,882 - Orchestrator - WARNING - Backward compatibility (v1.1.13 to v1.1.14): Add default 'Server' > 'RequestTimeoutSecFloat' property\n",
"2020-10-11 00:32:27,883 - Orchestrator - WARNING - Backward compatibility (v1.1.13 to v1.1.14): Add default 'OrchestratorStart' > 'DefSettingsUpdatePathList' property list\n",
"2020-10-11 00:32:27,886 - Orchestrator - WARNING - Backward compatibility (v1.1.20 to v1.2.0): Remove old structure 'Processor'\n",
"2020-10-11 00:32:27,888 - Orchestrator - WARNING - Backward compatibility (v1.1.20 to v1.2.0): Create new structure 'ProcessorDict'\n",
"2020-10-11 00:32:27,893 - Orchestrator - INFO - Server init. Listen URL: , Listen port: 80\n",
"2020-10-11 00:32:27,893 - Orchestrator - INFO - Web server has been started\n",
"2020-10-11 00:32:27,932 - Orchestrator - INFO - Robot Screen active has been started\n",
"2020-10-11 00:32:27,937 - Orchestrator - INFO - Robot RDP active has been started\n",
"2020-10-11 00:32:27,940 - Orchestrator - INFO - Autocleaner thread has been started\n",
"2020-10-11 00:32:27,942 - Orchestrator - INFO - Orchestrator start activity run\n",
"2020-10-11 00:32:27,944 - Orchestrator - INFO - Scheduler loop start\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"----------------------------------------\n",
"Exception happened during processing of request from ('127.0.0.1', 57154)\n",
"Traceback (most recent call last):\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\socketserver.py\", line 650, in process_request_thread\n",
" self.finish_request(request, client_address)\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Server.py\", line 476, in finish_request\n",
" HTTPServer.finish_request(self, request, client_address)\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\socketserver.py\", line 360, in finish_request\n",
" self.RequestHandlerClass(request, client_address, self)\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\socketserver.py\", line 720, in __init__\n",
" self.handle()\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\http\\server.py\", line 426, in handle\n",
" self.handle_one_request()\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\http\\server.py\", line 414, in handle_one_request\n",
" method()\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Server.py\", line 336, in do_GET\n",
" lAuthenticateDict = AuthenticateVerify(self)\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Server.py\", line 73, in AuthenticateVerify\n",
" \"Password\": lPassword\n",
" File \"..\\pyOpenRPA\\Orchestrator\\ProcessorOld.py\", line 94, in Activity\n",
" lItem[\"Result\"] = Processor.ActivityListExecute(inGSettings = gSettingsDict, inActivityList = [inActivity])\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Processor.py\", line 32, in ActivityListExecute\n",
" if callable(lActivityItem[\"Def\"]): # CHeck if def is callable\n",
"KeyError: 'Def'\n",
"----------------------------------------\n",
"----------------------------------------\n",
"Exception happened during processing of request from ('127.0.0.1', 57158)\n",
"Traceback (most recent call last):\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\socketserver.py\", line 650, in process_request_thread\n",
" self.finish_request(request, client_address)\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Server.py\", line 476, in finish_request\n",
" HTTPServer.finish_request(self, request, client_address)\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\socketserver.py\", line 360, in finish_request\n",
" self.RequestHandlerClass(request, client_address, self)\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\socketserver.py\", line 720, in __init__\n",
" self.handle()\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\http\\server.py\", line 426, in handle\n",
" self.handle_one_request()\n",
" File \"C:\\Abs\\Archive\\scopeSrcUL\\OpenRPA\\Resources\\WPy64-3720\\python-3.7.2.amd64\\lib\\http\\server.py\", line 414, in handle_one_request\n",
" method()\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Server.py\", line 336, in do_GET\n",
" lAuthenticateDict = AuthenticateVerify(self)\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Server.py\", line 73, in AuthenticateVerify\n",
" \"Password\": lPassword\n",
" File \"..\\pyOpenRPA\\Orchestrator\\ProcessorOld.py\", line 94, in Activity\n",
" lItem[\"Result\"] = Processor.ActivityListExecute(inGSettings = gSettingsDict, inActivityList = [inActivity])\n",
" File \"..\\pyOpenRPA\\Orchestrator\\Processor.py\", line 32, in ActivityListExecute\n",
" if callable(lActivityItem[\"Def\"]): # CHeck if def is callable\n",
"KeyError: 'Def'\n",
"----------------------------------------\n"
]
}
],
"source": [
"from pyOpenRPA.Orchestrator import Orchestrator # Import orchestrator main\n",
"Orchestrator.Orchestrator(inGSettings=gSettings) # Call the orchestrator"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

@ -0,0 +1,23 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": ""
}
},
"nbformat": 4,
"nbformat_minor": 4
}

@ -1,6 +1,54 @@
# Def to check inGSettings and update structure to the backward compatibility # Def to check inGSettings and update structure to the backward compatibility
# !!! ATTENTION: Backward compatibility has been started from v1.1.13 !!! # !!! ATTENTION: Backward compatibility has been started from v1.1.13 !!!
# So you can use config of the orchestrator 1.1.13 in new Orchestrator versions and all will be ok :) (hope it's true) # So you can use config of the orchestrator 1.1.13 in new Orchestrator versions and all will be ok :) (hope it's true)
import win32security
# v1.2.0 Def for old procesor to new processor
# Return new activity for the new processor
def v1_2_0_ProcessorOld2NewActivityDict(inActivityOld):
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Technical defs for support old operations in old processor
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# {
# "Type":"WindowsLogon",
# "Domain":"",
# "User":"",
# "Password":""
# # Return "Result": True - user is logged on, False - user is not logged on
# }
def WindowLogon(inUserStr, inPasswordStr, inDomainStr=""):
#################################
# Windows logon
#################################
try:
hUser = win32security.LogonUser(
inUserStr,
inDomainStr,
inPasswordStr,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT
)
except win32security.error:
return False
else:
return True
###################################
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
if inActivityOld["Type"] == "WindowsLogon":
lResult = {
"Def": WindowLogon, # def link or def alias (look gSettings["Processor"]["AliasDefDict"])
"ArgList":[], # Args list
"ArgDict":{"inUserStr": inActivityOld["User"],"inPasswordStr":inActivityOld["Password"],"inDomainStr":inActivityOld["Domain"]}, # Args dictionary
"ArgGSettings": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList)
}
else:
raise Exception(f"BackwardCompatibility up to 1.2.0, old processor: No type {inActivityOld['Type']} has been found in old processor.")
return lResult # return the result
def Update(inGSettings): def Update(inGSettings):
lL = inGSettings["Logger"] # Alias for logger lL = inGSettings["Logger"] # Alias for logger
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

@ -41,165 +41,172 @@ def GSettingsAutocleaner(inGSettings):
if lL: lL.debug(f"Client > Session > TechnicalSessionGUIDCache > lItemKeyStr: Lifetime is expired. Remove from gSettings") # Info if lL: lL.debug(f"Client > Session > TechnicalSessionGUIDCache > lItemKeyStr: Lifetime is expired. Remove from gSettings") # Info
inGSettings["Client"]["Session"]["TechnicalSessionGUIDCache"] = lTechnicalSessionGUIDCacheNew # Set updated Cache inGSettings["Client"]["Session"]["TechnicalSessionGUIDCache"] = lTechnicalSessionGUIDCacheNew # Set updated Cache
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#Call Settings function from argv[1] file
################################################ # Main def for orchestrator
lSubmoduleFunctionName = "Settings" def Orchestrator(inGSettings):
lFileFullPath = sys.argv[1] #mGlobalDict = Settings.Settings(sys.argv[1])
lModuleName = (lFileFullPath.split("\\")[-1])[0:-3] gSettingsDict = inGSettings # Alias for old name in alg
lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) #Logger alias
lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification) lL = gSettingsDict["Logger"]
lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) if lL: lL.info("Link the gSettings in submodules") #Logging
gSettingsDict = None Processor.gSettingsDict = gSettingsDict
if lSubmoduleFunctionName in dir(lTechModuleFromSpec): Timer.gSettingsDict = gSettingsDict
# Run SettingUpdate function in submodule Timer.Processor.gSettingsDict = gSettingsDict
gSettingsDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() Server.gSettingsDict = gSettingsDict
################################################# Server.ProcessorOld.gSettingsDict = gSettingsDict # Backward compatibility
#mGlobalDict = Settings.Settings(sys.argv[1])
#Logger alias # Check _SessionLast_RDPList.json in working directory. if exist - load into gsettings
lL = gSettingsDict["Logger"] # GSettings
#"RobotRDPActive": {
if lL: lL.info("Link the gSettings in submodules") #Logging # "RDPList": {
Processor.gSettingsDict = gSettingsDict if os.path.exists("_SessionLast_RDPList.json"):
Timer.gSettingsDict = gSettingsDict lFile = open("_SessionLast_RDPList.json", "r", encoding="utf-8")
Timer.Processor.gSettingsDict = gSettingsDict lSessionLastRDPList = json.loads(lFile.read())
Server.gSettingsDict = gSettingsDict lFile.close() # Close the file
Server.Processor.gSettingsDict = gSettingsDict os.remove("_SessionLast_RDPList.json") # remove the temp file
gSettingsDict["RobotRDPActive"]["RDPList"]=lSessionLastRDPList # Set the last session dict
# Check _SessionLast_RDPList.json in working directory. if exist - load into gsettings if lL: lL.warning(f"RDP Session List was restored from previous Orchestrator session")
# GSettings
#"RobotRDPActive": { #Инициализация настроечных параметров
# "RDPList": { lDaemonLoopSeconds=gSettingsDict["Scheduler"]["ActivityTimeCheckLoopSeconds"]
if os.path.exists("_SessionLast_RDPList.json"): lDaemonActivityLogDict={} #Словарь отработанных активностей, ключ - кортеж (<activityType>, <datetime>, <processPath || processName>, <processArgs>)
lFile = open("_SessionLast_RDPList.json", "r", encoding="utf-8") lDaemonLastDateTime=datetime.datetime.now()
lSessionLastRDPList = json.loads(lFile.read()) gSettingsDict["Server"]["WorkingDirectoryPathStr"] = os.getcwd() # Set working directory in g settings
lFile.close() # Close the file
os.remove("_SessionLast_RDPList.json") # remove the temp file # Init SettingsUpdate defs from file list (after RDP restore)
gSettingsDict["RobotRDPActive"]["RDPList"]=lSessionLastRDPList # Set the last session dict lSettingsUpdateFilePathList = gSettingsDict.get("OrchestratorStart", {}).get("DefSettingsUpdatePathList",[])
if lL: lL.warning(f"RDP Session List was restored from previous Orchestrator session") lSubmoduleFunctionName = "SettingsUpdate"
lSettingsPath = "\\".join(os.path.join(os.getcwd(), __file__).split("\\")[:-1])
#Инициализация настроечных параметров for lModuleFilePathItem in lSettingsUpdateFilePathList: # Import defs with try catch
lDaemonLoopSeconds=gSettingsDict["Scheduler"]["ActivityTimeCheckLoopSeconds"] try: # Try to init - go next if error and log in logger
lDaemonActivityLogDict={} #Словарь отработанных активностей, ключ - кортеж (<activityType>, <datetime>, <processPath || processName>, <processArgs>) lModuleName = lModuleFilePathItem[0:-3]
lDaemonLastDateTime=datetime.datetime.now() lFileFullPath = os.path.join(lSettingsPath, lModuleFilePathItem)
gSettingsDict["Server"]["WorkingDirectoryPathStr"] = os.getcwd() # Set working directory in g settings lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath)
lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification)
# Init SettingsUpdate defs from file list (after RDP restore) lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec)
lSettingsUpdateFilePathList = gSettingsDict.get("OrchestratorStart", {}).get("DefSettingsUpdatePathList",[]) if lSubmoduleFunctionName in dir(lTechModuleFromSpec):
lSubmoduleFunctionName = "SettingsUpdate" # Run SettingUpdate function in submodule
lSettingsPath = "\\".join(os.path.join(os.getcwd(), __file__).split("\\")[:-1]) getattr(lTechModuleFromSpec, lSubmoduleFunctionName)(gSettingsDict)
for lModuleFilePathItem in lSettingsUpdateFilePathList: # Import defs with try catch except Exception as e:
try: # Try to init - go next if error and log in logger if lL: lL.exception(f"Error when init .py file in orchestrator '{lModuleFilePathItem}'. Exception is below:")
lModuleName = lModuleFilePathItem[0:-3]
lFileFullPath = os.path.join(lSettingsPath, lModuleFilePathItem) # Turn on backward compatibility
lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) BackwardCompatibility.Update(inGSettings= gSettingsDict)
lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification)
lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) #Инициализация сервера
if lSubmoduleFunctionName in dir(lTechModuleFromSpec): lThreadServer = Server.RobotDaemonServer("ServerThread", gSettingsDict)
# Run SettingUpdate function in submodule lThreadServer.start()
getattr(lTechModuleFromSpec, lSubmoduleFunctionName)(gSettingsDict) if lL: lL.info("Web server has been started") #Logging
except Exception as e:
if lL: lL.exception(f"Error when init .py file in orchestrator '{lModuleFilePathItem}'. Exception is below:") # Init the RobotScreenActive in another thread
lRobotScreenActiveThread = threading.Thread(target= Monitor.CheckScreen)
# Turn on backward compatibility lRobotScreenActiveThread.daemon = True # Run the thread in daemon mode.
BackwardCompatibility.Update(inGSettings= gSettingsDict) lRobotScreenActiveThread.start() # Start the thread execution.
if lL: lL.info("Robot Screen active has been started") #Logging
#Инициализация сервера
lThreadServer = Server.RobotDaemonServer("ServerThread", gSettingsDict) # Init the RobotRDPActive in another thread
lThreadServer.start() lRobotRDPActiveThread = threading.Thread(target= RobotRDPActive.RobotRDPActive, kwargs={"inGSettings":gSettingsDict})
if lL: lL.info("Web server has been started") #Logging lRobotRDPActiveThread.daemon = True # Run the thread in daemon mode.
lRobotRDPActiveThread.start() # Start the thread execution.
# Init the RobotScreenActive in another thread if lL: lL.info("Robot RDP active has been started") #Logging
lRobotScreenActiveThread = threading.Thread(target= Monitor.CheckScreen)
lRobotScreenActiveThread.daemon = True # Run the thread in daemon mode. # Init autocleaner in another thread
lRobotScreenActiveThread.start() # Start the thread execution. lAutocleanerThread = threading.Thread(target= GSettingsAutocleaner, kwargs={"inGSettings":gSettingsDict})
if lL: lL.info("Robot Screen active has been started") #Logging lAutocleanerThread.daemon = True # Run the thread in daemon mode.
lAutocleanerThread.start() # Start the thread execution.
# Init the RobotRDPActive in another thread if lL: lL.info("Autocleaner thread has been started") #Logging
lRobotRDPActiveThread = threading.Thread(target= RobotRDPActive.RobotRDPActive, kwargs={"inGSettings":gSettingsDict})
lRobotRDPActiveThread.daemon = True # Run the thread in daemon mode. # Orchestrator start activity
lRobotRDPActiveThread.start() # Start the thread execution. if lL: lL.info("Orchestrator start activity run") #Logging
if lL: lL.info("Robot RDP active has been started") #Logging for lActivityItem in gSettingsDict["OrchestratorStart"]["ActivityList"]:
Processor.ActivityListOrDict(lActivityItem)
# Init autocleaner in another thread
lAutocleanerThread = threading.Thread(target= GSettingsAutocleaner, kwargs={"inGSettings":gSettingsDict}) if lL: lL.info("Scheduler loop start") #Logging
lAutocleanerThread.daemon = True # Run the thread in daemon mode. gDaemonActivityLogDictRefreshSecInt = 10 # The second period for clear lDaemonActivityLogDict from old items
lAutocleanerThread.start() # Start the thread execution. gDaemonActivityLogDictLastTime = time.time() # The second perioad for clean lDaemonActivityLogDict from old items
if lL: lL.info("Autocleaner thread has been started") #Logging while True:
lCurrentDateTime = datetime.datetime.now()
# Orchestrator start activity #Циклический обход правил
if lL: lL.info("Orchestrator start activity run") #Logging lFlagSearchActivityType=True
for lActivityItem in gSettingsDict["OrchestratorStart"]["ActivityList"]: # Periodically clear the lDaemonActivityLogDict
Processor.ActivityListOrDict(lActivityItem) if time.time()-gDaemonActivityLogDictLastTime>=gDaemonActivityLogDictRefreshSecInt:
gDaemonActivityLogDictLastTime = time.time() # Update the time
if lL: lL.info("Scheduler loop start") #Logging for lIndex, lItem in enumerate(lDaemonActivityLogDict):
gDaemonActivityLogDictRefreshSecInt = 10 # The second period for clear lDaemonActivityLogDict from old items if lItem["ActivityEndDateTime"] and lCurrentDateTime<=lItem["ActivityEndDateTime"]:
gDaemonActivityLogDictLastTime = time.time() # The second perioad for clean lDaemonActivityLogDict from old items pass
while True: # Activity is actual - do not delete now
lCurrentDateTime = datetime.datetime.now() else:
#Циклический обход правил # remove the activity - not actual
lFlagSearchActivityType=True lDaemonActivityLogDict.pop(lIndex,None)
# Periodically clear the lDaemonActivityLogDict lIterationLastDateTime = lDaemonLastDateTime # Get current datetime before iterator (need for iterate all activities in loop)
if time.time()-gDaemonActivityLogDictLastTime>=gDaemonActivityLogDictRefreshSecInt: # Iterate throught the activity list
gDaemonActivityLogDictLastTime = time.time() # Update the time for lIndex, lItem in enumerate(gSettingsDict["Scheduler"]["ActivityTimeList"]):
for lIndex, lItem in enumerate(lDaemonActivityLogDict): # Prepare GUID of the activity
if lItem["ActivityEndDateTime"] and lCurrentDateTime<=lItem["ActivityEndDateTime"]: lGUID = None
pass if "GUID" in lItem and lItem["GUID"]:
# Activity is actual - do not delete now lGUID = lItem["GUID"]
else: else:
# remove the activity - not actual lGUID = str(uuid.uuid4())
lDaemonActivityLogDict.pop(lIndex,None) lItem["GUID"]=lGUID
lIterationLastDateTime = lDaemonLastDateTime # Get current datetime before iterator (need for iterate all activities in loop)
# Iterate throught the activity list #Проверка дней недели, в рамках которых можно запускать активность
for lIndex, lItem in enumerate(gSettingsDict["Scheduler"]["ActivityTimeList"]): lItemWeekdayList=lItem.get("WeekdayList", [0, 1, 2, 3, 4, 5, 6])
# Prepare GUID of the activity if lCurrentDateTime.weekday() in lItemWeekdayList:
lGUID = None if lFlagSearchActivityType:
if "GUID" in lItem and lItem["GUID"]: #######################################################################
lGUID = lItem["GUID"] #Branch 1 - if has TimeHH:MM
else: #######################################################################
lGUID = str(uuid.uuid4()) if "TimeHH:MM" in lItem:
lItem["GUID"]=lGUID #Вид активности - запуск процесса
#Сформировать временной штамп, относительно которого надо будет проверять время
#Проверка дней недели, в рамках которых можно запускать активность #часовой пояс пока не учитываем
lItemWeekdayList=lItem.get("WeekdayList", [0, 1, 2, 3, 4, 5, 6]) lActivityDateTime=datetime.datetime.strptime(lItem["TimeHH:MM"],"%H:%M")
if lCurrentDateTime.weekday() in lItemWeekdayList: lActivityDateTime=lActivityDateTime.replace(year=lCurrentDateTime.year,month=lCurrentDateTime.month,day=lCurrentDateTime.day)
if lFlagSearchActivityType: #Убедиться в том, что время наступило
####################################################################### if (
#Branch 1 - if has TimeHH:MM lActivityDateTime>=lDaemonLastDateTime and
####################################################################### lCurrentDateTime>=lActivityDateTime):
if "TimeHH:MM" in lItem: # Log info about activity
#Вид активности - запуск процесса if lL: lL.info(f"Scheduler:: Activity is started. Scheduler item: {lItem}") #Logging
#Сформировать временной штамп, относительно которого надо будет проверять время # Do the activity
#часовой пояс пока не учитываем Processor.ActivityListOrDict(lItem["Activity"])
lActivityDateTime=datetime.datetime.strptime(lItem["TimeHH:MM"],"%H:%M") lIterationLastDateTime = datetime.datetime.now() # Set the new datetime for the new processor activity
lActivityDateTime=lActivityDateTime.replace(year=lCurrentDateTime.year,month=lCurrentDateTime.month,day=lCurrentDateTime.day) #######################################################################
#Убедиться в том, что время наступило #Branch 2 - if TimeHH:MMStart, TimeHH:MMStop, ActivityIntervalSeconds
if ( #######################################################################
lActivityDateTime>=lDaemonLastDateTime and if "TimeHH:MMStart" in lItem and "TimeHH:MMStop" in lItem and "ActivityIntervalSeconds" in lItem:
lCurrentDateTime>=lActivityDateTime): #Сформировать временной штамп, относительно которого надо будет проверять время
# Log info about activity #часовой пояс пока не учитываем
if lL: lL.info(f"Scheduler:: Activity is started. Scheduler item: {lItem}") #Logging lActivityDateTime=datetime.datetime.strptime(lItem["TimeHH:MMStart"],"%H:%M")
# Do the activity lActivityDateTime=lActivityDateTime.replace(year=lCurrentDateTime.year,month=lCurrentDateTime.month,day=lCurrentDateTime.day)
Processor.ActivityListOrDict(lItem["Activity"]) lActivityTimeEndDateTime=datetime.datetime.strptime(lItem["TimeHH:MMStop"],"%H:%M")
lIterationLastDateTime = datetime.datetime.now() # Set the new datetime for the new processor activity lActivityTimeEndDateTime=lActivityTimeEndDateTime.replace(year=lCurrentDateTime.year,month=lCurrentDateTime.month,day=lCurrentDateTime.day)
####################################################################### #Убедиться в том, что время наступило
#Branch 2 - if TimeHH:MMStart, TimeHH:MMStop, ActivityIntervalSeconds if (
####################################################################### lCurrentDateTime<lActivityTimeEndDateTime and
if "TimeHH:MMStart" in lItem and "TimeHH:MMStop" in lItem and "ActivityIntervalSeconds" in lItem: lCurrentDateTime>=lActivityDateTime and
#Сформировать временной штамп, относительно которого надо будет проверять время (lGUID,lActivityDateTime) not in lDaemonActivityLogDict):
#часовой пояс пока не учитываем #Запись в массив отработанных активностей
lActivityDateTime=datetime.datetime.strptime(lItem["TimeHH:MMStart"],"%H:%M") lDaemonActivityLogDict[(lGUID,lActivityDateTime)]={"ActivityStartDateTime":lCurrentDateTime, "ActivityEndDateTime":lActivityTimeEndDateTime}
lActivityDateTime=lActivityDateTime.replace(year=lCurrentDateTime.year,month=lCurrentDateTime.month,day=lCurrentDateTime.day) #Запуск циклической процедуры
lActivityTimeEndDateTime=datetime.datetime.strptime(lItem["TimeHH:MMStop"],"%H:%M") Timer.activityLoopStart(lItem["ActivityIntervalSeconds"], lActivityTimeEndDateTime, lItem["Activity"])
lActivityTimeEndDateTime=lActivityTimeEndDateTime.replace(year=lCurrentDateTime.year,month=lCurrentDateTime.month,day=lCurrentDateTime.day) lDaemonLastDateTime = lIterationLastDateTime # Set the new datetime for the new processor activity
#Убедиться в том, что время наступило #Уснуть до следующего прогона
if ( time.sleep(lDaemonLoopSeconds)
lCurrentDateTime<lActivityTimeEndDateTime and
lCurrentDateTime>=lActivityDateTime and # Backward compatibility below to 1.2.0
(lGUID,lActivityDateTime) not in lDaemonActivityLogDict): if __name__ == "__main__":
#Запись в массив отработанных активностей #Call Settings function from argv[1] file
lDaemonActivityLogDict[(lGUID,lActivityDateTime)]={"ActivityStartDateTime":lCurrentDateTime, "ActivityEndDateTime":lActivityTimeEndDateTime} ################################################
#Запуск циклической процедуры lSubmoduleFunctionName = "Settings"
Timer.activityLoopStart(lItem["ActivityIntervalSeconds"], lActivityTimeEndDateTime, lItem["Activity"]) lFileFullPath = sys.argv[1]
lDaemonLastDateTime = lIterationLastDateTime # Set the new datetime for the new processor activity lModuleName = (lFileFullPath.split("\\")[-1])[0:-3]
#Уснуть до следующего прогона lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath)
time.sleep(lDaemonLoopSeconds) lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification)
lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec)
gSettingsDict = None
if lSubmoduleFunctionName in dir(lTechModuleFromSpec):
# Run SettingUpdate function in submodule
gSettingsDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)()
#################################################
Orchestrator(inGSettings=gSettingsDict) # Call the orchestrator

@ -8,8 +8,8 @@ def ProcessorRunSync(inGSettings):
# { # {
# "Def":"DefAliasTest", # def link or def alias (look gSettings["Processor"]["AliasDefDict"]) # "Def":"DefAliasTest", # def link or def alias (look gSettings["Processor"]["AliasDefDict"])
# "ArgList":[1,2,3], # Args list # "ArgList":[1,2,3], # Args list
# "ArgDict":{"ttt":1,"222":2,"dsd":3} # Args dictionary # "ArgDict":{"ttt":1,"222":2,"dsd":3}, # Args dictionary
# "ArgGSettings": # Name of GSettings attribute: str (ArgDict) or index (for ArgList) # "ArgGSettings": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList)
# }, # },
], ],
"AliasDefDict": {}, # Storage for def with Str alias. To use it see pyOpenRPA.Orchestrator.ControlPanel "AliasDefDict": {}, # Storage for def with Str alias. To use it see pyOpenRPA.Orchestrator.ControlPanel

@ -1,12 +1,14 @@
import datetime import datetime
import http.client import http.client
import json import json
import pdb
import os import os
import sys import sys
import subprocess import subprocess
import importlib import importlib
import psutil import psutil
from . import BackwardCompatibility # Use backward compatibility to goes to the new processor
from . import Processor # Use new processor
import copy
#Input arg #Input arg
# [ # [
# { # {
@ -84,8 +86,14 @@ import psutil
# "Result" # "Result"
gSettingsDict = None gSettingsDict = None
def Activity(inActivity): def Activity(inActivity):
#Глобальная переменная - глобальный словарь унаследованный от Settings.py lItem = copy.deepcopy(inActivity)
global gSettingsDict global gSettingsDict
# Update 2020.10 - go to the new processor
lActivityNew = BackwardCompatibility.v1_2_0_ProcessorOld2NewActivityDict(inActivityOld=inActivity)
# Append new activity in list
lItem["Result"] = Processor.ActivityListExecute(inGSettings = gSettingsDict, inActivityList = [inActivity])
"""
#Глобальная переменная - глобальный словарь унаследованный от Settings.py
lL = gSettingsDict["Logger"] # Alias for logger lL = gSettingsDict["Logger"] # Alias for logger
#Alias (compatibility) #Alias (compatibility)
lItem = inActivity lItem = inActivity
@ -271,6 +279,7 @@ def Activity(inActivity):
else: else:
lItem["Result"] = True lItem["Result"] = True
################################### ###################################
"""
#Вернуть результат #Вернуть результат
return lItem return lItem

@ -11,7 +11,8 @@ from socketserver import ThreadingMixIn
import threading import threading
import json import json
from threading import Thread from threading import Thread
from . import Processor from . import Processor # Add new processor
from . import ProcessorOld # Support old processor - deprecated defs only for backward compatibility
import urllib.parse # decode URL in string import urllib.parse # decode URL in string
import importlib import importlib
import pdb import pdb
@ -64,7 +65,7 @@ def AuthenticateVerify(inRequest):
lDomain = lUser.split("\\")[0] lDomain = lUser.split("\\")[0]
lUser = lUser.split("\\")[1] lUser = lUser.split("\\")[1]
#Try to logon - use processor #Try to logon - use processor
lLogonResult = Processor.Activity( lLogonResult = ProcessorOld.Activity(
{ {
"Type": "WindowsLogon", "Type": "WindowsLogon",
"Domain": lDomain, "Domain": lDomain,
@ -451,7 +452,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
if not lIsSuperToken: if not lIsSuperToken:
if lL: lL.info(f"Server:: User activity from web. Domain: {self.OpenRPA['Domain']}, Username: {self.OpenRPA['User']}, Activity: {lInputObject}") if lL: lL.info(f"Server:: User activity from web. Domain: {self.OpenRPA['Domain']}, Username: {self.OpenRPA['User']}, Activity: {lInputObject}")
# Send message back to client # Send message back to client
message = json.dumps(Processor.ActivityListOrDict(lInputObject)) message = json.dumps(ProcessorOld.ActivityListOrDict(lInputObject))
# Write content as utf-8 data # Write content as utf-8 data
self.wfile.write(bytes(message, "utf8")) self.wfile.write(bytes(message, "utf8"))
return return

@ -1,6 +1,7 @@
[1.2.0] [1.2.0]
- Consolidated processor from old orchestrator and from RDPActive processor (one threaded). Look in GSettings - Consolidated processor from old orchestrator and from RDPActive processor (one threaded). Look in GSettings
- - Support old orchestrator structure Processor. - - Support old orchestrator structure Processor.
- - - Create BackwardCompatibility def to update structure from old to new processor
- - Support orchestrator start - - Support orchestrator start
- - Support scheduler - - Support scheduler
- - Support old items - - Support old items

Loading…
Cancel
Save