import sys

from fabric.utils import error, puts
from git import RemoteProgress


def print_err(message, func=None, exception=None, stdout=None, stderr=None):
    error('[Hemp] ' + message, func, exception, stdout, stderr)


def print_info(text, show_prefix=None, end="\n", flush=True):
    puts('[Hemp] ' + text, show_prefix, end, flush)


def print_git_output(stdout):
    for line in stdout.split('\n'):
        sys.stdout.write('[GIT] ' + line + '\n')
        sys.stdout.flush()


class SimpleProgressPrinter(RemoteProgress):
    def _parse_progress_line(self, line):
        if '\r' in line:
            line = line.replace('\r', '\r[GIT] ')
        sys.stdout.write('[GIT] ' + line + '\n')
        sys.stdout.flush()

[(8, 'fabric.utils.error', 'error', False, 'from fabric.utils import error, puts\n'), (12, 'fabric.utils.puts', 'puts', False, 'from fabric.utils import error, puts\n'), (17, 'sys.stdout.write', 'sys.stdout.write', False, 'import sys\n'), (18, 'sys.stdout.flush', 'sys.stdout.flush', False, 'import sys\n'), (25, 'sys.stdout.write', 'sys.stdout.write', False, 'import sys\n'), (26, 'sys.stdout.flush', 'sys.stdout.flush', False, 'import sys\n')]