Get user confirmation or abort execution.

    confirm returns True (if user confirms) or False (if user declines
    and exitCodeOnAbort is None) or aborts with sys.exit(exitCodeOnAbort)
    (if user declines and exitCodeOnAbort is not None).

    Depending on acceptByDefault, the default answer (if user presses
    Return only), is to accept or abort.  " - are you sure [y] ?" or "
    - are you sure [n] ?" will be appended to msg, depending on the
    value of acceptByDefault.

    If batch is True, returns immediately.

def confirm(msg, acceptByDefault=False, exitCodeOnAbort=1, batch=False):
    """Get user confirmation or abort execution.

    confirm returns True (if user confirms) or False (if user declines
    and exitCodeOnAbort is None) or aborts with sys.exit(exitCodeOnAbort)
    (if user declines and exitCodeOnAbort is not None).

    Depending on acceptByDefault, the default answer (if user presses
    Return only), is to accept or abort.  " - are you sure [y] ?" or "
    - are you sure [n] ?" will be appended to msg, depending on the
    value of acceptByDefault.

    If batch is True, returns immediately."""
    if batch:
        return
    if acceptByDefault:
        msg += ' - are you sure [y] ? '
    else:
        msg += ' - are you sure [n] ? '
    while True:
        reply = raw_input(msg).lower()
        print
        if reply == '':
            reply = 'y' if acceptByDefault else 'n'
        if reply == 'y':
            return True
        elif reply == 'n':
            if exitCodeOnAbort is None:
                return False
            else:
                error('Program execution aborted by user')
                sys.exit(exitCodeOnAbort)
        else:
            print "ERROR: Invalid reply - please enter either 'y' or 'n', or press just enter to accept default\n"