# Path: syncano_cli/base/options.py
# class ErrorOpt(OptionsBase):
#     OPTIONS = ['color']
# 
#     def __init__(self, color=ColorSchema.ERROR, **kwargs):
#         super(ErrorOpt, self).__init__(color=color, **kwargs)
# 
# class SpacedOpt(OptionsBase):
#     OPTIONS = ['space_top', 'space_bottom']
# 
#     def __init__(self, space_top=True, space_bottom=True, **kwargs):
#         super(SpacedOpt, self).__init__(space_top=space_top, space_bottom=space_bottom, **kwargs)
# 
# class TopSpacedOpt(OptionsBase):
#     OPTIONS = ['space_top']
# 
#     def __init__(self, space_top=True, **kwargs):
#         super(TopSpacedOpt, self).__init__(space_top=space_top, **kwargs)
# 
# Path: syncano_cli/config.py
# ACCOUNT_CONFIG = ConfigParser()
# 
# Path: syncano_cli/init/helpers.py
# def random_instance_name():
#     return '{adj}-{noun}-{rnd}'.format(
#         adj=random.choice(INSTANCE_NAME_ADJECTIVES),
#         noun=random.choice(INSTANCE_NAME_NOUNS),
#         rnd=random.randint(1000, 9999),
#     )


import sys
import syncano
from syncano.exceptions import SyncanoRequestError
from syncano_cli.base.options import ErrorOpt, SpacedOpt, TopSpacedOpt
from syncano_cli.config import ACCOUNT_CONFIG
from syncano_cli.init.helpers import random_instance_name
                from syncano_cli.account.command import AccountCommands
        from syncano_cli.instance.command import InstanceCommands
                account_command = AccountCommands(config_path=config_path)
                account_command.register(email=email, password=password)
                self.formatter.write('Account created for email: {}'.format(email),
                                     TopSpacedOpt())
            elif 'password' in exc.message:
                self.formatter.write('Invalid login: you have provided wrong password.', ErrorOpt())
                sys.exit(1)

    def create_instance(self, instance_commands):
        instance_name = random_instance_name()
        return instance_commands.create(instance_name=instance_name)

    def do_login_or_register(self, email, password, config_path):
        try:
            self.do_login(email, password, config_path)
        except SyncanoRequestError as exc:
            self.do_register(exc, email, password, config_path)

        instance_commands = InstanceCommands(self.config_path)
        instances = [i for i in instance_commands.api_list()]
        instance_name = instances[0].name if instances else self.create_instance(instance_commands).name
        self.set_instance_as_default(config_path, instance_name, instance_commands)

    def set_instance_as_default(self, config_path, instance_name, instance_commands):
        self.formatter.write('Instance `{}` set as default.'.format(instance_name), TopSpacedOpt())
        instance_commands.set_default(instance_name=instance_name, config_path=config_path)

    def validate_password(self, password, repeat_password):
        while password != repeat_password:
            self.formatter.write('Password and repeat password are not the same. Please correct:', ErrorOpt(),

# Path: syncano_cli/base/options.py
# class ErrorOpt(OptionsBase):
#     OPTIONS = ['color']
# 
#     def __init__(self, color=ColorSchema.ERROR, **kwargs):
#         super(ErrorOpt, self).__init__(color=color, **kwargs)
# 
# class SpacedOpt(OptionsBase):
#     OPTIONS = ['space_top', 'space_bottom']
# 
#     def __init__(self, space_top=True, space_bottom=True, **kwargs):
#         super(SpacedOpt, self).__init__(space_top=space_top, space_bottom=space_bottom, **kwargs)
# 
# class TopSpacedOpt(OptionsBase):
#     OPTIONS = ['space_top']
# 
#     def __init__(self, space_top=True, **kwargs):
#         super(TopSpacedOpt, self).__init__(space_top=space_top, **kwargs)
# 
# Path: syncano_cli/config.py
# ACCOUNT_CONFIG = ConfigParser()
# 
# Path: syncano_cli/init/helpers.py
# def random_instance_name():
#     return '{adj}-{noun}-{rnd}'.format(
#         adj=random.choice(INSTANCE_NAME_ADJECTIVES),
#         noun=random.choice(INSTANCE_NAME_NOUNS),
#         rnd=random.randint(1000, 9999),
#     )


# Path: syncano_cli/base/mixins.py
import sys
import syncano
from syncano.exceptions import SyncanoRequestError
from syncano_cli.base.options import ErrorOpt, SpacedOpt, TopSpacedOpt
from syncano_cli.config import ACCOUNT_CONFIG
from syncano_cli.init.helpers import random_instance_name
                from syncano_cli.account.command import AccountCommands
        from syncano_cli.instance.command import InstanceCommands

                account_command = AccountCommands(config_path=config_path)
                account_command.register(email=email, password=password)
                self.formatter.write('Account created for email: {}'.format(email),
                                     TopSpacedOpt())
            elif 'password' in exc.message:
                self.formatter.write('Invalid login: you have provided wrong password.', ErrorOpt())
                sys.exit(1)

    def create_instance(self, instance_commands):
        instance_name = random_instance_name()
        return instance_commands.create(instance_name=instance_name)

    def do_login_or_register(self, email, password, config_path):
        try:
            self.do_login(email, password, config_path)
        except SyncanoRequestError as exc:
            self.do_register(exc, email, password, config_path)

        instance_commands = InstanceCommands(self.config_path)
        instances = [i for i in instance_commands.api_list()]
        instance_name = instances[0].name if instances else self.create_instance(instance_commands).name
        self.set_instance_as_default(config_path, instance_name, instance_commands)

    def set_instance_as_default(self, config_path, instance_name, instance_commands):
        self.formatter.write('Instance `{}` set as default.'.format(instance_name), TopSpacedOpt())
        instance_commands.set_default(instance_name=instance_name, config_path=config_path)

    def validate_password(self, password, repeat_password):
        while password != repeat_password:
            self.formatter.write('Password and repeat password are not the same. Please correct:', ErrorOpt(),

                                 SpacedOpt())