def writeActionAsFileInTempDirectory(
vcoUrl: str,
bearerToken: str,
moduleName: str,
actionName: str,
fileName: str,
base64Encoded: bool = False
) -> bool:
""" Writes the content of an action as file in the temporary
directory, by using the JavaScript action getActionAsText.
@param vcoUrl {string} - URL of Aria orchestrator
@param bearerToken {string}
@param moduleName {string} - Module of the action
@param actionName {string} - Name of the action
@param fileName {string} - Name of the file
@param base64Encoded {bool} - If action contains base64 encoded
content true, otherwise false
@returns {bool} Indicates whether the file exists
@author Stefan Schnell <mail@stefan-schnell.de>
@license MIT
@version 0.1.0
"""
if not vcoUrl:
raise Exception("vcoUrl argument can not be null")
if not bearerToken:
raise Exception("bearerToken argument can not be null")
if not moduleName:
raise Exception("moduleName argument can not be null")
if not actionName:
raise Exception("actionName argument can not be null")
if not fileName:
raise Exception("fileName argument can not be null")
tempFileName: str = tempfile.gettempdir() + "/" + fileName
result: bool = False
parameters: list = [
{
"name": "in_moduleName", "type": "string", "value": {
"string": { "value": moduleName }
}
},
{
"name": "in_actionName", "type": "string", "value": {
"string": { "value": actionName }
}
}
]
action = Action()
try:
actionContent: str = action.invoke(
vcoUrl = vcoUrl,
bearerToken = bearerToken,
actionModule = "de.stschnell",
actionName = "getActionAsText",
parameters = parameters
)["executionResult"]["value"]["string"]["value"]
except Exception as err:
raise Exception(repr(err))
if not actionContent:
raise Exception("Action contains no content")
try:
if os.path.exists(tempFileName):
os.remove(tempFileName)
if base64Encoded:
with open(tempFileName, "wb") as outFile:
outFile.write(
base64.decodebytes(
actionContent.encode("ascii")
)
)
outFile.close()
else:
with open(tempFileName, "w") as outFile:
outFile.write(actionContent)
outFile.close()
except Exception as err:
raise Exception("Error at writeActionAsFileInTempDirectory " + \
" - " + repr(err))
if os.path.exists(tempFileName):
result = True
return result
|