How to use the todoman.configuration.ConfigurationException function in todoman

To help you get started, we’ve selected a few todoman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / todoman / tests / test_config.py View on Github external
def test_colour_validation_invalid(config):
    config.write("color = 'on_weekends_only'\n", 'a')
    with patch(
        'todoman.configuration.find_config',
        return_value=(str(config)),
    ), pytest.raises(ConfigurationException):
        load_config()
github pimutils / todoman / todoman / cli.py View on Github external
def init_config(self):
        try:
            self.config = load_config()
        except ConfigurationException as e:
            raise click.ClickException(e.args[0])
github pimutils / todoman / todoman / configuration.py View on Github external
def validate_date_format(fmt):
    if any(x in fmt for x in ('%H', '%M', '%S', '%X')):
        raise ConfigurationException(
            'Found time component in `date_format`, please use `time_format` '
            'for that.'
        )
    return fmt
github pimutils / todoman / todoman / configuration.py View on Github external
def load_config(custom_path=None):
    path = find_config(custom_path)
    specpath = os.path.join(os.path.dirname(__file__), 'confspec.ini')
    validator = Validator({
        'expand_path': expand_path,
        'cache_path': validate_cache_path,
        'date_format': validate_date_format,
        'time_format': validate_time_format,
    })

    config = ConfigObj(path, configspec=specpath, file_error=True)
    validation = config.validate(validator, preserve_errors=True)

    for section, key, error in flatten_errors(config, validation):
        if not error:
            raise ConfigurationException((
                '{} is missing from the {} section of the configuration ' +
                'file'
            ).format(key, section))
        if isinstance(error, VdtValueError):
            raise ConfigurationException(
                'Bad {} setting, {}'.format(key, error.args[0])
            )

    return config
github pimutils / todoman / todoman / configuration.py View on Github external
def find_config(custom_path=None):
    if custom_path:
        if not exists(custom_path):
            raise ConfigurationException(
                "Configuration file {} does not exist".format(custom_path)
            )
        return custom_path

    for d in xdg.BaseDirectory.xdg_config_dirs:
        path = join(d, 'todoman', 'todoman.conf')
        if exists(path):
            return path

    raise ConfigurationException("No configuration file found.\n\n")
github pimutils / todoman / todoman / configuration.py View on Github external
def find_config(custom_path=None):
    if custom_path:
        if not exists(custom_path):
            raise ConfigurationException(
                "Configuration file {} does not exist".format(custom_path)
            )
        return custom_path

    for d in xdg.BaseDirectory.xdg_config_dirs:
        path = join(d, 'todoman', 'todoman.conf')
        if exists(path):
            return path

    raise ConfigurationException("No configuration file found.\n\n")
github pimutils / todoman / todoman / configuration.py View on Github external
def validate_time_format(fmt):
    if any(x in fmt for x in ('%Y', '%y', '%m', '%d', '%x')):
        raise ConfigurationException(
            'Found date component in `time_format`, please use `date_format` '
            'for that.'
        )
    return fmt