Skip to content

Commit

Permalink
Use yaml to read network config
Browse files Browse the repository at this point in the history
Avoids converting strings to/from unicode
  • Loading branch information
tomdee committed Mar 23, 2016
1 parent 7ab3450 commit 24a2ee1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion calico.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import print_function
import logging
import json
import yaml
import os
import sys

Expand Down Expand Up @@ -654,8 +655,12 @@ def main():
"""
# Read the network config file from stdin. Replace newline characters
# so that we can properly load it as json.
# The python json library loads strings as as the unicode type. This causes
# problems when loading values into os.environ.
# Rather than try to encode them as strings, just use the yaml library.
# For more details see http://stackoverflow.com/questions/956867/how-to-get-string-objects-instead-of-unicode-ones-from-json-in-python
config_raw = ''.join(sys.stdin.readlines()).replace('\n', '')
network_config = json.loads(config_raw)
network_config = yaml.safe_load(config_raw)

# Get the log level from the config file, default to INFO.
log_level = network_config.get(LOG_LEVEL_KEY, "INFO").upper()
Expand Down

0 comments on commit 24a2ee1

Please sign in to comment.