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.
62 lines
2.7 KiB
62 lines
2.7 KiB
import datetime
|
|
import http.client
|
|
import json
|
|
import pdb
|
|
import os
|
|
import subprocess
|
|
#Глобальная переменная - все глобальные значения программы
|
|
global mGlobalDict
|
|
#{
|
|
# actionList:
|
|
# [
|
|
# {
|
|
# type: <RemoteMachineProcessingRun>,
|
|
# host: <localhost>,
|
|
# port: <port>,
|
|
# bodyObject: <object dict, int, str, list>
|
|
# },
|
|
# {
|
|
# type: <ActivityLogScheduleListGet>
|
|
# },
|
|
# {
|
|
# type: <ActivityCMDRun>,
|
|
# code: <str>
|
|
# }
|
|
# ]
|
|
#
|
|
#}
|
|
|
|
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'))}
|
|
#Обработка команды ActivityLogScheduleListGet
|
|
if lItem["type"]=="ActivityLogScheduleListGet":
|
|
#pdb.set_trace()
|
|
lResult["actionListResult"][-1] = {**lResult["actionListResult"][-1], **{"result":mGlobalDict["ActivityLogScheduleList"]}}
|
|
#Обработка команды ActivityCMDRun
|
|
if lItem["type"]=="ActivityCMDRun":
|
|
lCMDCode="cmd /c "+lItem["code"]
|
|
subprocess.Popen(lCMDCode)
|
|
lResultCMDRun=1#os.system(lCMDCode)
|
|
lResult["actionListResult"][-1] = {**lResult["actionListResult"][-1], **{"result":str(lResultCMDRun)}}
|
|
#Вернуть результат
|
|
return lResult
|