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, 4, 8, 63), 'fabric.utils.error', 'error', ({(8, 10, 8, 29): "('[Hemp] ' + message)", (8, 31, 8, 35): 'func', (8, 37, 8, 46): 'exception', (8, 48, 8, 54): 'stdout', (8, 56, 8, 62): 'stderr'}, {}), "('[Hemp] ' + message, func, exception, stdout, stderr)", False, 'from fabric.utils import error, puts\n'), ((12, 4, 12, 51), 'fabric.utils.puts', 'puts', ({(12, 9, 12, 25): "('[Hemp] ' + text)", (12, 27, 12, 38): 'show_prefix', (12, 40, 12, 43): 'end', (12, 45, 12, 50): 'flush'}, {}), "('[Hemp] ' + text, show_prefix, end, flush)", False, 'from fabric.utils import error, puts\n'), ((17, 8, 17, 48), 'sys.stdout.write', 'sys.stdout.write', ({(17, 25, 17, 47): "('[GIT] ' + line + '\\n')"}, {}), "('[GIT] ' + line + '\\n')", False, 'import sys\n'), ((18, 8, 18, 26), 'sys.stdout.flush', 'sys.stdout.flush', ({}, {}), '()', False, 'import sys\n'), ((25, 8, 25, 48), 'sys.stdout.write', 'sys.stdout.write', ({(25, 25, 25, 47): "('[GIT] ' + line + '\\n')"}, {}), "('[GIT] ' + line + '\\n')", False, 'import sys\n'), ((26, 8, 26, 26), 'sys.stdout.flush', 'sys.stdout.flush', ({}, {}), '()', False, 'import sys\n')]