# Path: syncano_cli/base/formatters.py
# class Formatter(object):
# 
#     indent = '    '
#     not_set = '-- not set --'
# 
#     def write(self, single_line, *options):
#         option = self.get_options(options)
#         styles = option.map_click()
#         single_line = self._indent(single_line, option)
#         self._write(single_line, option, **styles)
# 
#     def write_lines(self, lines, *options):
#         lines = lines.splitlines() if isinstance(lines, six.string_types) else lines
#         for line in lines:
#             self.write(line, *options)
# 
#     def write_block(self, lines, *options):
#         self.write_lines(lines, *options)
#         self.separator()
# 
#     @classmethod
#     def empty_line(cls):
#         click.echo()
# 
#     def separator(self, size=70, indent=1):
#         self.write(size * '-', DefaultOpt(indent=indent), WarningOpt(), BottomSpacedOpt())
# 
#     def display_config(self, config):
#         for name, value in six.iteritems(config):
#             self.write('{}{:20} {}'.format(
#                 self.indent,
#                 click.style(name, fg=ColorSchema.PROMPT),
#                 click.style(value, fg=ColorSchema.INFO)
#             ))
#         if not config:
#             self.write('No config specified yet.', DefaultOpt(indent=2))
#         self.empty_line()
# 
#     def get_options(self, options):
#         option_list = list(options) or []
#         option_list.insert(0, DefaultOpt())
#         return OptionsBase.build_options(option_list)
# 
#     def format_object(self, dictionary, indent=1, skip_fields=None):
#         skip_fields = skip_fields or []
#         indent += 1
#         for key, value in six.iteritems(dictionary):
#             if isinstance(value, dict):
#                 self.write('{}:'.format(click.style(key, fg=ColorSchema.PROMPT)), DefaultOpt(indent=indent))
#                 self.format_object(value, indent=indent, skip_fields=skip_fields)
#             elif isinstance(value, list):
#                 self.format_list(value, key=key, indent=indent)
#             else:
#                 if key in skip_fields:
#                     continue
#                 self.write('{}: {}'.format(
#                     click.style(key, fg=ColorSchema.PROMPT),
#                     click.style(value, fg=ColorSchema.INFO)
#                 ), DefaultOpt(indent=indent))
# 
#     def format_list(self, data_list, key=None, indent=2, skip_fields=None):
#         skip_fields = skip_fields or []
#         for el in data_list:
#             if isinstance(el, dict):
#                 self.format_object(el, indent=indent, skip_fields=skip_fields)
#             else:
#                 if key:
#                     self.write('{}: {}'.format(
#                         click.style(key, fg=ColorSchema.PROMPT),
#                         click.style(el, fg=ColorSchema.INFO)
#                     ), DefaultOpt(indent=indent))
#                 else:
#                     self.write('{}'.format(el), DefaultOpt(indent=indent))
#             self.empty_line()
# 
#     def _write(self, line, options, **styles):
#         if options.space_top:
#             self.empty_line()
# 
#         click.echo(click.style(line, **styles))
# 
#         if options.space_bottom:
#             self.empty_line()
# 
#     def _indent(self, line, options):
#         return '{}{}'.format(self.indent * options.indent, line)
# 
# Path: syncano_cli/base/options.py
# class ColorSchema(object):
#     INFO = 'green'
#     PROMPT = 'cyan'
#     WARNING = 'yellow'
#     ERROR = 'red'
# 
# Path: syncano_cli/base/prompter.py
# class Prompter(object):
#     indent = '    '
# 
#     def prompt(self, text, color=None, **kwargs):
#         styles_kwargs = {'fg': color or ColorSchema.PROMPT}
#         return click.prompt(click.style("{}{}".format(self.indent, text), **styles_kwargs), **kwargs)
# 
#     def confirm(self, text, color=None, **kwargs):
#         styles_kwargs = {'fg': color or ColorSchema.PROMPT}
#         return click.confirm(click.style("{}{}".format(self.indent, text), **styles_kwargs), **kwargs)
# 
# Path: syncano_cli/config.py
# ACCOUNT_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.syncano')
# 
# Path: syncano_cli/parse_to_syncano/config.py
# CONFIG_VARIABLES_NAMES = ['PARSE_MASTER_KEY', 'PARSE_APPLICATION_ID',
#                           'SYNCANO_ADMIN_API_KEY', 'SYNCANO_INSTANCE_NAME']


import click
from syncano_cli.base.formatters import Formatter
from syncano_cli.base.options import ColorSchema
from syncano_cli.base.prompter import Prompter
from syncano_cli.config import ACCOUNT_CONFIG_PATH
from syncano_cli.parse_to_syncano.config import CONFIG_VARIABLES_NAMES
# -*- coding: utf-8 -*-


def force_config_value(config, config_var_name, section='P2S'):
    prompter = Prompter()
    config_var = prompter.prompt('{}'.format(config_var_name))
    if not config.has_section(section):
        config.add_section(section)
    config.set(section, config_var_name, config_var)


def check_config_value(config, config_var_name, silent, section='P2S'):
    formatter = Formatter()
    if not config.has_option(section, config_var_name):
        force_config_value(config, config_var_name)
    else:
        if not silent:
            formatter.write("{config_var_name}: {config_var}".format(
                config_var_name=click.style(config_var_name, fg=ColorSchema.PROMPT),
                config_var=click.style(config.get(section, config_var_name), fg=ColorSchema.INFO)
            ))


def write_config_to_file(config):
    with open(ACCOUNT_CONFIG_PATH, 'wt') as config_file:
        config.write(config_file)


def check_configuration(config, silent=False):

