Merge pull request #16 from Konstantine00/config-dir-fix

Fix issue where config dir was not created by default
kivy_mainline_and_py3.8
goodboy 2018-03-06 02:49:19 -05:00 committed by GitHub
commit ebae64bfdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -1,20 +1,19 @@
""" """
Broker configuration mgmt. Broker configuration mgmt.
""" """
from os import path from os import path, makedirs
import configparser import configparser
import click import click
from ..log import get_logger from ..log import get_logger
log = get_logger('broker-config') log = get_logger('broker-config')
_broker_conf_path = path.join(click.get_app_dir('piker'), 'brokers.ini') _config_dir = click.get_app_dir('piker')
_broker_conf_path = path.join(_config_dir, 'brokers.ini')
def load() -> (configparser.ConfigParser, str): def load() -> (configparser.ConfigParser, str):
"""Load broker config. """Load broker config.
Create a ``broker.ini`` file if one dne.
""" """
config = configparser.ConfigParser() config = configparser.ConfigParser()
read = config.read(_broker_conf_path) read = config.read(_broker_conf_path)
@ -24,7 +23,13 @@ def load() -> (configparser.ConfigParser, str):
def write(config: configparser.ConfigParser) -> None: def write(config: configparser.ConfigParser) -> None:
"""Write broker config to disk. """Write broker config to disk.
Create a ``brokers.ini`` file if one does not exist.
""" """
if not path.isdir(_config_dir):
log.debug(f"Creating config dir {_config_dir}")
makedirs(_config_dir)
log.debug(f"Writing config file {_broker_conf_path}") log.debug(f"Writing config file {_broker_conf_path}")
with open(_broker_conf_path, 'w') as cf: with open(_broker_conf_path, 'w') as cf:
return config.write(cf) return config.write(cf)