From 255f7df0df82206f9fcc26a707b1f7a86d146cb6 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 14 May 2023 18:22:03 +0200 Subject: Add support for yaml configuration file Signed-off-by: Olivier Gayot --- monitor_menu/__main__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/monitor_menu/__main__.py b/monitor_menu/__main__.py index e42c440..fce1a65 100644 --- a/monitor_menu/__main__.py +++ b/monitor_menu/__main__.py @@ -8,6 +8,7 @@ import logging from os.path import expanduser import subprocess from typing import Any +import yaml import dialog @@ -161,9 +162,13 @@ def main(): args = parser.parse_args() logging.basicConfig(level=args.log_level.numerical_level) - config_file = '~/.config/monitor-profiles.json' - with open(expanduser(config_file)) as fh: - data = json.load(fh) + try: + with open(expanduser("~/.config/monitor-profiles.yaml")) as fh: + data = yaml.safe_load(fh) + except FileNotFoundError: + with open(expanduser("~/.config/monitor-profiles.json")) as fh: + data = json.load(fh) + profiles = [Profile.from_json_dict(item) for item in data] match args.command: -- cgit v1.2.3