From 15fc66f0a9cef8db7a47504cace95277838f00a0 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 23 Aug 2021 14:42:26 -0400 Subject: [PATCH] Add config account loader --- piker/brokers/config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/piker/brokers/config.py b/piker/brokers/config.py index 9a8f6360..3805f9c8 100644 --- a/piker/brokers/config.py +++ b/piker/brokers/config.py @@ -20,6 +20,7 @@ Broker configuration mgmt. import os from os.path import dirname import shutil +from typing import Optional import toml import click @@ -101,3 +102,20 @@ def write( log.debug(f"Writing config file {path}") with open(path, 'w') as cf: return toml.dump(config, cf) + + +def load_accounts() -> dict[str, Optional[str]]: + + # our default paper engine entry + accounts: dict[str, Optional[str]] = {'paper': None} + + conf, path = load() + section = conf.get('accounts') + if section is None: + log.warning('No accounts config found?') + + for brokername, account_labels in section.items(): + for name, value in account_labels.items(): + accounts[f'{brokername}.{name}'] = value + + return accounts