コード例 #1
0
ファイル: confile.py プロジェクト: ylcumberbirch/pyms
    def __init__(self, *args, **kwargs):
        """
        Get configuration from a dictionary(variable `config`), from path (variable `path`) or from
        environment with the constant `CONFIGMAP_FILE`
        Set the configuration as upper case to inject the keys in flask config. Flask search for uppercase keys in
        `app.config.from_object`
        ```python
        if key.isupper():
            self[key] = getattr(obj, key)
        ```
        """
        self._loader = LoadFile(kwargs.get("path"), CONFIGMAP_FILE_ENVIRONMENT,
                                DEFAULT_CONFIGMAP_FILENAME)
        self._crypt = Crypt(path=kwargs.get("path"))
        self._empty_init = kwargs.get("empty_init", False)
        config = kwargs.get("config")
        if config is None:
            config = self._loader.get_file(anyconfig.load)
        if not config:
            if self._empty_init:
                config = {}
            else:
                path = self._loader.path if self._loader.path else ""
                raise ConfigDoesNotFoundException(
                    "Configuration file {}not found".format(path + " "))

        config = self.set_config(config)

        super(ConfFile, self).__init__(config)
コード例 #2
0
ファイル: confile.py プロジェクト: pkjmesra/pyms
    def __init__(self, *args, **kwargs):
        """
        Get configuration from a dictionary(variable `config`), from path (variable `path`) or from
        environment with the constant `PYMS_CONFIGMAP_FILE`
        Set the configuration as upper case to inject the keys in flask config. Flask search for uppercase keys in
        `app.config.from_object`
        ```python
        if key.isupper():
            self[key] = getattr(obj, key)
        ```
        """
        # TODO Remove temporally backward compatibility on future versions
        configmap_file_env = self.__get_updated_configmap_file_env(
        )  # Temporally backward compatibility

        self._loader = LoadFile(kwargs.get("path"), configmap_file_env,
                                DEFAULT_CONFIGMAP_FILENAME)
        self._crypt_cls = kwargs.get("crypt")
        if self._crypt_cls:
            self._crypt = self._crypt_cls(path=kwargs.get("path"))
        self._empty_init = kwargs.get("empty_init", False)
        config = kwargs.get("config")
        if config is None:
            config = self._loader.get_file(anyconfig.load)
        if not config:
            if self._empty_init:
                config = {}
            else:
                path = self._loader.path if self._loader.path else ""
                raise ConfigDoesNotFoundException(
                    "Configuration file {}not found".format(path + " "))

        config = self.set_config(config)

        super().__init__(config)
コード例 #3
0
    def __init__(self, *args, **kwargs):
        """
        Get configuration from a dictionary(variable `config`), from path (variable `path`) or from
        environment with the constant `CONFIGMAP_FILE_ENVIRONMENT`
        """

        config = kwargs.get("config") or self._get_conf_from_file(
            kwargs.get("path")) or self._get_conf_from_env()

        if not config:
            raise ConfigDoesNotFoundException("Configuration file not found")

        logger.debug("[CONF] INIT: Settings {kwargs}".format(kwargs=kwargs, ))

        config = {k: v for k, v in self.normalize_config(config)}
        [setattr(self, k, v) for k, v in config.items()]
        super(ConfFile, self).__init__(config)
コード例 #4
0
    def __init__(self, *args, **kwargs):
        """
        Get configuration from a dictionary(variable `config`), from path (variable `path`) or from
        environment with the constant `CONFIGMAP_FILE`
        """
        self.empty_init = kwargs.get("empty_init", False)
        config = kwargs.get("config")
        if config is None:
            config = self._get_conf_from_file(
                kwargs.get("path")) or self._get_conf_from_env()

        if not config:
            if self.empty_init:
                config = {}
            else:
                raise ConfigDoesNotFoundException(
                    "Configuration file not found")

        config = dict(self.normalize_config(config))
        _ = [setattr(self, k, v) for k, v in config.items()]
        super(ConfFile, self).__init__(config)