From 6fd730c96b9c9675db4144de16c255b9a43d169e Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Mon, 1 Sep 2014 20:44:43 +0100 Subject: [PATCH] Use yaml for config file --- synapse/config/_base.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index 78197e4a75..08de6ee5ec 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -18,6 +18,7 @@ import ConfigParser as configparser import argparse import sys import os +import yaml class Config(object): @@ -35,12 +36,8 @@ class Config(object): @staticmethod def read_config_file(file_path): - config = configparser.SafeConfigParser() - config.read([file_path]) - config_dict = {} - for section in config.sections(): - config_dict.update(config.items(section)) - return config_dict + with open(file_path) as file_stream: + return yaml.load(file_stream) @classmethod def add_arguments(cls, parser): @@ -95,15 +92,13 @@ class Config(object): config_dir_path = os.path.dirname(config_args.config_path) config_dir_path = os.path.abspath(config_dir_path) cls.generate_config(args, config_dir_path) - config = configparser.SafeConfigParser() - config.add_section(generate_section) + config = {} for key, value in vars(args).items(): if (key not in set(["config_path", "generate_config"]) and value is not None): - print key, "=", value - config.set(generate_section, key, str(value)) + config[key] = value with open(config_args.config_path, "w") as config_file: - config.write(config_file) + yaml.dump(config, config_file, default_flow_style=False) sys.exit(0) return cls(args)