#OrchestratorGlobalDictAnywhere #NeedToTestChangeInMainAndCheckInProcessor

dev-linux
Ivan Maslov 6 years ago
parent 3245a7f17d
commit d7c3a56334

@ -8,6 +8,11 @@ import signal
import pdb import pdb
import orchestratorServer import orchestratorServer
lGlobalDict={}
#"JSONConfigurationDict":<JSON>
#"ActivityLog":[{""}]
#"ActivityLogSchedule"
#Чтение конфигурации #Чтение конфигурации
lDaemonConfigurationFile = codecs.open("orchestratorConfiguration.json", "r","utf_8_sig") lDaemonConfigurationFile = codecs.open("orchestratorConfiguration.json", "r","utf_8_sig")
lDaemonConfigurationJSONString = lDaemonConfigurationFile.read() lDaemonConfigurationJSONString = lDaemonConfigurationFile.read()
@ -16,15 +21,20 @@ lDaemonConfigurationFile.close()
#Преобразование в JSON #Преобразование в JSON
lDaemonConfigurationObject=json.loads(lDaemonConfigurationJSONString) lDaemonConfigurationObject=json.loads(lDaemonConfigurationJSONString)
#Инициализация настроечных параметров #Инициализация настроечных параметров
lDaemonLoopSeconds=lDaemonConfigurationObject["loopSeconds"] lDaemonLoopSeconds=lDaemonConfigurationObject["loopSeconds"]
lDaemonActivityLogDict={} #Словарь отработанных активностей, ключ - кортеж (<activityType>, <datetime>, <processPath || processName>, <processArgs>) lDaemonActivityLogDict={} #Словарь отработанных активностей, ключ - кортеж (<activityType>, <datetime>, <processPath || processName>, <processArgs>)
lDaemonStartDateTime=datetime.datetime.now() lDaemonStartDateTime=datetime.datetime.now()
#Инициализация globalDict
lGlobalDict["JSONConfigurationDict"]=lDaemonConfigurationObject
lGlobalDict["ActivityLogSchedule"]=lDaemonActivityLogDict
orchestratorServer.mActivityLogDict = lDaemonActivityLogDict orchestratorServer.mActivityLogDict = lDaemonActivityLogDict
#Инициализация сервера #Инициализация сервера
lThreadServer = orchestratorServer.RobotDaemonServer("ServerThread",lDaemonConfigurationObject) lThreadServer = orchestratorServer.RobotDaemonServer("ServerThread",lGlobalDict)
lThreadServer.start() lThreadServer.start()
#Вечный цикл #Вечный цикл
while True: while True:

@ -1,6 +1,8 @@
import datetime import datetime
import http.client import http.client
import json import json
#Глобальная переменная - все глобальные значения программы
global mGlobalDict
#{ #{
# actionList: # actionList:
# [ # [
@ -13,7 +15,9 @@ import json
# ] # ]
# #
#} #}
def ProcessingRun(inConfigurationDict): def ProcessingRun(inConfigurationDict):
print(mGlobalDict)
lDateTimeString=datetime.datetime.strftime(datetime.datetime.now(),"%Y.%m.%d %H:%M:%S::%f") lDateTimeString=datetime.datetime.strftime(datetime.datetime.now(),"%Y.%m.%d %H:%M:%S::%f")
lResult={"dateTime":lDateTimeString, "state":"connected", "actionListResult":[]} lResult={"dateTime":lDateTimeString, "state":"connected", "actionListResult":[]}

@ -9,6 +9,7 @@ import PIL
from PIL import ImageGrab from PIL import ImageGrab
from threading import Thread from threading import Thread
import orchestratorProcessor import orchestratorProcessor
def SaveScreenshot(inFilePath): def SaveScreenshot(inFilePath):
# grab fullscreen # grab fullscreen
lScreenshot = ImageGrab.grab() lScreenshot = ImageGrab.grab()
@ -18,13 +19,17 @@ def SaveScreenshot(inFilePath):
#Глобальные переменные #Глобальные переменные
global mActivityLogDict global mActivityLogDict
mJSONConfigurationDict={} #inGlobalDict
# "JSONConfigurationDict":<JSON>
class RobotDaemonServer(Thread): class RobotDaemonServer(Thread):
def __init__(self,name,inJSONConfigurationDict): def __init__(self,name,inGlobalDict):
Thread.__init__(self) Thread.__init__(self)
self.name = name self.name = name
global mJSONConfigurationDict global mJSONConfigurationDict
mJSONConfigurationDict=inJSONConfigurationDict mJSONConfigurationDict=inGlobalDict["JSONConfigurationDict"]
#Перенос переменной в orchestratorProcessor
orchestratorProcessor.mGlobalDict=inGlobalDict
def run(self,inServerAddress="127.0.0.1",inPort=8081): def run(self,inServerAddress="127.0.0.1",inPort=8081):
print('starting server...') print('starting server...')
# Server settings # Server settings
@ -111,7 +116,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
self.send_header('Content-type','application/json') self.send_header('Content-type','application/json')
self.end_headers() self.end_headers()
# Send message back to client # Send message back to client
message = json.dumps(robotDaemonProcessor.ProcessingRun(lInputObject)) message = json.dumps(orchestratorProcessor.ProcessingRun(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

Loading…
Cancel
Save