"""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: ')) version = input(_('Risotto API\'s version (default: "v1"): ')) if not version: version = "v1" yaml_template = f"""url: {url} version: {version}""" 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.version = config['version'] self.debug = config.get('debug', False) self.remote_url = 'http://{}/api/{}'.format(self.url, self.version) 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()