# Path: syncano_cli/base/formatters.py
# class Formatter(object):
# 
#     indent = '    '
#     not_set = '-- not set --'
# 
#     def write(self, single_line, *options):
#         option = self.get_options(options)
#         styles = option.map_click()
#         single_line = self._indent(single_line, option)
#         self._write(single_line, option, **styles)
# 
#     def write_lines(self, lines, *options):
#         lines = lines.splitlines() if isinstance(lines, six.string_types) else lines
#         for line in lines:
#             self.write(line, *options)
# 
#     def write_block(self, lines, *options):
#         self.write_lines(lines, *options)
#         self.separator()
# 
#     @classmethod
#     def empty_line(cls):
#         click.echo()
# 
#     def separator(self, size=70, indent=1):
#         self.write(size * '-', DefaultOpt(indent=indent), WarningOpt(), BottomSpacedOpt())
# 
#     def display_config(self, config):
#         for name, value in six.iteritems(config):
#             self.write('{}{:20} {}'.format(
#                 self.indent,
#                 click.style(name, fg=ColorSchema.PROMPT),
#                 click.style(value, fg=ColorSchema.INFO)
#             ))
#         if not config:
#             self.write('No config specified yet.', DefaultOpt(indent=2))
#         self.empty_line()
# 
#     def get_options(self, options):
#         option_list = list(options) or []
#         option_list.insert(0, DefaultOpt())
#         return OptionsBase.build_options(option_list)
# 
#     def format_object(self, dictionary, indent=1, skip_fields=None):
#         skip_fields = skip_fields or []
#         indent += 1
#         for key, value in six.iteritems(dictionary):
#             if isinstance(value, dict):
#                 self.write('{}:'.format(click.style(key, fg=ColorSchema.PROMPT)), DefaultOpt(indent=indent))
#                 self.format_object(value, indent=indent, skip_fields=skip_fields)
#             elif isinstance(value, list):
#                 self.format_list(value, key=key, indent=indent)
#             else:
#                 if key in skip_fields:
#                     continue
#                 self.write('{}: {}'.format(
#                     click.style(key, fg=ColorSchema.PROMPT),
#                     click.style(value, fg=ColorSchema.INFO)
#                 ), DefaultOpt(indent=indent))
# 
#     def format_list(self, data_list, key=None, indent=2, skip_fields=None):
#         skip_fields = skip_fields or []
#         for el in data_list:
#             if isinstance(el, dict):
#                 self.format_object(el, indent=indent, skip_fields=skip_fields)
#             else:
#                 if key:
#                     self.write('{}: {}'.format(
#                         click.style(key, fg=ColorSchema.PROMPT),
#                         click.style(el, fg=ColorSchema.INFO)
#                     ), DefaultOpt(indent=indent))
#                 else:
#                     self.write('{}'.format(el), DefaultOpt(indent=indent))
#             self.empty_line()
# 
#     def _write(self, line, options, **styles):
#         if options.space_top:
#             self.empty_line()
# 
#         click.echo(click.style(line, **styles))
# 
#         if options.space_bottom:
#             self.empty_line()
# 
#     def _indent(self, line, options):
#         return '{}{}'.format(self.indent * options.indent, line)
# 
# Path: syncano_cli/base/options.py
# class ColorSchema(object):
#     INFO = 'green'
#     PROMPT = 'cyan'
#     WARNING = 'yellow'
#     ERROR = 'red'
# 
# Path: syncano_cli/base/prompter.py
# class Prompter(object):
#     indent = '    '
# 
#     def prompt(self, text, color=None, **kwargs):
#         styles_kwargs = {'fg': color or ColorSchema.PROMPT}
#         return click.prompt(click.style("{}{}".format(self.indent, text), **styles_kwargs), **kwargs)
# 
#     def confirm(self, text, color=None, **kwargs):
#         styles_kwargs = {'fg': color or ColorSchema.PROMPT}
#         return click.confirm(click.style("{}{}".format(self.indent, text), **styles_kwargs), **kwargs)
# 
# Path: syncano_cli/config.py
# ACCOUNT_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.syncano')
# 
# Path: syncano_cli/parse_to_syncano/config.py
# CONFIG_VARIABLES_NAMES = ['PARSE_MASTER_KEY', 'PARSE_APPLICATION_ID',
#                           'SYNCANO_ADMIN_API_KEY', 'SYNCANO_INSTANCE_NAME']


# Path: syncano_cli/parse_to_syncano/moses.py
import click
from syncano_cli.base.formatters import Formatter
from syncano_cli.base.options import ColorSchema
from syncano_cli.base.prompter import Prompter
from syncano_cli.config import ACCOUNT_CONFIG_PATH
from syncano_cli.parse_to_syncano.config import CONFIG_VARIABLES_NAMES

# -*- coding: utf-8 -*-


def force_config_value(config, config_var_name, section='P2S'):
    prompter = Prompter()
    config_var = prompter.prompt('{}'.format(config_var_name))
    if not config.has_section(section):
        config.add_section(section)
    config.set(section, config_var_name, config_var)


def check_config_value(config, config_var_name, silent, section='P2S'):
    formatter = Formatter()
    if not config.has_option(section, config_var_name):
        force_config_value(config, config_var_name)
    else:
        if not silent:
            formatter.write("{config_var_name}: {config_var}".format(
                config_var_name=click.style(config_var_name, fg=ColorSchema.PROMPT),
                config_var=click.style(config.get(section, config_var_name), fg=ColorSchema.INFO)
            ))


def write_config_to_file(config):
    with open(ACCOUNT_CONFIG_PATH, 'wt') as config_file:
        config.write(config_file)


def check_configuration(config, silent=False):

    for config_var_name in CONFIG_VARIABLES_NAMES: