import re


def _progress_stdout_handler(progress_cb):
    """
    :return: stdout handler which looks for percentage done reports
             and makes an appropriate call to the progress callback.

    The handler uses a regex to look for a 'percentage'
    output and calls the progress handler with the number
    found and a 'total' of 100.
    """
    percent_re = re.compile(r"^(\d+)%?$")
    def _handler(line):
        match = percent_re.match(line)
        if match:
            progress_cb(int(match.group(1)), 100)
    return _handler