Last active
May 17, 2018 06:50
-
-
Save FabienArcellier/9d5c61a04088cf044f2dbfb36203f641 to your computer and use it in GitHub Desktop.
template to use python as command engine as you would use bash -ex
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
#!/usr/bin/env python | |
import os | |
import sys | |
SCRIPT_DIR = os.path.realpath(os.path.join(__file__, '..')) | |
ROOT_DIR = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | |
def main(arguments): | |
os.chdir(ROOT_DIR + '/dev/') | |
_system('docker-compose up') | |
# BOILERPLATE TO REPRODUCE -ex behavior of bash | |
def _system(cmd, logged = True): | |
if logged: | |
print('$ {0}'.format(cmd)) | |
output = os.system(cmd) | |
# see : https://stackoverflow.com/a/6466753 | |
error_code = output >> 8 | |
if error_code > 0: | |
raise OSError(error_code) | |
if __name__ == '__main__': | |
try: | |
main(sys.argv[1:]) | |
except (OSError) as e: | |
sys.exit(e.args[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment