|
|
|
import datetime
|
|
|
|
import http.client
|
|
|
|
import json
|
|
|
|
import pdb
|
|
|
|
#Глобальная переменная - все глобальные значения программы
|
|
|
|
global mGlobalDict
|
|
|
|
#{
|
|
|
|
# actionList:
|
|
|
|
# [
|
|
|
|
# {
|
|
|
|
# type: <RemoteMachineProcessingRun>,
|
|
|
|
# host: <localhost>,
|
|
|
|
# port: <port>,
|
|
|
|
# bodyObject: <object dict, int, str, list>
|
|
|
|
# },
|
|
|
|
# {
|
|
|
|
# type: <ActivityLogScheduleGet>
|
|
|
|
# }
|
|
|
|
# ]
|
|
|
|
#
|
|
|
|
#}
|
|
|
|
|
|
|
|
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":[]}
|
|
|
|
|
|
|
|
for lItem in inConfigurationDict["actionList"]:
|
|
|
|
#Добавить входные значения
|
|
|
|
lResult["actionListResult"].append({"inArgs":lItem})
|
|
|
|
#Обработка запроса на отправку команды на удаленную машину
|
|
|
|
if lItem["type"]=="RemoteMachineProcessingRun":
|
|
|
|
lHTTPConnection = http.client.HTTPConnection(lItem["host"], lItem["port"], timeout=5)
|
|
|
|
try:
|
|
|
|
lHTTPConnection.request("POST","/ProcessingRun",json.dumps(lItem["bodyObject"]))
|
|
|
|
except Exception as e:
|
|
|
|
#Объединение словарей
|
|
|
|
lResult["actionListResult"][-1] = {**lResult["actionListResult"][-1], **{"state":"disconnected","errorMessage":str(e)}}
|
|
|
|
#lResult["actionListResult"][-1].join({"state":"disconnected","errorMessage":str(e)})
|
|
|
|
else:
|
|
|
|
lHTTPResponse=lHTTPConnection.getresponse()
|
|
|
|
lHTTPResponseByteArray=lHTTPResponse.read()
|
|
|
|
lResult["actionListResult"][-1] = {**lResult["actionListResult"][-1], **json.loads(lHTTPResponseByteArray.decode('utf8'))}
|
|
|
|
#Обработка команды ActivityLogScheduleGet
|
|
|
|
if lItem["type"]=="ActivityLogScheduleListGet":
|
|
|
|
pdb.set_trace()
|
|
|
|
lResult["actionListResult"][-1] = {**lResult["actionListResult"][-1], **{"result":mGlobalDict["ActivityLogScheduleList"]}}
|
|
|
|
#Вернуть результат
|
|
|
|
return lResult
|