Commit 515920e6 by Timm Behner

Merge branch 'config_helper'

parents cc7177f4 622d80b0
MIT License
Copyright (c) 2016 MASS Project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -4,6 +4,7 @@ from .file_functions import read_in_chunks, get_directory_for_filename, create_d
from .git_functions import get_version_string_from_git
from .hash_functions import md5sum
from .fail_safe_file_operations import get_binary_from_file, write_binary_to_file, get_safe_name, delete_file, get_files_in_dir
from .config_functions import update_config_from_env
__all__ = [
'get_directory_for_filename',
......@@ -16,5 +17,6 @@ __all__ = [
'write_binary_to_file',
'get_safe_name',
'delete_file',
'get_files_in_dir'
'get_files_in_dir',
'update_config_from_env',
]
"""Helper functions for configuration files.
"""
import os
import logging
log = logging.getLogger(__name__)
def update_config_from_env(config):
""" Update configuration fields in config from environment variables.
The environment variable names are expected to be of the form, that the
section name and the variable name are seperated by a dubble underscore,
e.g.
SECTION_NAME__VARIABLE_NAME
"""
for key, val in os.environ.items():
if '__' in key:
section, section_key = key.lower().split('__')
try:
config[section.capitalize()][section_key] = val
except KeyError:
log.error('No section {} or value {} found.'.format(section.capitalize(), section_key))
return config
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment