"""Risotto command line configuration parser """ from os.path import isfile, expanduser, join from yaml import load, SafeLoader, YAMLError from .i18n import _ class Config: def __init__(self): config_file = join(expanduser("~"), '.cucchiaiata-config.yaml') if not isfile(config_file): print(_('Attention, there is no configuration file')) url = input(_('Address to Risotto server: ')) yaml_template = f'url: {url}' with open(config_file, 'w') as fh: fh.write(yaml_template) print(_('config file {} created').format(config_file)) with open(config_file, 'r') as stream: try: config = load(stream, Loader=SafeLoader) except YAMLError as err: raise Exception(_('Error when creating the config file {}').format(err)) self.url = config['url'] self.debug = config.get('debug', False) self.remote_url = f'http://{self.url}/api' self.token_file = join(expanduser("~"), '.zephir-client.jwt.token') self.indent = config.get('indent', 2) self.allow_insecure_https = config.get('allow_insecure_https', False) config = Config()