Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
Created June 11, 2014 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rattrayalex/57bd40b2de7f8868d25f to your computer and use it in GitHub Desktop.
Save rattrayalex/57bd40b2de7f8868d25f to your computer and use it in GitHub Desktop.
show commands that are being run
from clint.textui import puts, indent, colored
def red(msg):
return puts(colored.red(msg))
def shell(cmd, fail_silently=False, *args, **kwargs):
# tell the user what's about to go out
puts(colored.blue("-> {}".format(cmd)))
try:
out = subprocess.check_output(cmd, shell=True, *args, **kwargs)
except subprocess.CalledProcessError as e:
red("Command failed! (exit code {})".format(e.returncode))
with indent(4):
red("Failed cmd: {}".format(e.cmd))
red("Exit code: {}".format(e.returncode))
red("Output:")
out = e.output
if not fail_silently:
raise e
finally:
with indent(4):
puts(out)
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment