From d7c3a56334cf2acabd96123a9abd23632cdfaf86 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Wed, 24 Apr 2019 09:58:26 +0300 Subject: [PATCH] #OrchestratorGlobalDictAnywhere #NeedToTestChangeInMainAndCheckInProcessor --- Orchestrator/orchestratorMain.py | 12 +++++++++++- Orchestrator/orchestratorProcessor.py | 4 ++++ Orchestrator/orchestratorServer.py | 13 +++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Orchestrator/orchestratorMain.py b/Orchestrator/orchestratorMain.py index fe89ba7b..70a443f4 100644 --- a/Orchestrator/orchestratorMain.py +++ b/Orchestrator/orchestratorMain.py @@ -8,6 +8,11 @@ import signal import pdb import orchestratorServer +lGlobalDict={} +#"JSONConfigurationDict": +#"ActivityLog":[{""}] +#"ActivityLogSchedule" + #Чтение конфигурации lDaemonConfigurationFile = codecs.open("orchestratorConfiguration.json", "r","utf_8_sig") lDaemonConfigurationJSONString = lDaemonConfigurationFile.read() @@ -16,15 +21,20 @@ lDaemonConfigurationFile.close() #Преобразование в JSON lDaemonConfigurationObject=json.loads(lDaemonConfigurationJSONString) + #Инициализация настроечных параметров lDaemonLoopSeconds=lDaemonConfigurationObject["loopSeconds"] lDaemonActivityLogDict={} #Словарь отработанных активностей, ключ - кортеж (, , , ) lDaemonStartDateTime=datetime.datetime.now() +#Инициализация globalDict +lGlobalDict["JSONConfigurationDict"]=lDaemonConfigurationObject +lGlobalDict["ActivityLogSchedule"]=lDaemonActivityLogDict + orchestratorServer.mActivityLogDict = lDaemonActivityLogDict #Инициализация сервера -lThreadServer = orchestratorServer.RobotDaemonServer("ServerThread",lDaemonConfigurationObject) +lThreadServer = orchestratorServer.RobotDaemonServer("ServerThread",lGlobalDict) lThreadServer.start() #Вечный цикл while True: diff --git a/Orchestrator/orchestratorProcessor.py b/Orchestrator/orchestratorProcessor.py index 3370ceda..533fc8cf 100644 --- a/Orchestrator/orchestratorProcessor.py +++ b/Orchestrator/orchestratorProcessor.py @@ -1,6 +1,8 @@ import datetime import http.client import json +#Глобальная переменная - все глобальные значения программы +global mGlobalDict #{ # actionList: # [ @@ -13,7 +15,9 @@ import json # ] # #} + def ProcessingRun(inConfigurationDict): + print(mGlobalDict) lDateTimeString=datetime.datetime.strftime(datetime.datetime.now(),"%Y.%m.%d %H:%M:%S::%f") lResult={"dateTime":lDateTimeString, "state":"connected", "actionListResult":[]} diff --git a/Orchestrator/orchestratorServer.py b/Orchestrator/orchestratorServer.py index 64e20cd1..1ff98280 100644 --- a/Orchestrator/orchestratorServer.py +++ b/Orchestrator/orchestratorServer.py @@ -9,6 +9,7 @@ import PIL from PIL import ImageGrab from threading import Thread import orchestratorProcessor + def SaveScreenshot(inFilePath): # grab fullscreen lScreenshot = ImageGrab.grab() @@ -18,13 +19,17 @@ def SaveScreenshot(inFilePath): #Глобальные переменные global mActivityLogDict -mJSONConfigurationDict={} +#inGlobalDict +# "JSONConfigurationDict": class RobotDaemonServer(Thread): - def __init__(self,name,inJSONConfigurationDict): + def __init__(self,name,inGlobalDict): Thread.__init__(self) self.name = name global mJSONConfigurationDict - mJSONConfigurationDict=inJSONConfigurationDict + mJSONConfigurationDict=inGlobalDict["JSONConfigurationDict"] + + #Перенос переменной в orchestratorProcessor + orchestratorProcessor.mGlobalDict=inGlobalDict def run(self,inServerAddress="127.0.0.1",inPort=8081): print('starting server...') # Server settings @@ -111,7 +116,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): self.send_header('Content-type','application/json') self.end_headers() # Send message back to client - message = json.dumps(robotDaemonProcessor.ProcessingRun(lInputObject)) + message = json.dumps(orchestratorProcessor.ProcessingRun(lInputObject)) # Write content as utf-8 data self.wfile.write(bytes(message, "utf8")) return