# Path: py_mina/config.py
# def fetch(key, default_value=None):
#     """
#     Gets and ensures config setting or returns `default_value` if provided
#     """
# 
#     if key in config.keys():
#         return config.get(key)
#     else:
#         if default_value != None:
#             return default_value
#         else:
#             raise Exception('"%s" is not defined' % key)
# 
# def ensure(key):
#     """
#     Ensures presence of config setting. Prevents from running unnecessary commands,
#     before discovering, that config setting is not set
#     """
# 
#     if not key in config.keys():
#         raise Exception('"%s" must be defined' % key)
# 
# def check_config(required_settings=[]):
#     """
#     Ensures required settings in cofig
#     """
# 
#     try:
#         for setting in required_settings:
#             ensure(setting)
#     except EnsureConfigError:
#         msg = 'Bad config!\nRequired settings: {0}\nCurrent config: {1}'
# 
#         raise Exception(msg.format(required_settings, config))  


import timeit
import os
import re
from py_mina.config import fetch, ensure, check_config
from fabric.api import run, sudo, settings, env, cd, hide
from py_mina.echo import *

        # Exit if no host
        if repo_host == '': 
            return

        # Parse port
        repo_port_match = re.search(r':([0-9]+)', maybe_repository)
        repo_port = repo_port_match.group(1) if bool(repo_port_match) else 22

        echo_subtask('Adding repository to known hosts')

        add_to_known_hosts(repo_host, repo_port)


def add_host_to_known_hosts():
    """
    Adds current host to the known hosts

    `fabric3` library sets to `env.host_string` current host where task is executed
    """

    ensure('hosts')

    echo_subtask('Adding current host to known hosts')

    add_to_known_hosts(env.host_string, env.port)


def add_to_known_hosts(host, port):
    cmd = '''

# Path: py_mina/config.py
# def fetch(key, default_value=None):
#     """
#     Gets and ensures config setting or returns `default_value` if provided
#     """
# 
#     if key in config.keys():
#         return config.get(key)
#     else:
#         if default_value != None:
#             return default_value
#         else:
#             raise Exception('"%s" is not defined' % key)
# 
# def ensure(key):
#     """
#     Ensures presence of config setting. Prevents from running unnecessary commands,
#     before discovering, that config setting is not set
#     """
# 
#     if not key in config.keys():
#         raise Exception('"%s" must be defined' % key)
# 
# def check_config(required_settings=[]):
#     """
#     Ensures required settings in cofig
#     """
# 
#     try:
#         for setting in required_settings:
#             ensure(setting)
#     except EnsureConfigError:
#         msg = 'Bad config!\nRequired settings: {0}\nCurrent config: {1}'
# 
#         raise Exception(msg.format(required_settings, config))  


# Path: py_mina/subtasks/setup.py
import timeit
import os
import re
from py_mina.config import fetch, ensure, check_config
from fabric.api import run, sudo, settings, env, cd, hide
from py_mina.echo import *


        # Exit if no host
        if repo_host == '': 
            return

        # Parse port
        repo_port_match = re.search(r':([0-9]+)', maybe_repository)
        repo_port = repo_port_match.group(1) if bool(repo_port_match) else 22

        echo_subtask('Adding repository to known hosts')

        add_to_known_hosts(repo_host, repo_port)


def add_host_to_known_hosts():
    """
    Adds current host to the known hosts

    `fabric3` library sets to `env.host_string` current host where task is executed
    """

    ensure('hosts')

    echo_subtask('Adding current host to known hosts')

    add_to_known_hosts(env.host_string, env.port)


def add_to_known_hosts(host, port):
    cmd = '''

if ! ssh-keygen -H -F {0} &>/dev/null; then