import os
LEVELS = {'0': {'prefix': '/uploads/', 'store': 'data-sd2e-community'},
'1': {'prefix': '/products/', 'store': 'data-sd2e-community'},
'2': {'prefix': '/products/', 'store': 'data-sd2e-community'},
'Reference': {'prefix': '/reference/', 'store': 'data-sd2e-community'}}
[docs]def prefix_for_level(level):
try:
return LEVELS.get(str(level)).get('prefix')
except KeyError:
if os.environ.get('STORAGE_SYSTEM_PREFIX_OVERRIDE') is not None:
return '0'
else:
raise KeyError('Processing level {} is not known'.format(level))
[docs]def store_for_level(level):
try:
return LEVELS.get(str(level)).get('store')
except KeyError:
raise KeyError('Processing level {} is not known'.format(level))
[docs]def level_for_prefix(prefix):
for lev, props in LEVELS.items():
if prefix == props['prefix']:
return lev
if os.environ.get('STORAGE_SYSTEM_PREFIX_OVERRIDE') is not None:
return '0'
else:
raise KeyError('Prefix {} does not map to a processing level'.format(prefix))
[docs]def level_for_filepath(filepath):
if not filepath.startswith('/'):
filepath = '/' + filepath
for lev, props in LEVELS.items():
if filepath.startswith(props['prefix']):
return lev
if os.environ.get('STORAGE_SYSTEM_PREFIX_OVERRIDE') is not None:
return '0'
else:
return 'User'
# raise KeyError('Path does not map to a known prefix')