Orchestrator new engine test 1 is complete. Need test 2 Restart button fix. All urls in settings

Signed-off-by: Ivan Maslov <Ivan.Maslov@UnicodeLabs.ru>
dev-linux
Ivan Maslov 5 years ago
parent ff5c381a2a
commit 0e25557ea2

@ -1,5 +1,6 @@
import psutil import psutil
import datetime import datetime
def RenderRobotR01(inGlobalConfiguration): def RenderRobotR01(inGlobalConfiguration):
#Subheader Variants #Subheader Variants
lSubheaderRunTrueText="Состояние: <span style=\"color:green\">Работает</span>" lSubheaderRunTrueText="Состояние: <span style=\"color:green\">Работает</span>"
@ -65,6 +66,9 @@ def CheckIfProcessRunning(processName):
#Orchestrator settings #Orchestrator settings
def Settings(): def Settings():
import os
import pyOpenRPA.Orchestrator
lOrchestratorFolder = "\\".join(pyOpenRPA.Orchestrator.__file__.split("\\")[:-1])
mDict = { mDict = {
"Server": { "Server": {
"ListenPort_": "Порт, по которому можно подключиться к демону", "ListenPort_": "Порт, по которому можно подключиться к демону",
@ -112,8 +116,17 @@ def Settings():
# "ResponseFilePath": "", #Absolute or relative path # "ResponseFilePath": "", #Absolute or relative path
# "ResponseFolderPath": "", #Absolute or relative path # "ResponseFolderPath": "", #Absolute or relative path
# "ResponseContentType": "", #HTTP Content-type # "ResponseContentType": "", #HTTP Content-type
# "ResponseDefRequestGlobalResponse": None #Function with str result # "ResponseDefRequestGlobal": None #Function with str result
#} #}
#Orchestrator basic dependencies
{"Method":"GET", "URL": "/", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "Web\\Index.xhtml"), "ResponseContentType": "text/html"},
{"Method":"GET", "URL": "/3rdParty/Semantic-UI-CSS-master/semantic.min.css", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.css"), "ResponseContentType": "text/css"},
{"Method":"GET", "URL": "/3rdParty/Semantic-UI-CSS-master/semantic.min.js", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.js"), "ResponseContentType": "application/javascript"},
{"Method":"GET", "URL": "/3rdParty/jQuery/jquery-3.1.1.min.js", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\jQuery\\jquery-3.1.1.min.js"), "ResponseContentType": "application/javascript"},
{"Method":"GET", "URL": "/3rdParty/Google/LatoItalic.css", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Google\\LatoItalic.css"), "ResponseContentType": "font/css"},
{"Method":"GET", "URL": "/3rdParty/Semantic-UI-CSS-master/themes/default/assets/fonts/icons.woff2", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\themes\\default\\assets\\fonts\\icons.woff2"), "ResponseContentType": "font/woff2"},
{"Method":"GET", "URL": "/favicon.ico", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "Web\\favicon.ico"), "ResponseContentType": "image/x-icon"},
{"Method":"GET", "URL": "/3rdParty/Handlebars/handlebars-v4.1.2.js", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Handlebars\\handlebars-v4.1.2.js"), "ResponseContentType": "application/javascript"},
] ]
}, },
"Scheduler": { "Scheduler": {

@ -14,6 +14,7 @@ import logging
import copy import copy
#from .Settings import Settings #from .Settings import Settings
import importlib import importlib
from importlib import util
#Создать файл логирования #Создать файл логирования
# add filemode="w" to overwrite # add filemode="w" to overwrite
if not os.path.exists("Reports"): if not os.path.exists("Reports"):

@ -101,6 +101,8 @@ def AuthenticateVerify(inRequest):
#Set-cookie #Set-cookie
inRequest.OpenRPA["AuthToken"] = lAuthToken inRequest.OpenRPA["AuthToken"] = lAuthToken
inRequest.OpenRPASetCookie = {} inRequest.OpenRPASetCookie = {}
#New engine of server
inRequest.OpenRPAResponseDict["SetCookies"]["AuthToken"] = lAuthToken
#inRequest.OpenRPAResponse["Set-Cookie"]=[]lResult["Set-Cookie"] = lAuthToken #inRequest.OpenRPAResponse["Set-Cookie"]=[]lResult["Set-Cookie"] = lAuthToken
#pdb.set_trace() #pdb.set_trace()
#inRequest.send_header("Set-Cookie:", f"AuthToken={lAuthToken}") #inRequest.send_header("Set-Cookie:", f"AuthToken={lAuthToken}")
@ -204,11 +206,14 @@ def UserAccessCheckBefore(inMethod, inRequest):
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
#Tech def #Tech def
#return {"headers":[],"body":"","statuscode":111} #return {"headers":[],"body":"","statuscode":111}
def URLItemCheckDo(self, inURLItem, inMethod, inResponseDict): def URLItemCheckDo(self, inURLItem, inMethod):
############################### ###############################
#Tech sub def - do item #Tech sub def - do item
################################ ################################
def URLItemDo(inURLItem,inRequest,inGlobalDict,inResponseDict): def URLItemDo(inURLItem,inRequest,inGlobalDict):
inResponseDict = inRequest.OpenRPAResponseDict
#Set status code 200
inResponseDict["StatusCode"] = 200
#Content-type #Content-type
if "ResponseContentType" in inURLItem: if "ResponseContentType" in inURLItem:
inResponseDict["Headers"]["Content-type"] = inURLItem["ResponseContentType"] inResponseDict["Headers"]["Content-type"] = inURLItem["ResponseContentType"]
@ -221,7 +226,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
lFileObject.close() lFileObject.close()
#If function is set #If function is set
if "ResponseDefRequestGlobalResponse" in inURLItem: if "ResponseDefRequestGlobalResponse" in inURLItem:
inURLItem["ResponseDefRequestGlobalResponse"](inRequest,inGlobalDict,inResponseDict) inURLItem["ResponseDefRequestGlobal"](inRequest,inGlobalDict)
# TODO If folder path is set # TODO If folder path is set
if "ResponseFolderPath" in inURLItem: if "ResponseFolderPath" in inURLItem:
# #
@ -233,24 +238,24 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
lURLPath = self.path lURLPath = self.path
lURLPath = lURLPath.upper() lURLPath = lURLPath.upper()
if lURLPath.startswith(inURLItem["URL"].upper()): if lURLPath.startswith(inURLItem["URL"].upper()):
URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) URLItemDo(inURLItem, self, mGlobalDict)
return True return True
# check Match type variant: Contains # check Match type variant: Contains
elif inURLItem["MatchType"].upper() == "CONTAINS": elif inURLItem["MatchType"].upper() == "CONTAINS":
lURLPath = self.path lURLPath = self.path
lURLPath = lURLPath.upper() lURLPath = lURLPath.upper()
if lURLPath.contains(inURLItem["URL"].upper()): if lURLPath.contains(inURLItem["URL"].upper()):
URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) URLItemDo(inURLItem, self, mGlobalDict)
return True return True
# check Match type variant: Equal # check Match type variant: Equal
elif inURLItem["MatchType"].upper() == "EQUAL": elif inURLItem["MatchType"].upper() == "EQUAL":
if inURLItem["URL"].upper() == self.path.upper(): if inURLItem["URL"].upper() == self.path.upper():
URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) URLItemDo(inURLItem, self, mGlobalDict)
return True return True
# check Match type variant: EqualCase # check Match type variant: EqualCase
elif inURLItem["MatchType"].upper() == "EQUALCASE": elif inURLItem["MatchType"].upper() == "EQUALCASE":
if inURLItem["URL"] == self.path: if inURLItem["URL"] == self.path:
URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) URLItemDo(inURLItem, self, mGlobalDict)
return True return True
return False return False
#ResponseContentTypeFile #ResponseContentTypeFile
@ -269,20 +274,24 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
#Закрыть файловый объект #Закрыть файловый объект
lFileObject.close() lFileObject.close()
# ResponseContentTypeFile # ResponseContentTypeFile
def ResponseDictSend(self, inResponseDict): def ResponseDictSend(self):
inResponseDict = self.OpenRPAResponseDict
# Send response status code # Send response status code
self.send_response(inResponseDict["StatusCode"]) self.send_response(inResponseDict["StatusCode"])
# Send headers # Send headers
for lItemKey, lItemValue in inResponseDict["Headers"].items(): for lItemKey, lItemValue in inResponseDict["Headers"].items():
self.send_header(lItemKey, lItemValue) self.send_header(lItemKey, lItemValue)
# Send headers: Set-Cookie
for lItemKey, lItemValue in inResponseDict["SetCookies"].items():
self.send_header("Set-Cookie", f"{lItemKey}={lItemValue}")
#Close headers section in response #Close headers section in response
self.end_headers() self.end_headers()
# Write content as utf-8 data # Write content as utf-8 data
self.wfile.write(inResponseDict["Body"]) self.wfile.write(inResponseDict["Body"])
# GET
def do_GET(self): def do_GET(self):
# Prepare result dict # Prepare result dict
lResponseDict = {"Headers": {}, "Set-cookies":{}, "Body": "", "StatusCode": None} lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": "", "StatusCode": None}
self.OpenRPAResponseDict = lResponseDict
##################################### #####################################
#Do authentication #Do authentication
#Check if authentication is turned on #Check if authentication is turned on
@ -309,38 +318,15 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
############################ ############################
#New server engine (url from global dict (URLList)) #New server engine (url from global dict (URLList))
############################ ############################
for lURLItem in mGlobalDict["URLList"]: for lURLItem in mGlobalDict["Server"]["URLList"]:
#Check if all condition are applied #Check if all condition are applied
lFlagURLIsApplied=False lFlagURLIsApplied=False
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET", lResponseDict) lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET")
if lFlagURLIsApplied: if lFlagURLIsApplied:
self.ResponseDictSend(lResponseDict) print("New engine")
self.ResponseDictSend()
return return
################################################### ###################################################
#Мост между файлом и http запросом (новый формат)
if self.path == "/":
self.SendResponseContentTypeFile('text/html', os.path.join(lOrchestratorFolder, "Web\\Index.xhtml"))
#Мост между файлом и http запросом (новый формат)
if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.css':
self.SendResponseContentTypeFile('text/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.css"))
#Мост между файлом и http запросом (новый формат)
if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.js':
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.js"))
#Мост между файлом и http запросом (новый формат)
if self.path == '/3rdParty/jQuery/jquery-3.1.1.min.js':
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\jQuery\\jquery-3.1.1.min.js"))
#Мост между файлом и http запросом (новый формат)
if self.path == '/3rdParty/Google/LatoItalic.css':
self.SendResponseContentTypeFile('font/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Google\\LatoItalic.css"))
#Мост между файлом и http запросом (новый формат)
if self.path == '/3rdParty/Semantic-UI-CSS-master/themes/default/assets/fonts/icons.woff2':
self.SendResponseContentTypeFile('font/woff2', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Semantic-UI-CSS-master\\themes\\default\\assets\\fonts\\icons.woff2"))
#Мост между файлом и http запросом (новый формат)
if self.path == '/favicon.ico':
self.SendResponseContentTypeFile('image/x-icon', os.path.join(lOrchestratorFolder, "Web\\favicon.ico"))
#Мост между файлом и http запросом (новый формат)
if self.path == '/3rdParty/Handlebars/handlebars-v4.1.2.js':
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Handlebars\\handlebars-v4.1.2.js"))
#Получить скриншот #Получить скриншот
if self.path.split("?")[0] == '/GetScreenshot': if self.path.split("?")[0] == '/GetScreenshot':
#Сохранить файл на диск #Сохранить файл на диск
@ -389,6 +375,9 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
self.end_headers() self.end_headers()
# POST # POST
def do_POST(self): def do_POST(self):
# Prepare result dict
lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": "", "StatusCode": None}
self.OpenRPAResponseDict = lResponseDict
##################################### #####################################
#Do authentication #Do authentication
#Check if authentication is turned on #Check if authentication is turned on

@ -1,4 +1,4 @@
import sys import sys
lFolderPath = "\\".join(__file__.split("\\")[:-2]) lFolderPath = "\\".join(__file__.split("\\")[:-3])
sys.path.insert(0, lFolderPath) sys.path.insert(0, lFolderPath)
from Orchestrator import Orchestrator from pyOpenRPA.Orchestrator import Orchestrator
Loading…
Cancel
Save