Exemple #1
0
    def generate_config(cls, path: str = None) -> None:
        """
        generate config file in ``path``.

        :param path: the config file path, if it's None, will be replaced by './config.yaml'.
        :return:
        """
        if path is None:
            path = "config.yaml"
        src_path = PathUtils.join(PathUtils.src_root_dir(), "resources",
                                  "config.yaml")
        shutil.copy(src_path, path)
Exemple #2
0
    def load_logging_config(cls) -> None:
        """

        """
        logging_config_path = PathUtils.join(PathUtils.src_root_dir(),
                                             "resources", "logging.yaml")
        with open(logging_config_path) as f:
            text = f.read().replace("{logs_root}", GflConf.logs_dir)
            data = yaml.load(text, yaml.SafeLoader)

        if cls.get_property("debug"):
            data["root"]["level"] = "DEBUG"
            data["loggers"]["gfl"]["level"] = "DEBUG"

        logging.config.dictConfig(data)
Exemple #3
0
    def load(cls) -> None:
        """
        load config properties from disk file.

        :return:
        """
        base_config_path = PathUtils.join(PathUtils.src_root_dir(),
                                          "resources", "config.yaml")
        with open(base_config_path) as f:
            cls.__readonly_props = yaml.load(f, Loader=yaml.SafeLoader)

        path = PathUtils.join(cls.home_dir, "config.yaml")
        if os.path.exists(path):
            with open(path) as f:
                config_data = yaml.load(f, Loader=yaml.SafeLoader)
                cls.__readonly_props.update(config_data)

        if os.path.exists(cls.logs_dir):
            cls.load_logging_config()
        else:
            warnings.warn("cannot found logs dir.")