Merge pull request #6096 from edx/jarv/config-refactor-wip
Jarv/config refactor wip
This commit is contained in:
26
common/djangoapps/util/config_parse.py
Normal file
26
common/djangoapps/util/config_parse.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
Helper functions for configuration parsing
|
||||
"""
|
||||
import collections
|
||||
|
||||
|
||||
def convert_tokens(tokens):
|
||||
"""
|
||||
This function is called on the token
|
||||
dictionary that is imported from a yaml file.
|
||||
It returns a new dictionary where
|
||||
all strings containing 'None' are converted
|
||||
to a literal None due to a bug in Ansible
|
||||
"""
|
||||
|
||||
if tokens == 'None':
|
||||
return None
|
||||
elif isinstance(tokens, basestring) or (not isinstance(tokens, collections.Iterable)):
|
||||
return tokens
|
||||
elif isinstance(tokens, dict):
|
||||
return {
|
||||
convert_tokens(k): convert_tokens(v)
|
||||
for k, v in tokens.items()
|
||||
}
|
||||
else:
|
||||
return [convert_tokens(v) for v in tokens]
|
||||
Reference in New Issue
Block a user