@ -26,6 +26,7 @@ from .RobotScreenActive import Monitor #Start robot screen active
from . import SettingsTemplate # Settings template
import uuid # Generate uuid
import datetime # datetime
import math
#Единый глобальный словарь (З а основу взять из Settings.py)
gSettingsDict = None
@ -60,6 +61,27 @@ def AgentActivityItemAdd(inGSettings, inHostNameStr, inUserStr, inActivityItemDi
# Return the result
return lGUIDStr
def AgentActivityItemExists ( inGSettings , inHostNameStr , inUserStr , inGUIDStr ) :
"""
Check by GUID if ActivityItem has exists in request list . If exist - the result response has not been recieved from the agent
: param inGSettings : Global settings dict ( singleton )
: param inGUIDStr : GUID String of the ActivityItem
: return : True - ActivityItem is exist in AgentDict ; False - else case
"""
# Check if GUID is exists in dict - has been recieved
# Main alg
lAgentDictItemKeyTurple = ( inHostNameStr . upper ( ) , inUserStr . upper ( ) )
lResultBool = False
if lAgentDictItemKeyTurple in inGSettings [ " AgentDict " ] :
inGSettings [ " AgentDict " ] [ lAgentDictItemKeyTurple ] = SettingsTemplate . __AgentDictItemCreate__ ( )
for lActivityItem in inGSettings [ " AgentDict " ] [ lAgentDictItemKeyTurple ] [ " ActivityList " ] :
if inGUIDStr == lActivityItem . get ( " GUIDStr " , None ) :
lResultBool = True
break
return lResultBool
def AgentActivityItemReturnExists ( inGSettings , inGUIDStr ) :
"""
Check by GUID if ActivityItem has been executed and result has come to the Orchestrator
@ -117,6 +139,55 @@ def AgentOSCMD(inGSettings, inHostNameStr, inUserStr, inCMDStr, inRunAsyncBool=T
#Send item in AgentDict for the futher data transmition
return AgentActivityItemAdd ( inGSettings = inGSettings , inHostNameStr = inHostNameStr , inUserStr = inUserStr , inActivityItemDict = lActivityItemDict )
def AgentOSFileSend ( inGSettings , inHostNameStr , inUserStr , inOrchestratorFilePathStr , inAgentFilePathStr ) :
"""
Send the file from the Orchestrator to Agent ( synchroniously ) pyOpenRPA . Agent daemon process ( safe for JSON transmition ) .
Work safety with big files
: param inGSettings : Global settings dict ( singleton )
: param inHostNameStr :
: param inUserStr :
: param inFilePathStr :
: param inFileDataBytes :
: return : GUID String of the ActivityItem - you can wait ( sync or async ) result by this guid !
"""
lActivityItemCheckIntervalSecFloat = inGSettings [ " ServerDict " ] [ " AgentFileChunkCheckIntervalSecFloat " ]
# Get the chunk limit
lChunkByteSizeInt = inGSettings [ " ServerDict " ] [ " AgentFileChunkBytesSizeInt " ]
lL = inGSettings . get ( " Logger " , None )
# Open the file and get the size (in bytes)
lFile = open ( inOrchestratorFilePathStr , " rb " )
lFileSizeBytesInt = lFile . seek ( 0 , 2 )
lFile . seek ( 0 )
lChunkCountInt = math . ceil ( lFileSizeBytesInt / lChunkByteSizeInt )
if lL : lL . info ( f " O2A: Start to send binary file via chunks. Chunk count: { lChunkCountInt } , From (Orch side): { inOrchestratorFilePathStr } , To (Agent side): { inAgentFilePathStr } " )
for lChunkNumberInt in range ( lChunkCountInt ) :
# Read chunk
lFileChunkBytes = lFile . read ( lChunkByteSizeInt )
# Convert to base64
lFileChunkBase64Str = base64 . b64encode ( lFileChunkBytes ) . decode ( " utf-8 " )
# Send chunk
if lChunkNumberInt == 0 :
lActivityItemGUIDStr = AgentOSFileBinaryDataBase64StrCreate ( inGSettings = inGSettings , inHostNameStr = inHostNameStr ,
inUserStr = inUserStr , inFilePathStr = inAgentFilePathStr ,
inFileDataBase64Str = lFileChunkBase64Str )
else :
lActivityItemGUIDStr = AgentOSFileBinaryDataBase64StrAppend ( inGSettings = inGSettings , inHostNameStr = inHostNameStr ,
inUserStr = inUserStr , inFilePathStr = inAgentFilePathStr ,
inFileDataBase64Str = lFileChunkBase64Str )
# Wait for the activity will be deleted
while AgentActivityItemExists ( inGSettings = inGSettings , inHostNameStr = inHostNameStr , inUserStr = inUserStr , inGUIDStr = lActivityItemGUIDStr ) :
time . sleep ( lActivityItemCheckIntervalSecFloat )
if lL : lL . debug (
f " O2A: BINARY SEND: Current chunk index: { lChunkNumberInt } " )
# Close the file
lFile . close ( )
def AgentOSFileBinaryDataBytesCreate ( inGSettings , inHostNameStr , inUserStr , inFilePathStr , inFileDataBytes ) :
"""
Create binary file by the base64 string by the pyOpenRPA . Agent daemon process ( safe for JSON transmition )
@ -163,6 +234,30 @@ def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr,
#Send item in AgentDict for the futher data transmition
return AgentActivityItemAdd ( inGSettings = inGSettings , inHostNameStr = inHostNameStr , inUserStr = inUserStr , inActivityItemDict = lActivityItemDict )
def AgentOSFileBinaryDataBase64StrAppend ( inGSettings , inHostNameStr , inUserStr , inFilePathStr , inFileDataBase64Str ) :
"""
Append binary file by the base64 string by the pyOpenRPA . Agent daemon process ( safe for JSON transmission )
: param inGSettings : Global settings dict ( singleton )
: param inHostNameStr :
: param inUserStr :
: param inFilePathStr :
: param inFileDataBase64Str :
: return : GUID String of the ActivityItem - you can wait ( sync or async ) result by this guid !
"""
lActivityItemDict = {
" Def " : " OSFileBinaryDataBase64StrAppend " , # 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
return 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 " ) :
"""