Created
June 11, 2014 20:02
-
-
Save rattrayalex/57bd40b2de7f8868d25f to your computer and use it in GitHub Desktop.
show commands that are being run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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