viktor.external.generic
GenericAnalysis
- class viktor.external.generic.GenericAnalysis(files=None, executable_key=None, output_filenames=None)
Bases:
ExternalProgram
GenericAnalysis can be used to evaluate an executable on third-party infrastructure. The executable is expected to be blocking, i.e. if the executable is invoked from command prompt, it should wait until the executable is finished. For security purposes the executable that should be called has to be defined in the configuration file of the worker.
Usage:
files = [ ('input1.txt', file1), ('input2.txt', file2) ] generic_analysis = GenericAnalysis(files=files, executable_key="someexecutable", output_filenames=["output.txt"]) generic_analysis.execute(timeout=60) output_file = generic_analysis.get_output_file("output.txt")
Exceptions which can be raised during calculation:
viktor.errors.LicenseError
: no license availableviktor.errors.ExecutionError
: generic error. Error message provides more information
- Parameters:
files (
List
[Tuple
[str
,Union
[BytesIO
,File
]]]) – Files that are transferred to the working directory on the server. Each file is a tuple containing the content and the filename which is used to save on the infrastructure.executable_key (
str
) – The key of the executable that needs to be evaluated. This key should be present in the configuration file of the worker.output_filenames (
List
[str
]) – A list of filenames (including extension) that are to be transferred back to the SDK. This filename is relative to the working directory.
At least one of the attributes above should be included in the call.
- Raises:
ValueError – when no attribute is included in call.
- get_output_file(filename, *, as_file=False)
Method can be used to retrieve the results generated by running an external analysis. Call method
execute()
first andget_output_file()
afterwards.- Parameters:
filename (
str
) – The name of the file (including extension) that you want to get.as_file (
bool
) – Return as BytesIO (default) or File
- Return type:
Union
[BytesIO
,File
,None
]