def analyze(self, input_directory, output_directory, **kwargs):
is_api_call = True<EOL>if len(self._analyses) == <NUM_LIT:0>:<EOL><INDENT>if '<STR_LIT>' not in kwargs.keys():<EOL><INDENT>return CONSTANTS.ERROR<EOL><DEDENT>self.create_analysis(kwargs['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT:args>' in kwargs:<EOL><INDENT>self._process_args(self._analyses[<NUM_LIT:0>], kwargs['<STR_LIT:args>'])<EOL>is_api_call = False<EOL><DEDENT>error_count = <NUM_LIT:0><EOL>self._input_directory = input_directory<EOL>self._output_directory = output_directory<EOL>for test_id in sorted(self._analyses.keys()):<EOL><INDENT>if not self._analyses[test_id].input_directory:<EOL><INDENT>self._analyses[test_id].input_directory = input_directory<EOL><DEDENT>if not self._analyses[test_id].output_directory:<EOL><INDENT>if len(self._analyses) > <NUM_LIT:1>:<EOL><INDENT>self._analyses[test_id].output_directory = os.path.join(output_directory, str(test_id))<EOL><DEDENT>else:<EOL><INDENT>self._analyses[test_id].output_directory = output_directory<EOL><DEDENT><DEDENT>if('<STR_LIT>' in kwargs.keys()) and (not self._analyses[test_id].config):<EOL><INDENT>self._analyses[test_id].config = kwargs['<STR_LIT>']<EOL><DEDENT>self._create_output_directories(self._analyses[test_id])<EOL>self._analyses[test_id].status = self.run(self._analyses[test_id], is_api_call, **kwargs)<EOL>if self._analyses[test_id].status != CONSTANTS.OK:<EOL><INDENT>error_count += <NUM_LIT:1><EOL><DEDENT><DEDENT>if len(self._analyses) == <NUM_LIT:1>:<EOL><INDENT>return self._analyses[<NUM_LIT:0>].status<EOL><DEDENT>elif error_count > <NUM_LIT:0>:<EOL><INDENT>return CONSTANTS.ERROR<EOL><DEDENT>else:<EOL><INDENT>return CONSTANTS.OK<EOL><DEDENT>
Run all the analysis saved in self._analyses, sorted by test_id.
This is useful when Naarad() is used by other programs and multiple analyses are run
In naarad CLI mode, len(_analyses) == 1
:param: input_directory: location of log files
:param: output_directory: root directory for analysis output
:param: **kwargs: Optional keyword args
:return: int: status code.