diff options
author | nico <nico@magicbroccoli.de> | 2020-03-06 11:58:01 +0100 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2020-03-06 12:46:48 +0100 |
commit | d82744488951d55d5e5a95b41136a5719d8c5534 (patch) | |
tree | f75e0c3bb45d4e172e1a4128fc34f3954e7ec46f /config.py | |
parent | c8d88a537d3afdc10618e92ea63dc353a3250058 (diff) |
yaml config
+ implement yaml config file parsing
* update default config file
* update global config file from .conf to .yml ( debatable )
Signed-off-by: nico <nico@magicbroccoli.de>
Diffstat (limited to 'config.py')
-rw-r--r-- | config.py | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -1,20 +1,23 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import json import sys from os import environ from pathlib import Path +from ruamel.yaml import YAML +from ruamel.yaml.parser import ParserError +from ruamel.yaml.scanner import ScannerError + class Config: def __init__(self): # class variables self.content = None - self.conf_file = Path('/etc/ejabberd-metrics.conf') + self.conf_file = Path('/etc/ejabberd-metrics.yml') # dev config overwrite if environ.get('ejabberd_metrics_dev'): - self.conf_file = Path('config.json') + self.conf_file = Path('config.yml') # read config file self._read() @@ -23,13 +26,13 @@ class Config: """init the config object with this method""" self._check() - # open and load json content from config + # open file as an iostream with open(self.conf_file, 'r', encoding='utf-8') as f: try: - self.content = json.load(f) + self.content = YAML(typ='safe').load(f) # catch json decoding errors - except json.JSONDecodeError as err: + except (ParserError, ScannerError) as err: print(err, file=sys.stderr) exit(1) |