# Path: py_mina/echo.py
# def echo_task(message, error=False):
#     color = red if error == True else yellow
#     
#     print(color('\n=====> %s' % message))
# 
# def print_task_stats(task_name, start_time, error=None):
#     status_tuple = (task_name, time_string(start_time))
# 
#     if error:
#         echo_comment(('\n[FATAL ERROR]\n\n%s' % error), error=True)
#         echo_status(('\n=====> Task "%s" failed %s \n' % status_tuple), error=True)
#     else:
#         echo_status('\n=====> Task "%s" finished %s \n' % status_tuple)


import timeit
from fabric.api import task, settings, show, hide
from py_mina.subtasks.setup import *
from py_mina.echo import echo_task, print_task_stats
		Creates required structure and adds hosts to known hosts
		"""
		with settings(hide('output')):
			create_required_structure()				
			add_repo_to_known_hosts()
			add_host_to_known_hosts()


	def setup_wrapper(*args):
		"""
		Runs setup process on remote server
			1) check required settings (user, host, deploy_to)
			2) creates required structure (releases, shared, tmp)   
			3) adds repo and host to known hosts if possible
			4) runs wrpapped function
		"""

		check_setup_config()

		start_time = timeit.default_timer()

		echo_task('Running "%s" task' % wrapped_function_name)

		with settings(show('debug'), colorize_errors=True):
			try:
				_pre_setup()
				wrapped_function(*args)

				print_task_stats(wrapped_function_name, start_time)
			except Exception as e:

# Path: py_mina/echo.py
# def echo_task(message, error=False):
#     color = red if error == True else yellow
#     
#     print(color('\n=====> %s' % message))
# 
# def print_task_stats(task_name, start_time, error=None):
#     status_tuple = (task_name, time_string(start_time))
# 
#     if error:
#         echo_comment(('\n[FATAL ERROR]\n\n%s' % error), error=True)
#         echo_status(('\n=====> Task "%s" failed %s \n' % status_tuple), error=True)
#     else:
#         echo_status('\n=====> Task "%s" finished %s \n' % status_tuple)


# Path: py_mina/decorators/setup.py
import timeit
from fabric.api import task, settings, show, hide
from py_mina.subtasks.setup import *
from py_mina.echo import echo_task, print_task_stats

		Creates required structure and adds hosts to known hosts
		"""
		with settings(hide('output')):
			create_required_structure()				
			add_repo_to_known_hosts()
			add_host_to_known_hosts()


	def setup_wrapper(*args):
		"""
		Runs setup process on remote server
			1) check required settings (user, host, deploy_to)
			2) creates required structure (releases, shared, tmp)   
			3) adds repo and host to known hosts if possible
			4) runs wrpapped function
		"""

		check_setup_config()

		start_time = timeit.default_timer()

		echo_task('Running "%s" task' % wrapped_function_name)

		with settings(show('debug'), colorize_errors=True):
			try:
				_pre_setup()
				wrapped_function(*args)

				print_task_stats(wrapped_function_name, start_time)
			except Exception as e:

				print_task_stats(wrapped_function_name, start_time, e)