From 2fc1553c9f62fedabc00a561cec5da5f64e076ea Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Sun, 6 Dec 2020 20:19:04 +0300 Subject: [PATCH] - Agent Add 2 defs: - - def OSFileTextDataStrCreate(inFilePathStr, inFileDataStr, inEncodingStr = "utf-8",inGSettings = None): # Create text file by the string - - def OSFileBinaryDataBase64StrCreate(inFilePathStr, inFileDataBase64Str,inGSettings = None): # Create binary file by the base64 string (safe for JSON transmition) -Orc Defs - - def AgentOSFileBinaryDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBytes): # Send binary file to Agent (Bytes) - - def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBase64Str): # Send binary file to Agent (base64 string) - - def AgentOSFileTextDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataStr, inEncodingStr = "utf-8"): # Send text file to Agent (string) --- Sources/pyOpenRPA/Agent/Agent.py | 21 ++++++-- .../pyOpenRPA/Orchestrator/Orchestrator.py | 48 ++++++++++++++----- changelog.md | 10 ++-- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/Sources/pyOpenRPA/Agent/Agent.py b/Sources/pyOpenRPA/Agent/Agent.py index 02f9a4fd..d17a77d1 100644 --- a/Sources/pyOpenRPA/Agent/Agent.py +++ b/Sources/pyOpenRPA/Agent/Agent.py @@ -1,13 +1,24 @@ -import threading, socket, getpass, sys, uuid, subprocess +import threading, socket, getpass, sys, uuid, subprocess, base64 from . import O2A, A2O # Data flow Orchestrator To Agent from . import Processor # Processor Queue -# Send CMD to OS. Result return to log + Orchestrator by the A2O connection -def OSFileDataBytesCreate(inFilePathStr, inFileDataBytes,inGSettings = None): +# Create binary file by the base64 string (safe for JSON transmition) +def OSFileBinaryDataBase64StrCreate(inFilePathStr, inFileDataBase64Str,inGSettings = None): lFile = open(inFilePathStr, "wb") - lFile.write(inFileDataBytes) + lFile.write(base64.b64decode(inFileDataBase64Str)) + lFile.close() + lL = inGSettings.get("Logger", None) if type(inGSettings) is dict else None + lMessageStr = f"AGENT Binary file {inFilePathStr} has been created." + if lL: lL.info(lMessageStr) + A2O.LogListSend(inGSettings=inGSettings, inLogList=[lMessageStr]) + +# Create text file by the string +def OSFileTextDataStrCreate(inFilePathStr, inFileDataStr, inEncodingStr = "utf-8",inGSettings = None): + lFile = open(inFilePathStr, "w", encoding=inEncodingStr) + lFile.write(inFileDataStr) + lFile.close() lL = inGSettings.get("Logger", None) if type(inGSettings) is dict else None - lMessageStr = f"AGENT File {inFilePathStr} has been created." + lMessageStr = f"AGENT Text file {inFilePathStr} has been created." if lL: lL.info(lMessageStr) A2O.LogListSend(inGSettings=inGSettings, inLogList=[lMessageStr]) diff --git a/Sources/pyOpenRPA/Orchestrator/Orchestrator.py b/Sources/pyOpenRPA/Orchestrator/Orchestrator.py index f9f2b8ad..e2c461a2 100644 --- a/Sources/pyOpenRPA/Orchestrator/Orchestrator.py +++ b/Sources/pyOpenRPA/Orchestrator/Orchestrator.py @@ -1,4 +1,4 @@ -import subprocess, json, psutil, time, os, win32security, sys #Get input argument +import subprocess, json, psutil, time, os, win32security, sys, base64 #Get input argument from . import Server from . import Timer from . import Processor @@ -50,27 +50,51 @@ def AgentOSCMD(inGSettings, inHostNameStr, inUserStr, inCMDStr, inRunAsyncBool=T #Send item in AgentDict for the futher data transmition AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) -# Send to agent activity item to OSCMD -def AgentOSFileDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBytes): - # pyOpenRPA.Agent: Send CMD to OS. Result return to log + Orchestrator by the A2O connection - # def OSFileBytesCreate(inFilePathStr, inFileDataBytes,inGSettings = None): +# Send binary file to Agent (Bytes) +def AgentOSFileBinaryDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBytes): + # pyOpenRPA.Agent: Create binary file by the base64 string (safe for JSON transmition) + # def OSFileBinaryDataBase64StrCreate(inFilePathStr, inFileDataBase64Str,inGSettings = None): # Create Activity Item for the agent + lFileDataBase64Str = base64.b64encode(inFileDataBytes).decode("utf-8") lActivityItemDict = { - "Def":"OSFileDataBytesCreate", # def alias (look pyOpeRPA.Agent gSettings["ProcessorDict"]["AliasDefDict"]) + "Def":"OSFileBinaryDataBase64StrCreate", # def alias (look pyOpeRPA.Agent gSettings["ProcessorDict"]["AliasDefDict"]) "ArgList":[], # Args list - "ArgDict":{"inFilePathStr":inFilePathStr,"inFileDataBytes":inFileDataBytes}, # Args dictionary + "ArgDict":{"inFilePathStr":inFilePathStr,"inFileDataBase64Str":lFileDataBase64Str}, # Args dictionary "ArgGSettings": "inGSettings", # Name of GSettings attribute: str (ArgDict) or index (for ArgList) "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) -# Send to agent activity item to OSCMD -def AgentOSFileDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataStr, inEncodingStr="utf-8"): - # pyOpenRPA.Agent: Send CMD to OS. Result return to log + Orchestrator by the A2O connection - # def OSFileBytesCreate(inFilePathStr, inFileDataBytes,inGSettings = None): +# Send binary file to Agent (base64 string) +def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBase64Str): + # pyOpenRPA.Agent: Create binary file by the base64 string (safe for JSON transmition) + # def OSFileBinaryDataBase64StrCreate(inFilePathStr, inFileDataBase64Str,inGSettings = None): + # Create Activity Item for the agent + lActivityItemDict = { + "Def":"OSFileBinaryDataBase64StrCreate", # def alias (look pyOpeRPA.Agent gSettings["ProcessorDict"]["AliasDefDict"]) + "ArgList":[], # Args list + "ArgDict":{"inFilePathStr":inFilePathStr,"inFileDataBase64Str":inFileDataBase64Str}, # Args dictionary + "ArgGSettings": "inGSettings", # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + } + #Send item in AgentDict for the futher data transmition + AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) + +# Send text file to Agent (string) +def AgentOSFileTextDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataStr, inEncodingStr = "utf-8"): + # pyOpenRPA.Agent: Create text file by the string + # def OSFileTextDataStrCreate(inFilePathStr, inFileDataStr, inEncodingStr = "utf-8",inGSettings = None): # Create Activity Item for the agent - AgentOSFileDataBytesCreate(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inFilePathStr=inFilePathStr, inFileDataBytes=inFileDataStr.encode(inEncodingStr)) + lActivityItemDict = { + "Def":"OSFileTextDataStrCreate", # def alias (look pyOpeRPA.Agent gSettings["ProcessorDict"]["AliasDefDict"]) + "ArgList":[], # Args list + "ArgDict":{"inFilePathStr":inFilePathStr,"inFileDataStr":inFileDataStr, "inEncodingStr": inEncodingStr}, # Args dictionary + "ArgGSettings": "inGSettings", # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + } + #Send item in AgentDict for the futher data transmition + AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) # OS DEFS # Defs to use in orchestrator diff --git a/changelog.md b/changelog.md index b4651925..62febdcb 100644 --- a/changelog.md +++ b/changelog.md @@ -60,13 +60,15 @@ - Agent: Create Processor in Agent similarly to Orchestrator (pyOpenRPA.Agent.Processor == pyOpenRPA.Orchestrator.Processor) - Agent: Add Agent defs as Alias in ProcessorDict - Agent Add 2 defs: -- - def OSFileBytesCreate(inFilePathStr, inFileBytes,inGSettings = None): # Send CMD to OS. Result return to log + Orchestrator by the A2O connection +- - def OSFileTextDataStrCreate(inFilePathStr, inFileDataStr, inEncodingStr = "utf-8",inGSettings = None): # Create text file by the string +- - def OSFileBinaryDataBase64StrCreate(inFilePathStr, inFileDataBase64Str,inGSettings = None): # Create binary file by the base64 string (safe for JSON transmition) - - def OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings = None): # Send CMD to OS. Result return to log + Orchestrator by the A2O connection - Orc: Add Agent Defs - - def AgentActivityItemAdd(inGSettings, inHostNameStr, inUserStr, inActivityItemDict): # Add activity in AgentDict - - def AgentOSCMD(inGSettings, inHostNameStr, inUserStr, inCMDStr): # Send to agent activity item to OSCMD -- - def AgentOSFileDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBytes): # Send to agent activity item to OSCMD -- - def AgentOSFileDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataStr, inEncodingStr="utf-8"): # Send to agent activity item to OSCMD +- - def AgentOSFileBinaryDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBytes): # Send binary file to Agent (Bytes) +- - def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBase64Str): # Send binary file to Agent (base64 string) +- - def AgentOSFileTextDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataStr, inEncodingStr = "utf-8"): # Send text file to Agent (string) - Orc WEB: Create mGlobal.pyOpenRPA.ActivityListExecute({}) to test some activities from the front [1.1.0] After 2 month test prefinal with new improovements (+RobotRDPActive in Orchestrator + Easy ControlPanelTemplate) @@ -74,7 +76,7 @@ Beta before 1.1.0 (new way of OpenRPA with improvements. Sorry, but no backward [1.0.37] Minor fix in RobotRDPActive [1.0.33] -Manu changes - look git +Menu changes - look git [1.0.31] Orchestrator new engine - test 2 is ready. Go to PIP [1.0.30]