Add config for saving access creds between runs

kivy_mainline_and_py3.8
Tyler Goodlet 2018-01-22 21:26:38 -05:00
parent 9745e16cf2
commit e312fb6525
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
"""
Broker configuration mgmt.
"""
from os import path
import configparser
from ..log import get_logger
log = get_logger('broker-config')
_broker_conf_path = path.join(path.dirname(__file__), 'brokers.ini')
def load() -> (configparser.ConfigParser, str):
"""Load broker config.
Create a ``broker.ini`` file if one dne.
"""
config = configparser.ConfigParser()
# mode = 'r' if path.exists(_broker_conf_path) else 'a'
read = config.read(_broker_conf_path)
log.debug(f"Read config file {_broker_conf_path}")
return config, _broker_conf_path
def write(config: configparser.ConfigParser) -> None:
"""Write broker config to disk.
"""
log.debug(f"Writing config file {_broker_conf_path}")
with open(_broker_conf_path, 'w') as cf:
return config.write(cf)