# 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
# -*- coding: utf-8 -*-



class RegisterMixin(object):

    def do_login(self, email, password, config_path):
        connection = syncano.connect().connection()
        api_key = connection.authenticate(email=email, password=password)
        ACCOUNT_CONFIG.set('DEFAULT', 'key', api_key)
        with open(config_path, 'wt') as fp:
            ACCOUNT_CONFIG.write(fp)

    def do_register(self, exc, email, password, config_path):
        if exc.status_code == 401:
            if 'email' in exc.message:
                account_command = AccountCommands(config_path=config_path)
                account_command.register(email=email, password=password)
                self.formatter.write('Account created for email: {}'.format(email),

# 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

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



class RegisterMixin(object):

    def do_login(self, email, password, config_path):
        connection = syncano.connect().connection()
        api_key = connection.authenticate(email=email, password=password)
        ACCOUNT_CONFIG.set('DEFAULT', 'key', api_key)
        with open(config_path, 'wt') as fp:
            ACCOUNT_CONFIG.write(fp)

    def do_register(self, exc, email, password, config_path):
        if exc.status_code == 401:
            if 'email' in exc.message:
                account_command = AccountCommands(config_path=config_path)
                account_command.register(email=email, password=password)
                self.formatter.write('Account created for email: {}'.format(email),

                                     TopSpacedOpt())