import os
from anadroid.results_analysis.AbstractAnalyzer import AbstractAnalyzer
from anadroid.utils.Utils import execute_shell_command, log_to_file
DEFAULT_FILENAME = "scc.json"
[docs]class SCCAnalyzer(AbstractAnalyzer):
"""Implements AbstractAnalyzer interface to allow to calculate app code results using scc tool.
"""
def __init__(self, profiler):
super(SCCAnalyzer, self).__init__(profiler)
self.bin_cmd = "scc"
[docs] def setup(self, **kwargs):
pass
[docs] def analyze(self, app, output_log_file=DEFAULT_FILENAME, **kwargs):
input_dir = app.proj.proj_dir
cmd = f"{self.bin_cmd} {input_dir} -f json"
res = execute_shell_command(cmd)
if res.validate(Exception(f"Unable to analyze sources with {self.bin_cmd}")):
log_to_file(res.output, output_log_file, mode='w')
[docs] def show_results(self, app_list):
pass
[docs] def get_val_for_filter(self, filter_name, add_data=None):
return super().get_val_for_filter(filter_name, add_data)
[docs] def analyze_tests(self, app=None, results_dir=None, **kwargs):
if app is None:
return True
base_dir = app.local_res if results_dir is None else results_dir
output_file = os.path.join(base_dir, DEFAULT_FILENAME)
self.analyze(app, output_file, **kwargs)
[docs] def analyze_test(self, app, test_id, **kwargs):
pass
[docs] def validate_test(self, app, arg1, **kwargs):
return True
[docs] def validate_filters(self):
return super().validate_filters()