How to use the confuse.Filename function in confuse

To help you get started, we’ve selected a few confuse 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 beetbox / confuse / test / test_valid.py View on Github external
def test_filename_relative_to_sibling_needs_siblings(self):
        config = _root({'foo': 'bar'})
        with self.assertRaises(confuse.ConfigTemplateError):
            config['foo'].get(confuse.Filename(relative_to='bar'))
github beetbox / confuse / test / test_valid.py View on Github external
def test_filename_with_file_source(self):
        source = confuse.ConfigSource({'foo': 'foo/bar'},
                                      filename='/baz/config.yaml')
        config = _root(source)
        config.config_dir = lambda: '/config/path'
        valid = config['foo'].get(confuse.Filename())
        self.assertEqual(valid, os.path.realpath('/config/path/foo/bar'))
github beetbox / confuse / test / test_valid.py View on Github external
def test_default_none(self):
        config = _root({})
        valid = config['foo'].get(confuse.Filename(None))
        self.assertEqual(valid, None)
github beetbox / confuse / test / test_valid.py View on Github external
def test_missing_required_value(self):
        config = _root({})
        with self.assertRaises(confuse.NotFoundError):
            config['foo'].get(confuse.Filename())
github beetbox / confuse / test / test_valid.py View on Github external
def test_filename_relative_to_sibling(self):
        config = _root({'foo': '/', 'bar': 'baz'})
        valid = config.get({
            'foo': confuse.Filename(),
            'bar': confuse.Filename(relative_to='foo')
        })
        self.assertEqual(valid.foo, os.path.realpath('/'))
        self.assertEqual(valid.bar, os.path.realpath('/baz'))
github beetbox / confuse / test / test_valid.py View on Github external
def test_filename_relative_to_sibling(self):
        config = _root({'foo': '/', 'bar': 'baz'})
        valid = config.get({
            'foo': confuse.Filename(),
            'bar': confuse.Filename(relative_to='foo')
        })
        self.assertEqual(valid.foo, os.path.realpath('/'))
        self.assertEqual(valid.bar, os.path.realpath('/baz'))
github beetbox / confuse / test / test_valid.py View on Github external
def test_filename_relative_to_sibling_with_recursion(self):
        config = _root({'foo': '/', 'bar': 'r', 'baz': 'z'})
        with self.assertRaises(confuse.ConfigTemplateError):
            config.get({
                'foo': confuse.Filename(relative_to='bar'),
                'bar': confuse.Filename(relative_to='baz'),
                'baz': confuse.Filename(relative_to='foo')
            })
github beetbox / beets / beetsplug / discogs.py View on Github external
def _tokenfile(self):
        """Get the path to the JSON file for storing the OAuth token.
        """
        return self.config['tokenfile'].get(confuse.Filename(in_app_dir=True))
github beetbox / beets / beetsplug / beatport.py View on Github external
def _tokenfile(self):
        """Get the path to the JSON file for storing the OAuth token.
        """
        return self.config['tokenfile'].get(confuse.Filename(in_app_dir=True))
github beetbox / confuse / example / __init__.py View on Github external
"""An example application using Confuse for configuration."""
from __future__ import division, absolute_import, print_function
import confuse
import argparse


template = {
    'library': confuse.Filename(),
    'import_write': confuse.OneOf([bool, 'ask', 'skip']),
    'ignore': confuse.StrSeq(),
    'plugins': list,

    'paths': {
        'directory': confuse.Filename(),
        'default': confuse.Filename(relative_to='directory'),
    }
}

config = confuse.LazyConfig('ConfuseExample', __name__)


def main():
    parser = argparse.ArgumentParser(description='example Confuse program')
    parser.add_argument('--library', '-l', dest='library', metavar='LIBPATH',
                        help='library database file')
    parser.add_argument('--directory', '-d', dest='paths.directory',
                        metavar='DIRECTORY',
                        help='destination music directory')
    parser.add_argument('--verbose', '-v', dest='verbose', action='store_true',
                        help='print debugging messages')