def cmd(action, cmd, *args, **kwargs):
    if (isinstance(cmd, basestring) and (not kwargs.get('shell', False))):
        cmd = cmd.split()
    allow_failure = kwargs.pop('allow_failure', False)
    stdin_log = ''
    if (('stdin' in kwargs) and isinstance(kwargs['stdin'], basestring)):
        stdin_log = ('--> ' + kwargs['stdin'])
        stdin = tempfile.TemporaryFile()
        stdin.write(kwargs['stdin'])
        stdin.seek(0)
        kwargs['stdin'] = stdin
    print(action, cmd, stdin_log)
    try:
        output = subprocess.check_output(cmd, *args, stderr=subprocess.STDOUT, **kwargs)
        print_output(output)
    except subprocess.CalledProcessError as e:
        print_output(e.output)
        if allow_failure:
            return
        print('*************************************************')
        print('*** First command failure occurred here.      ***')
        print('*** Will now try to clean up working state.   ***')
        print('*************************************************')
        fail('')
def cmd(action, cmd, *args, **kwargs):
    if (isinstance(cmd, basestring) and (not kwargs.get('shell', False))):
        cmd = cmd.split()
    allow_failure = kwargs.pop('allow_failure', False)
    stdin_log = 
    if (('stdin' in kwargs) and isinstance(kwargs['stdin'], basestring)):
        stdin_log = ('--> ' + kwargs['stdin'])
        stdin = tempfile.TemporaryFile()
        stdin.write(kwargs['stdin'])
        stdin.seek(0)
        kwargs['stdin'] = stdin
    print(action, cmd, stdin_log)
    try:
        output = subprocess.check_output(cmd, *args, stderr=subprocess.STDOUT, **kwargs)
        print_output(output)
    except subprocess.CalledProcessError as e:
        print_output(e.output)
        if allow_failure:
            return
        print('*************************************************')
        print('*** First command failure occurred here.      ***')
        print('*** Will now try to clean up working state.   ***')
        print('*************************************************')
        fail()