55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
from ScEpTIC.analysis.options import AnalysisResultFormat
|
|
from ScEpTIC.config.base_config import ScEpTICBaseConfig
|
|
from ScEpTIC.analysis import CONFIG_FUNCTION_NAME
|
|
|
|
class AnalysisConfig(ScEpTICBaseConfig):
|
|
"""
|
|
Configuration for AST Transformations
|
|
"""
|
|
_config_domain = {
|
|
'enabled_analysis': {'class': str, 'mode': 'add'},
|
|
'save_results': {'class': bool, 'mode': 'set'},
|
|
'results_formats': {'class': AnalysisResultFormat, 'mode': 'add'},
|
|
}
|
|
|
|
|
|
def __init__(self, main_config):
|
|
super().__init__(main_config)
|
|
|
|
self.__default_removed = False
|
|
|
|
self.enabled_analysis = []
|
|
self.save_results = True
|
|
self.results_formats = [AnalysisResultFormat.JSON, AnalysisResultFormat.TEXT]
|
|
|
|
self._register_config_callback("enabled_analysis", self._analysis_callback)
|
|
self._register_config_callback("results_formats", self._results_format_callback)
|
|
|
|
def _analysis_callback(self, config_name, config_value):
|
|
"""
|
|
Callback to add an analysis configuration
|
|
:param config_name: the configuration name
|
|
:param config_value: the configuration value
|
|
"""
|
|
module_name = 'ScEpTIC.analysis.{}.config'.format(config_value)
|
|
module = __import__(module_name, fromlist=[CONFIG_FUNCTION_NAME])
|
|
config = getattr(module, CONFIG_FUNCTION_NAME)
|
|
setattr(self, config_value, config(self._main_config))
|
|
|
|
|
|
def _results_format_callback(self, config_name, config_value):
|
|
"""
|
|
Removes the defaults results formats and ensures that no duplicates are in the list.
|
|
:param config_name: the configuration name
|
|
:param config_value: the configuration value
|
|
"""
|
|
|
|
if not self.__default_removed:
|
|
self.__default_removed = True
|
|
|
|
# Remove the default values and keep the added one
|
|
self.results_formats = [self.results_formats[-1]]
|
|
|
|
# Avoid duplicates when saving. Not an elegant solution, but works and keeps the generality of the "add" mode.
|
|
self.results_formats = list(set(self.results_formats))
|