from functools import reduce
import yaml
+from six.moves import configparser
from oslo_utils import importutils
from oslo_serialization import jsonutils
def read_json_from_file(path):
with open(path, 'r') as f:
- return jsonutils.load(f)
+ j = f.read()
+ # don't use jsonutils.load() it conflicts with already decoded input
+ return jsonutils.loads(j)
def write_json_to_file(path, data, mode='w'):
def write_file(path, data, mode='w'):
with open(path, mode) as f:
f.write(data)
+
+
+def parse_ini_file(path):
+ parser = configparser.ConfigParser()
+ parser.read(path)
+
+ try:
+ default = {k: v for k, v in parser.items('DEFAULT')}
+ except configparser.NoSectionError:
+ default = {}
+
+ config = dict(DEFAULT=default,
+ **{s: {k: v for k, v in parser.items(
+ s)} for s in parser.sections()})
+
+ return config