Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common_helper_files
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
common_helper_files
Commits
c0ec2f3c
Commit
c0ec2f3c
authored
8 years ago
by
Timm Behner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
helper function for configuration update from environment variables
parent
4658f92c
master
…
2.2
0.3.0
0.2.3
0.2.2
0.2
0.1.9
0.1.8
0.1.7
0.1.6
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletions
+30
-1
__init__.py
common_helper_files/__init__.py
+3
-1
config_functions.py
common_helper_files/config_functions.py
+27
-0
No files found.
common_helper_files/__init__.py
View file @
c0ec2f3c
...
...
@@ -2,6 +2,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'
,
...
...
@@ -14,5 +15,6 @@ __all__ = [
'write_binary_to_file'
,
'get_safe_name'
,
'delete_file'
,
'get_files_in_dir'
'get_files_in_dir'
,
'update_config_from_env'
,
]
This diff is collapsed.
Click to expand it.
common_helper_files/config_functions.py
0 → 100644
View file @
c0ec2f3c
"""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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment