simplify config.load()
This commit is contained in:
@@ -43,9 +43,14 @@ def main():
|
|||||||
if args.configs_json:
|
if args.configs_json:
|
||||||
config.load(args.configs_json, strict=True)
|
config.load(args.configs_json, strict=True)
|
||||||
if args.configs_yaml:
|
if args.configs_yaml:
|
||||||
config.load(args.configs_yaml, strict=True, fmt="yaml")
|
import yaml
|
||||||
|
config.load(args.configs_yaml, strict=True, load=yaml.safe_load)
|
||||||
if args.configs_toml:
|
if args.configs_toml:
|
||||||
config.load(args.configs_toml, strict=True, fmt="toml")
|
try:
|
||||||
|
import tomllib as toml
|
||||||
|
except ImportError:
|
||||||
|
import toml
|
||||||
|
config.load(args.configs_toml, strict=True, load=toml.loads)
|
||||||
if args.filename:
|
if args.filename:
|
||||||
filename = args.filename
|
filename = args.filename
|
||||||
if filename == "/O":
|
if filename == "/O":
|
||||||
|
|||||||
@@ -49,29 +49,8 @@ if getattr(sys, "frozen", False):
|
|||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# public interface
|
# public interface
|
||||||
|
|
||||||
def load(files=None, strict=False, fmt="json"):
|
def load(files=None, strict=False, load=util.json_loads):
|
||||||
"""Load JSON configuration files"""
|
"""Load JSON configuration files"""
|
||||||
if fmt == "yaml":
|
|
||||||
try:
|
|
||||||
import yaml
|
|
||||||
load = yaml.safe_load
|
|
||||||
except ImportError:
|
|
||||||
log.error("Could not import 'yaml' module")
|
|
||||||
return
|
|
||||||
elif fmt == "toml":
|
|
||||||
try:
|
|
||||||
import tomllib
|
|
||||||
load = tomllib.loads
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
import toml
|
|
||||||
load = toml.loads
|
|
||||||
except ImportError:
|
|
||||||
log.error("Could not import 'toml' module")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
load = util.json_loads
|
|
||||||
|
|
||||||
for pathfmt in files or _default_configs:
|
for pathfmt in files or _default_configs:
|
||||||
path = util.expand_path(pathfmt)
|
path = util.expand_path(pathfmt)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user