You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.7 KiB
38 lines
1.7 KiB
6 years ago
|
import datetime
|
||
|
import http.client
|
||
|
import json
|
||
|
#{
|
||
|
# actionList:
|
||
|
# [
|
||
|
# {
|
||
|
# type: <RemoteMachineProcessingRun>,
|
||
|
# host: <localhost>,
|
||
|
# port: <port>,
|
||
|
# bodyObject: <object dict, int, str, list>
|
||
|
# }
|
||
|
# ]
|
||
|
#
|
||
|
#}
|
||
|
def ProcessingRun(inConfigurationDict):
|
||
|
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'))}
|
||
|
#Вернуть результат
|
||
|
return lResult
|