# 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
import fabric.api
from py_mina.echo import echo_task, print_task_stats
"""


from __future__ import with_statement


def task(wrapped_function):
	"""
	Task function decorator
	"""

	wrapped_function_name = wrapped_function.__name__

	def task_wrapper(*args):
		"""
		Runs task and prints stats at the end
		"""

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

		start_time = timeit.default_timer()

		with fabric.api.settings(colorize_errors=True):
			try:
				wrapped_function(*args)
			except Exception as e:
				print_task_stats(wrapped_function_name, start_time, e)

				raise e # escalate exception
			else:

# 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/task.py
import timeit
import fabric.api
from py_mina.echo import echo_task, print_task_stats

"""


from __future__ import with_statement


def task(wrapped_function):
	"""
	Task function decorator
	"""

	wrapped_function_name = wrapped_function.__name__

	def task_wrapper(*args):
		"""
		Runs task and prints stats at the end
		"""

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

		start_time = timeit.default_timer()

		with fabric.api.settings(colorize_errors=True):
			try:
				wrapped_function(*args)
			except Exception as e:
				print_task_stats(wrapped_function_name, start_time, e)

				raise e # escalate exception
			else:

				print_task_stats(wrapped_function_name, start_time)