diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2023-05-14 18:22:03 +0200 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2023-05-14 18:22:03 +0200 |
commit | 255f7df0df82206f9fcc26a707b1f7a86d146cb6 (patch) | |
tree | 2483e9c2d738dabd8015055b62a18c4834774509 /monitor_menu | |
parent | 3d2f56b15366adfc139419a6289e4be6365e87c8 (diff) |
Add support for yaml configuration file
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'monitor_menu')
-rw-r--r-- | monitor_menu/__main__.py | 11 |
1 files 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: |