Exemplo n.º 1
0
    def _get_configuration(self):
        # get options from config files and environment vairables
        merged_config = {}

        try:
            merged_config.update(
                self._read_configuration_file(self.glob_config_path))
        except Exception as e:
            Utils.warn('error while parsing global configuration Reason: ' +
                       e.message)

        try:
            merged_config.update(
                self._read_configuration_file(self.local_config_path))
        except Exception as e:
            Utils.warn('error while parsing user configuration Reason: ' +
                       e.message)

        merged_config.update(self._read_env_vars_config())

        self._check_configuration(merged_config)

        return merged_config
Exemplo n.º 2
0
    def __init__(self):
        # compute the location of the config files
        config_file_path_global = self._select([
            os.environ.get('CHEAT_GLOBAL_CONF_PATH'),
            '/etc/cheat',
        ])
        config_file_path_local = self._select([
            os.environ.get('CHEAT_LOCAL_CONF_PATH'),
            os.path.expanduser('~/.config/cheat/cheat'),
        ])

        # attempt to read the global config file
        config = {}
        try:
            config.update(self._read_config_file(config_file_path_global))
        except Exception as e:
            Utils.warn('Error while parsing global configuration: '
                       + e.message)

        # attempt to read the local config file
        try:
            config.update(self._read_config_file(config_file_path_local))
        except Exception as e:
            Utils.warn('Error while parsing local configuration: ' + e.message)

        # With config files read, now begin to apply envvar overrides and
        # default values

        # self.cheat_colors
        self.cheat_colors = self._select([
            Utils.boolify(os.environ.get('CHEAT_COLORS')),
            Utils.boolify(os.environ.get('CHEATCOLORS')),
            Utils.boolify(config.get('CHEAT_COLORS')),
            True,
        ])

        # self.cheat_colorscheme
        self.cheat_colorscheme = self._select([
            os.environ.get('CHEAT_COLORSCHEME'),
            config.get('CHEAT_COLORSCHEME'),
            'friendly',
        ]).strip().lower()

        # self.cheat_user_dir
        self.cheat_user_dir = self._select(
            map(os.path.expanduser,
                filter(None,
                    [os.environ.get('CHEAT_USER_DIR'),
                     os.environ.get('CHEAT_DEFAULT_DIR'),
                     os.environ.get('DEFAULT_CHEAT_DIR'),
                     # TODO: XDG home?
                     os.path.join('~', '.cheat')])))

        # self.cheat_editor
        self.cheat_editor = self._select([
            os.environ.get('CHEAT_EDITOR'),
            os.environ.get('EDITOR'),
            os.environ.get('VISUAL'),
            config.get('CHEAT_EDITOR'),
            'vi',
        ])

        # self.cheat_highlight
        self.cheat_highlight = self._select([
            os.environ.get('CHEAT_HIGHLIGHT'),
            config.get('CHEAT_HIGHLIGHT'),
            False,
        ])
        if isinstance(self.cheat_highlight, str):
            Utils.boolify(self.cheat_highlight)

        # self.cheat_path
        self.cheat_path = self._select([
            os.environ.get('CHEAT_PATH'),
            os.environ.get('CHEATPATH'),
            config.get('CHEAT_PATH'),
            '/usr/share/cheat',
        ])
Exemplo n.º 3
0
    def __init__(self):
        # compute the location of the config files
        config_file_path_global = self._select([
            os.environ.get('CHEAT_GLOBAL_CONF_PATH'),
            '/etc/cheat',
        ])
        config_file_path_local = self._select([
            os.environ.get('CHEAT_LOCAL_CONF_PATH'),
            os.path.expanduser('~/.config/cheat/cheat'),
        ])

        # attempt to read the global config file
        config = {}
        try:
            config.update(self._read_config_file(config_file_path_global))
        except Exception as e:
            Utils.warn('Error while parsing global configuration: '
                       + e.message)

        # attempt to read the local config file
        try:
            config.update(self._read_config_file(config_file_path_local))
        except Exception as e:
            Utils.warn('Error while parsing local configuration: ' + e.message)

        # With config files read, now begin to apply envvar overrides and
        # default values

        # self.cheat_colors
        self.cheat_colors = self._select([
            Utils.boolify(os.environ.get('CHEAT_COLORS')),
            Utils.boolify(os.environ.get('CHEATCOLORS')),
            Utils.boolify(config.get('CHEAT_COLORS')),
            True,
        ])

        # self.cheat_colorscheme
        self.cheat_colorscheme = self._select([
            os.environ.get('CHEAT_COLORSCHEME'),
            config.get('CHEAT_COLORSCHEME'),
            'light',
        ]).strip().lower()

        # self.cheat_user_dir
        self.cheat_user_dir = self._select(
            map(os.path.expanduser,
                filter(None,
                    [os.environ.get('CHEAT_USER_DIR'),
                     os.environ.get('CHEAT_DEFAULT_DIR'),
                     os.environ.get('DEFAULT_CHEAT_DIR'),
                     # TODO: XDG home?
                     os.path.join('~', '.cheat')])))

        # self.cheat_editor
        self.cheat_editor = self._select([
            os.environ.get('CHEAT_EDITOR'),
            os.environ.get('EDITOR'),
            os.environ.get('VISUAL'),
            config.get('CHEAT_EDITOR'),
            'vi',
        ])

        # self.cheat_highlight
        self.cheat_highlight = self._select([
            os.environ.get('CHEAT_HIGHLIGHT'),
            config.get('CHEAT_HIGHLIGHT'),
            False,
        ])
        if isinstance(self.cheat_highlight, str):
            Utils.boolify(self.cheat_highlight)

        # self.cheat_path
        self.cheat_path = self._select([
            os.environ.get('CHEAT_PATH'),
            os.environ.get('CHEATPATH'),
            config.get('CHEAT_PATH'),
            '/usr/share/cheat',
        ])