def start(self) -> None:
        # Construct configuration file
        if len(sys.argv) > 1:
            config_file = sys.argv[1]
        else:
            config_file = f"{Common.get_proj_root_path()}/res/conf/conf.ini"

        try:
            Validation.is_file_readable(
                config_file,
                f"Error on '{config_file}': configuration file *must* exists and be readable"
            )

            dispatcher_config = DispatcherConfig.get_instance()
            dispatcher_config.load_from(config_file)

            self.__file_observer = FileObserver(dispatcher_config)
            atexit.register(self.stop)
            # Blocking call
            self.__file_observer.start()
        except SyntaxError:
            print(
                f"Syntax error in configuration file.\n"
                f"Make sure to follow JSON format while defining formats, sources, destinations and rules."
            )
        except Exception as e:
            print(e)
Exemple #2
0
    def load_from(self, config_file: str) -> None:
        """

        :param config_file:
        :raise: SyntaxError if there is a syntax error in configuration file
        """
        Validation.is_file_readable(
            config_file, f"File '{config_file}' *must* exists and be readable")

        with self.__LOCK:
            self.__config_parser.read(config_file)
            self.__upload_config()
    def load_from(cls, log_config_file: str) -> None:
        from util import Validation
        Validation.is_file_readable(
            log_config_file,
            f"File '{log_config_file}' *must* exists and be readable")

        with cls.__LOCK:
            logging.config.fileConfig(fname=log_config_file)
            # loggers
            cls._LOGGER_ROOT = logging.getLogger(LogManager.Logger.ROOT.value)
            cls._LOGGER_OBSERVER = logging.getLogger(
                LogManager.Logger.OBSERVER.value)
            cls._LOGGER_CONVERTER = logging.getLogger(
                LogManager.Logger.CONVERTER.value)
    def __init_conf(self):
        # construct configuration file
        if len(sys.argv) > 1:
            conf_path = sys.argv[1]
        else:
            conf_path = f"{Path(Common.get_root_path(), Client._DEFAULT_CONF_PATH)}"

        Validation.is_file_readable(
            conf_path,
            f"Error on '{conf_path}': configuration file *must* exists and be readable"
        )

        self.__conf = Conf.get_instance()
        self.conf.load_from(conf_path)

        if self.conf.debug:
            self.__LOG_MANAGER.enable_debug_level()
    def load_from(self, config_file: str) -> None:
        """

        :param config_file:
        :raise: SyntaxError if there is a syntax error in configuration file
        """
        Validation.is_file_readable(
            config_file, f"File '{config_file}' *must* exists and be readable")
        self.__config_parser.read(config_file)

        # section GENERAL
        self.__put_str(Conf.K_TMP, Conf.S_GENERAL, Conf.K_TMP,
                       Conf.V_DEFAULT_TMP)
        self.__put_bool(Conf.K_DEBUG, Conf.S_GENERAL, Conf.K_DEBUG,
                        Conf.V_DEFAULT_DEBUG)

        # section TRAINING
        self.__put_str(Conf.K_DATASET_TRAIN, Conf.S_TRAINING,
                       Conf.K_DATASET_TRAIN, Conf.V_DEFAULT_DATASET_TRAIN)
        self.__put_float(Conf.K_DATASET_TEST_RATIO, Conf.S_TRAINING,
                         Conf.K_DATASET_TEST_RATIO,
                         Conf.V_DEFAULT_DATASET_TEST_RATIO)
        self.__put_int(Conf.K_RNG_SEED, Conf.S_TRAINING, Conf.K_RNG_SEED,
                       Conf.V_DEFAULT_RNG_SEED)
        self.__put_bool(Conf.K_CHARTS_COMPUTE, Conf.S_TRAINING,
                        Conf.K_CHARTS_COMPUTE, Conf.V_DEFAULT_CHARTS_COMPUTE)
        self.__put_bool(Conf.K_CHARTS_SAVE, Conf.S_TRAINING,
                        Conf.K_CHARTS_SAVE, Conf.V_DEFAULT_CHARTS_SAVE)
        self.__put_int(Conf.K_JOBS, Conf.S_TRAINING, Conf.K_JOBS,
                       Conf.V_DEFAULT_JOBS)
        self.__put_bool(Conf.K_CLASSIFIER_DUMP, Conf.S_TRAINING,
                        Conf.K_CLASSIFIER_DUMP, Conf.V_DEFAULT_CLASSIFIER_DUMP)

        # section MOBD
        self.__put_tuple(Conf.K_BENCHMARK_BEST_FOUND, Conf.S_MOBD,
                         Conf.K_BENCHMARK_BEST_FOUND,
                         Conf.V_DEFAULT_BENCHMARK_BEST_FOUND)
        self.__put_tuple(Conf.K_BENCHMARK_THRESHOLD, Conf.S_MOBD,
                         Conf.K_BENCHMARK_THRESHOLD,
                         Conf.V_DEFAULT_BENCHMARK_THRESHOLD)
        self.__put_str(Conf.K_DATASET_TEST, Conf.S_MOBD, Conf.K_DATASET_TEST,
                       Conf.V_DEFAULT_DATASET_TEST)