import os, yaml

config = {
    'debug': False,
    'port': 5000,
    'store_path': '/var/storitch',
    'pool_size': 5,
    'logging': {
        'level': 'warning',
        'path': None,
        'max_size': 100 * 1000 * 1000,# ~ 95 mb
        'num_backups': 10,
    },
    'image_exts': [
        '.jpg', '.jpeg', '.png', '.tiff', '.tif', '.gif',
        '.bmp', '.bmp2', '.bmp3', '.dcm', '.dicom', '.webp',
    ],
}

def load(path=None):
    default_paths = [
        '~/storitch.yaml',
        './storitch.yaml',
        '../storitch.yaml',
        '/etc/storitch/storitch.yaml',
        '/etc/storitch.yaml',
    ]
    if not path:
        path = os.environ.get('STORITCH_CONFIG', None)
        if not path:
            for p in default_paths:
                p = os.path.expanduser(p)
                if os.path.isfile(p):
                    path = p
                    break
    if not path:
        raise Exception('No config file specified.')
    if not os.path.isfile(path):
        raise Exception('Config: "{}" could not be found.'.format(path))
    with open(path) as f:
        data = yaml.load(f, Loader=yaml.FullLoader)
    for key in data:
        if key in config:
            if isinstance(config[key], dict):
                config[key].update(data[key])
            else:
                config[key] = data[key]
[((29, 15, 29, 54), 'os.environ.get', 'os.environ.get', ({(29, 30, 29, 47): '"""STORITCH_CONFIG"""', (29, 49, 29, 53): 'None'}, {}), "('STORITCH_CONFIG', None)", False, 'import os, yaml\n'), ((38, 11, 38, 31), 'os.path.isfile', 'os.path.isfile', ({(38, 26, 38, 30): 'path'}, {}), '(path)', False, 'import os, yaml\n'), ((41, 15, 41, 51), 'yaml.load', 'yaml.load', (), '', False, 'import os, yaml\n'), ((32, 20, 32, 41), 'os.path.expanduser', 'os.path.expanduser', ({(32, 39, 32, 40): 'p'}, {}), '(p)', False, 'import os, yaml\n'), ((33, 19, 33, 36), 'os.path.isfile', 'os.path.isfile', ({(33, 34, 33, 35): 'p'}, {}), '(p)', False, 'import os, yaml\n')]