|
|
|
|
import pdb
|
|
|
|
|
import pywinauto
|
|
|
|
|
import json
|
|
|
|
|
import subprocess
|
|
|
|
|
import zlib
|
|
|
|
|
import os
|
|
|
|
|
import ProcessCommunicator
|
|
|
|
|
import importlib
|
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
|
####################################
|
|
|
|
|
#Info: Main module of the Robot app (OpenRPA - Robot)
|
|
|
|
|
####################################
|
|
|
|
|
|
|
|
|
|
#Usage:
|
|
|
|
|
#Here you can run some activity or list of activities
|
|
|
|
|
|
|
|
|
|
#After import this module you can use the folowing functions:
|
|
|
|
|
#ActivityRun(inActivitySpecificationDict): outActivityResultDict - function - run activity (function or procedure)
|
|
|
|
|
#ActivityRunJSON(inActivitySpecificationDictJSON): outActivityResultDictJSON
|
|
|
|
|
#ActivityListRun(inActivitySpecificationDictList): outActivityResultDictList - function - run list of activities (function or procedure)
|
|
|
|
|
#ActivityListRunJSON(inActivitySpecificationDictListJSON): outActivityResultDictListJSON
|
|
|
|
|
|
|
|
|
|
#Naming:
|
|
|
|
|
#Activity - some action/list of actions
|
|
|
|
|
#Module - Any *.py file, which consist of area specific functions
|
|
|
|
|
#Argument
|
|
|
|
|
|
|
|
|
|
#inActivitySpecificationDict:
|
|
|
|
|
#{
|
|
|
|
|
# ModuleName: <"GUI"|..., str>,
|
|
|
|
|
# ActivityName: <Function or procedure name in module, str>,
|
|
|
|
|
# ArgumentList: [<Argument 1, any type>, ...] - optional,
|
|
|
|
|
# ArgumentDict: {<Argument 1 name, str>:<Argument 1 value, any type>, ...} - optional
|
|
|
|
|
#}
|
|
|
|
|
|
|
|
|
|
#outActivityResultDict:
|
|
|
|
|
#{
|
|
|
|
|
# ActivitySpecificationDict: {
|
|
|
|
|
# ModuleName: <"GUI"|..., str>,
|
|
|
|
|
# ActivityName: <Function or procedure name in module, str>,
|
|
|
|
|
# ArgumentList: [<Argument 1, any type>, ...] - optional,
|
|
|
|
|
# ArgumentDict: {<Argument 1 name, str>: <Argument 1 value, any type>, ...} - optional
|
|
|
|
|
# },
|
|
|
|
|
# ErrorFlag: <Boolean flag - Activity result has error (true) or not (false), boolean>,
|
|
|
|
|
# ErrorMessage: <Error message, str> - required if ErrorFlag is true,
|
|
|
|
|
# ErrorTraceback: <Error traceback log, str> - required if ErrorFlag is true,
|
|
|
|
|
# Result: <Result, returned from the Activity, int, str, boolean, list, dict> - required if ErrorFlag is false
|
|
|
|
|
#}
|
|
|
|
|
|
|
|
|
|
####################
|
|
|
|
|
#Section: Module initialization
|
|
|
|
|
####################
|
|
|
|
|
#Start childprocess - GUI Module 32 bit
|
|
|
|
|
mProcessGUI_x32 = subprocess.Popen(['..\\Resources\\WPy32-3720\\python-3.7.2\\python.exe','GUI.py'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
|
|
|
#Start childprocess - GUI Module 64 bit - uncomment after WPy64 installation
|
|
|
|
|
#mProcessGUI_x64 = subprocess.Popen(['..\\Resources\\WPy64-3720\\python-3.7.2\\python.exe','GUI.py'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####################
|
|
|
|
|
#Section: Activity
|
|
|
|
|
####################
|
|
|
|
|
def ActivityRun(inActivitySpecificationDict):
|
|
|
|
|
#Выполнить отправку в модуль GUI, если ModuleName == "GUI"
|
|
|
|
|
if inActivitySpecificationDict["ModuleName"] == "GUI":
|
|
|
|
|
#TODO: Доделать определение разрядности (32 и 64)
|
|
|
|
|
#Отправить запрос в дочерний процесс, который отвечает за работу с Windows окнами
|
|
|
|
|
ProcessCommunicator.ProcessChildSendObject(mProcessGUI_x32,inActivitySpecificationDict)
|
|
|
|
|
#Получить ответ от дочернего процесса
|
|
|
|
|
lResponseObject=ProcessCommunicator.ProcessChildReadWaitObject(mProcessGUI_x32)
|
|
|
|
|
#Вернуть результат
|
|
|
|
|
#Остальные модули подключать и выполнять здесь
|
|
|
|
|
else:
|
|
|
|
|
#Подготовить результирующую структуру
|
|
|
|
|
lResponseObject={"ActivitySpecificationDict":inActivitySpecificationDict,"ErrorFlag":False}
|
|
|
|
|
lArgumentList=[]
|
|
|
|
|
if "ArgumentList" in inActivitySpecificationDict:
|
|
|
|
|
lArgumentList=inActivitySpecificationDict["ArgumentList"]
|
|
|
|
|
lArgumentDict={}
|
|
|
|
|
if "ArgumentDict" in inActivitySpecificationDict:
|
|
|
|
|
lArgumentDict=inActivitySpecificationDict["ArgumentDict"]
|
|
|
|
|
try:
|
|
|
|
|
#Подключить модуль для вызова
|
|
|
|
|
lModule=importlib.import_module(inActivitySpecificationDict["ModuleName"])
|
|
|
|
|
#Найти функцию
|
|
|
|
|
lFunction=getattr(lModule,inActivitySpecificationDict["FunctionName"])
|
|
|
|
|
#Выполнить вызов и записать результат
|
|
|
|
|
lResponseObject["Result"]=lFunction(*lArgumentList,**lArgumentDict)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
#Установить флаг ошибки и передать тело ошибки
|
|
|
|
|
lResponseObject["ErrorFlag"]=True
|
|
|
|
|
lResponseObject["ErrorMessage"]=str(e)
|
|
|
|
|
lResponseObject["ErrorTraceback"]=traceback.format_exc()
|
|
|
|
|
return lResponseObject
|