From 0e25557ea2478ea235f46a1008d78fe6ef390c18 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Sun, 24 Nov 2019 10:43:53 +0300 Subject: [PATCH] Orchestrator new engine test 1 is complete. Need test 2 Restart button fix. All urls in settings Signed-off-by: Ivan Maslov --- Orchestrator/Settings/Settings.py | 15 ++++- .../pyOpenRPA/Orchestrator/Orchestrator.py | 1 + Sources/pyOpenRPA/Orchestrator/Server.py | 63 ++++++++----------- Sources/pyOpenRPA/Orchestrator/__main__.py | 4 +- 4 files changed, 43 insertions(+), 40 deletions(-) diff --git a/Orchestrator/Settings/Settings.py b/Orchestrator/Settings/Settings.py index 1900eb8e..23391779 100644 --- a/Orchestrator/Settings/Settings.py +++ b/Orchestrator/Settings/Settings.py @@ -1,5 +1,6 @@ import psutil import datetime + def RenderRobotR01(inGlobalConfiguration): #Subheader Variants lSubheaderRunTrueText="Состояние: Работает" @@ -65,6 +66,9 @@ def CheckIfProcessRunning(processName): #Orchestrator settings def Settings(): + import os + import pyOpenRPA.Orchestrator + lOrchestratorFolder = "\\".join(pyOpenRPA.Orchestrator.__file__.split("\\")[:-1]) mDict = { "Server": { "ListenPort_": "Порт, по которому можно подключиться к демону", @@ -112,8 +116,17 @@ def Settings(): # "ResponseFilePath": "", #Absolute or relative path # "ResponseFolderPath": "", #Absolute or relative path # "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": { diff --git a/Sources/pyOpenRPA/Orchestrator/Orchestrator.py b/Sources/pyOpenRPA/Orchestrator/Orchestrator.py index 1babc403..1cc29ae0 100644 --- a/Sources/pyOpenRPA/Orchestrator/Orchestrator.py +++ b/Sources/pyOpenRPA/Orchestrator/Orchestrator.py @@ -14,6 +14,7 @@ import logging import copy #from .Settings import Settings import importlib +from importlib import util #Создать файл логирования # add filemode="w" to overwrite if not os.path.exists("Reports"): diff --git a/Sources/pyOpenRPA/Orchestrator/Server.py b/Sources/pyOpenRPA/Orchestrator/Server.py index a608c5b4..31d3713e 100644 --- a/Sources/pyOpenRPA/Orchestrator/Server.py +++ b/Sources/pyOpenRPA/Orchestrator/Server.py @@ -101,6 +101,8 @@ def AuthenticateVerify(inRequest): #Set-cookie inRequest.OpenRPA["AuthToken"] = lAuthToken inRequest.OpenRPASetCookie = {} + #New engine of server + inRequest.OpenRPAResponseDict["SetCookies"]["AuthToken"] = lAuthToken #inRequest.OpenRPAResponse["Set-Cookie"]=[]lResult["Set-Cookie"] = lAuthToken #pdb.set_trace() #inRequest.send_header("Set-Cookie:", f"AuthToken={lAuthToken}") @@ -204,11 +206,14 @@ def UserAccessCheckBefore(inMethod, inRequest): class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): #Tech def #return {"headers":[],"body":"","statuscode":111} - def URLItemCheckDo(self, inURLItem, inMethod, inResponseDict): + def URLItemCheckDo(self, inURLItem, inMethod): ############################### #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 if "ResponseContentType" in inURLItem: inResponseDict["Headers"]["Content-type"] = inURLItem["ResponseContentType"] @@ -221,7 +226,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): lFileObject.close() #If function is set if "ResponseDefRequestGlobalResponse" in inURLItem: - inURLItem["ResponseDefRequestGlobalResponse"](inRequest,inGlobalDict,inResponseDict) + inURLItem["ResponseDefRequestGlobal"](inRequest,inGlobalDict) # TODO If folder path is set if "ResponseFolderPath" in inURLItem: # @@ -233,24 +238,24 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): lURLPath = self.path lURLPath = lURLPath.upper() if lURLPath.startswith(inURLItem["URL"].upper()): - URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) + URLItemDo(inURLItem, self, mGlobalDict) return True # check Match type variant: Contains elif inURLItem["MatchType"].upper() == "CONTAINS": lURLPath = self.path lURLPath = lURLPath.upper() if lURLPath.contains(inURLItem["URL"].upper()): - URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) + URLItemDo(inURLItem, self, mGlobalDict) return True # check Match type variant: Equal elif inURLItem["MatchType"].upper() == "EQUAL": if inURLItem["URL"].upper() == self.path.upper(): - URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) + URLItemDo(inURLItem, self, mGlobalDict) return True # check Match type variant: EqualCase elif inURLItem["MatchType"].upper() == "EQUALCASE": if inURLItem["URL"] == self.path: - URLItemDo(inURLItem, self, mGlobalDict,inResponseDict) + URLItemDo(inURLItem, self, mGlobalDict) return True return False #ResponseContentTypeFile @@ -269,20 +274,24 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): #Закрыть файловый объект lFileObject.close() # ResponseContentTypeFile - def ResponseDictSend(self, inResponseDict): + def ResponseDictSend(self): + inResponseDict = self.OpenRPAResponseDict # Send response status code self.send_response(inResponseDict["StatusCode"]) # Send headers for lItemKey, lItemValue in inResponseDict["Headers"].items(): 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 self.end_headers() # Write content as utf-8 data self.wfile.write(inResponseDict["Body"]) - # GET def do_GET(self): # Prepare result dict - lResponseDict = {"Headers": {}, "Set-cookies":{}, "Body": "", "StatusCode": None} + lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": "", "StatusCode": None} + self.OpenRPAResponseDict = lResponseDict ##################################### #Do authentication #Check if authentication is turned on @@ -309,38 +318,15 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): ############################ #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 lFlagURLIsApplied=False - lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET", lResponseDict) + lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET") if lFlagURLIsApplied: - self.ResponseDictSend(lResponseDict) + print("New engine") + self.ResponseDictSend() 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': #Сохранить файл на диск @@ -389,6 +375,9 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): self.end_headers() # POST def do_POST(self): + # Prepare result dict + lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": "", "StatusCode": None} + self.OpenRPAResponseDict = lResponseDict ##################################### #Do authentication #Check if authentication is turned on diff --git a/Sources/pyOpenRPA/Orchestrator/__main__.py b/Sources/pyOpenRPA/Orchestrator/__main__.py index f228ca09..c986e54c 100644 --- a/Sources/pyOpenRPA/Orchestrator/__main__.py +++ b/Sources/pyOpenRPA/Orchestrator/__main__.py @@ -1,4 +1,4 @@ import sys -lFolderPath = "\\".join(__file__.split("\\")[:-2]) +lFolderPath = "\\".join(__file__.split("\\")[:-3]) sys.path.insert(0, lFolderPath) -from Orchestrator import Orchestrator \ No newline at end of file +from pyOpenRPA.Orchestrator import Orchestrator \ No newline at end of file