Use yaml for config file
This commit is contained in:
parent
48142a01dd
commit
6fd730c96b
|
@ -18,6 +18,7 @@ import ConfigParser as configparser
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
|
@ -35,12 +36,8 @@ class Config(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_config_file(file_path):
|
def read_config_file(file_path):
|
||||||
config = configparser.SafeConfigParser()
|
with open(file_path) as file_stream:
|
||||||
config.read([file_path])
|
return yaml.load(file_stream)
|
||||||
config_dict = {}
|
|
||||||
for section in config.sections():
|
|
||||||
config_dict.update(config.items(section))
|
|
||||||
return config_dict
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_arguments(cls, parser):
|
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.dirname(config_args.config_path)
|
||||||
config_dir_path = os.path.abspath(config_dir_path)
|
config_dir_path = os.path.abspath(config_dir_path)
|
||||||
cls.generate_config(args, config_dir_path)
|
cls.generate_config(args, config_dir_path)
|
||||||
config = configparser.SafeConfigParser()
|
config = {}
|
||||||
config.add_section(generate_section)
|
|
||||||
for key, value in vars(args).items():
|
for key, value in vars(args).items():
|
||||||
if (key not in set(["config_path", "generate_config"])
|
if (key not in set(["config_path", "generate_config"])
|
||||||
and value is not None):
|
and value is not None):
|
||||||
print key, "=", value
|
config[key] = value
|
||||||
config.set(generate_section, key, str(value))
|
|
||||||
with open(config_args.config_path, "w") as config_file:
|
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)
|
sys.exit(0)
|
||||||
|
|
||||||
return cls(args)
|
return cls(args)
|
||||||
|
|
Loading…
Reference in New Issue