sapling/eden/cli/configutil.py
Eamonn Kent 59deefe6ab Eden should support toml configuration files
Summary:
Eden should load its configuration from toml files. This change includes:

- ConfigParser is the class that parses and provides access to the  configuration. We load the configuration from toml files and pass to ConfigParser in order to preserve existing behavior.

- The toml configuration format differs from the Config format. Thus, we use toml.load() and toml.dump() to load/save toml format configuration.

- Tests
  - configuration is properly loaded from a group of config files
  - toml configuration (if present) takes precedence
  - missing configuration files (/home/user/.edenrc) are ignored
  - invalid configuration files are fatal
  - update of configuration works (adding repo)
  - toml parsing handles over-rides of properties in the same way as cfg files

Deployment Strategy:
- This code determines whether to use toml configuration based on the presence
  of atleast 1 '.toml' file in the etc-eden-dir/config.d.

Reviewed By: chadaustin

Differential Revision: D9023232

fbshipit-source-id: 6734a9d91eca92b05872a758c764546451dd2d51
2018-08-03 17:06:41 -07:00

23 lines
850 B
Python

#!/usr/bin/env python3
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
import collections
import configparser
# Convert the passed ConfigParser to a raw dictionary (without interpolation)
# Useful for updating configuration files in different formats.
def config_to_raw_dict(config: configparser.ConfigParser) -> collections.OrderedDict:
rslt = collections.OrderedDict() # type: collections.OrderedDict
for section in config.sections():
rslt[section] = collections.OrderedDict()
for k, v in config.items(section, raw=True):
rslt[section][k] = v
return rslt