diff --git a/Sources/pyOpenRPA/Orchestrator/Server.py b/Sources/pyOpenRPA/Orchestrator/Server.py index 31d3713e..44d4801b 100644 --- a/Sources/pyOpenRPA/Orchestrator/Server.py +++ b/Sources/pyOpenRPA/Orchestrator/Server.py @@ -9,27 +9,16 @@ import uuid import datetime import os #for path operations from http import cookies -from desktopmagic.screengrab_win32 import ( - getDisplayRects, saveScreenToBmp, saveRectToBmp, getScreenAsImage, - getRectAsImage, getDisplaysAsImages) global mGlobalDict - - -def SaveScreenshot(inFilePath): - # grab fullscreen - # Save the entire virtual screen as a PNG - lScreenshot = getScreenAsImage() - lScreenshot.save('screenshot.png', format='png') - #lScreenshot = ScreenshotSecondScreen.grab_screen() - # save image file - #lScreenshot.save('screenshot.png') - +from . import ServerSettings #inGlobalDict # "JSONConfigurationDict": class RobotDaemonServer(Thread): def __init__(self,name,inGlobalDict): Thread.__init__(self) self.name = name + # Update the global dict + ServerSettings.SettingsUpdate(mGlobalDict) def run(self): inServerAddress=""; inPort = mGlobalDict["Server"]["ListenPort"]; @@ -225,12 +214,21 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): # Закрыть файловый объект lFileObject.close() #If function is set - if "ResponseDefRequestGlobalResponse" in inURLItem: - inURLItem["ResponseDefRequestGlobal"](inRequest,inGlobalDict) - # TODO If folder path is set + if "ResponseDefRequestGlobal" in inURLItem: + inURLItem["ResponseDefRequestGlobal"](inRequest, inGlobalDict) if "ResponseFolderPath" in inURLItem: - # - pass + lRequestPath = inRequest.path + lFilePathSecondPart = lRequestPath.replace(inURLItem["URL"],"") + lFilePath = os.path.join(inURLItem["ResponseFolderPath"],lFilePathSecondPart) + #print(f"File full path {lFilePath}") + #Check if file exist + if os.path.exists(lFilePath) and os.path.isfile(lFilePath): + lFileObject = open(lFilePath, "rb") + # Write content as utf-8 data + inResponseDict["Body"] = lFileObject.read() + inResponseDict["ContentType"]= "application/octet-stream" + # Закрыть файловый объект + lFileObject.close() ############################################## if inURLItem["Method"].upper() == inMethod.upper(): # check Match type variant: BeginWith @@ -323,15 +321,9 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): lFlagURLIsApplied=False lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET") if lFlagURLIsApplied: - print("New engine") + #print("New engine") self.ResponseDictSend() return - ################################################### - #Получить скриншот - if self.path.split("?")[0] == '/GetScreenshot': - #Сохранить файл на диск - SaveScreenshot("Screenshot.png") - self.SendResponseContentTypeFile('image/png',"Screenshot.png") #Monitor if self.path == '/Monitor/JSONDaemonListGet': # Send response status code @@ -343,24 +335,6 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): message = json.dumps(mGlobalDict) # Write content as utf-8 data self.wfile.write(bytes(message, "utf8")) - if self.path == '/Monitor/ControlPanelDictGet': - # Send response status code - self.send_response(200) - # Send headers - self.send_header('Content-type','application/json') - self.end_headers() - #Create result JSON - lResultJSON={"RenderRobotList":[]} - lRenderFunctionsRobotList=mGlobalDict["ControlPanelDict"]["RobotList"] - for lItem in lRenderFunctionsRobotList: - #Выполнить вызов и записать результат - lItemResultDict=lItem["RenderFunction"](mGlobalDict) - #RunFunction - lResultJSON["RenderRobotList"].append(lItemResultDict) - # Send message back to client - message = json.dumps(lResultJSON) - # Write content as utf-8 data - self.wfile.write(bytes(message, "utf8")) #Filemanager function if self.path.lower().startswith('/filemanager/'): lFileURL=self.path[13:] diff --git a/Sources/pyOpenRPA/Orchestrator/ServerSettings.py b/Sources/pyOpenRPA/Orchestrator/ServerSettings.py new file mode 100644 index 00000000..c8dc41ca --- /dev/null +++ b/Sources/pyOpenRPA/Orchestrator/ServerSettings.py @@ -0,0 +1,67 @@ +import json +#ControlPanelDict +from desktopmagic.screengrab_win32 import ( + getDisplayRects, saveScreenToBmp, saveRectToBmp, getScreenAsImage, + getRectAsImage, getDisplaysAsImages) +def Monitor_ControlPanelDictGet(inRequest,inGlobalDict): + inResponseDict = inRequest.OpenRPAResponseDict + # Create result JSON + lResultJSON = {"RenderRobotList": []} + lRenderFunctionsRobotList = inGlobalDict["ControlPanelDict"]["RobotList"] + for lItem in lRenderFunctionsRobotList: + # Выполнить вызов и записать результат + lItemResultDict = lItem["RenderFunction"](inGlobalDict) + # RunFunction + lResultJSON["RenderRobotList"].append(lItemResultDict) + # Send message back to client + message = json.dumps(lResultJSON) + # Write content as utf-8 data + #print(bytes(message, "utf8")) + inResponseDict["Body"] = bytes(message, "utf8") + +def GetScreenshot(inRequest,inGlobalDict): + # Get Screenshot + def SaveScreenshot(inFilePath): + # grab fullscreen + # Save the entire virtual screen as a PNG + lScreenshot = getScreenAsImage() + lScreenshot.save('screenshot.png', format='png') + # lScreenshot = ScreenshotSecondScreen.grab_screen() + # save image file + # lScreenshot.save('screenshot.png') + # Сохранить файл на диск + SaveScreenshot("Screenshot.png") + lFileObject = open("Screenshot.png", "rb") + # Write content as utf-8 data + inRequest.OpenRPAResponseDict["Body"] = lFileObject.read() + # Закрыть файловый объект + lFileObject.close() +def SettingsUpdate(inGlobalConfiguration): + import os + import pyOpenRPA.Orchestrator + lOrchestratorFolder = "\\".join(pyOpenRPA.Orchestrator.__file__.split("\\")[:-1]) + lURLList = \ + [ #List of available URLs with the orchestrator server + #{ + # "Method":"GET|POST", + # "URL": "/index", #URL of the request + # "MatchType": "", #"BeginWith|Contains|Equal|EqualCase", + # "ResponseFilePath": "", #Absolute or relative path + # "ResponseFolderPath": "", #Absolute or relative path + # "ResponseContentType": "", #HTTP Content-type + # "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"}, + {"Method": "GET", "URL": "/Monitor/ControlPanelDictGet", "MatchType": "Equal", "ResponseDefRequestGlobal": Monitor_ControlPanelDictGet, "ResponseContentType": "application/json"}, + {"Method": "GET", "URL": "/GetScreenshot", "MatchType": "BeginWith", "ResponseDefRequestGlobal": GetScreenshot, "ResponseContentType": "image/png"} + ] + inGlobalConfiguration["Server"]["URLList"]=inGlobalConfiguration["Server"]["URLList"]+lURLList + return inGlobalConfiguration \ No newline at end of file