<s> from robot . conf import RebotSettings <EOL> from robot . errors import DataError <EOL> from robot . model import ModelModifier <EOL> from robot . output import LOGGER <EOL> from robot . result import ExecutionResult , Result <EOL> from robot . utils import unic <EOL> from . jsmodelbuilders import JsModelBuilder <EOL> from . logreportwriters import LogWriter , ReportWriter <EOL> from . xunitwriter import XUnitWriter <EOL> class ResultWriter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * sources ) : <EOL> self . _sources = sources <EOL> def write_results ( self , settings = None , ** options ) : <EOL> """<STR_LIT>""" <EOL> settings = settings or RebotSettings ( options ) <EOL> results = Results ( settings , * self . _sources ) <EOL> if settings . output : <EOL> self . _write_output ( results . result , settings . output ) <EOL> if settings . xunit : <EOL> self . _write_xunit ( results . result , settings . xunit , <EOL> settings . xunit_skip_noncritical ) <EOL> if settings . log : <EOL> config = dict ( settings . log_config , <EOL> minLevel = results . js_result . min_level ) <EOL> self . _write_log ( results . js_result , settings . log , config ) <EOL> if settings . report : <EOL> results . js_result . remove_data_not_needed_in_report ( ) <EOL> self . _write_report ( results . js_result , settings . report , <EOL> settings . report_config ) <EOL> return results . return_code <EOL> def _write_output ( self , result , path ) : <EOL> self . _write ( '<STR_LIT>' , result . save , path ) <EOL> def _write_xunit ( self , result , path , skip_noncritical ) : <EOL> self . _write ( '<STR_LIT>' , XUnitWriter ( result , skip_noncritical ) . write , path ) <EOL> def _write_log ( self , js_result , path , config ) : <EOL> self . _write ( '<STR_LIT>' , LogWriter ( js_result ) . write , path , config ) <EOL> def _write_report ( self , js_result , path , config ) : <EOL> self . _write ( '<STR_LIT>' , ReportWriter ( js_result ) . write , path , config ) <EOL> def _write ( self , name , writer , path , * args ) : <EOL> try : <EOL> writer ( path , * args ) <EOL> except DataError as err : <EOL> LOGGER . error ( err . message ) <EOL> except EnvironmentError as err : <EOL> LOGGER . error ( "<STR_LIT>" % <EOL> ( name . lower ( ) , path , err . strerror , unic ( err . filename ) ) ) <EOL> else : <EOL> LOGGER . output_file ( name , path ) <EOL> class Results ( object ) : <EOL> def __init__ ( self , settings , * sources ) : <EOL> self . _settings = settings <EOL> self . _sources = sources <EOL> if len ( sources ) == <NUM_LIT:1> and isinstance ( sources [ <NUM_LIT:0> ] , Result ) : <EOL> self . _result = sources [ <NUM_LIT:0> ] <EOL> self . _prune = False <EOL> self . return_code = self . _result . return_code <EOL> else : <EOL> self . _result = None <EOL> self . _prune = True <EOL> self . return_code = - <NUM_LIT:1> <EOL> self . _js_result = None <EOL> @ property <EOL> def result ( self ) : <EOL> if self . _result is None : <EOL> include_keywords = bool ( self . _settings . log or self . _settings . output ) <EOL> flattened = self . _settings . flatten_keywords <EOL> self . _result = ExecutionResult ( include_keywords = include_keywords , <EOL> flattened_keywords = flattened , <EOL> merge = self . _settings . merge , <EOL> * self . _sources ) <EOL> self . _result . configure ( self . _settings . status_rc , <EOL> self . _settings . suite_config , <EOL> self . _settings . statistics_config ) <EOL> modifier = ModelModifier ( self . _settings . pre_rebot_modifiers , <EOL> self . _settings . process_empty_suite , <EOL> LOGGER ) <EOL> self . _result . suite . visit ( modifier ) <EOL> self . return_code = self . _result . return_code <EOL> return self . _result <EOL> @ property <EOL> def js_result ( self ) : <EOL> if self . _js_result is None : <EOL> builder = JsModelBuilder ( log_path = self . _settings . log , <EOL> split_log = self . _settings . split_log , <EOL> prune_input_to_save_memory = self . _prune ) <EOL> self . _js_result = builder . build_from ( self . result ) <EOL> if self . _prune : <EOL> self . _result = None <EOL> return self . _js_result </s>
