Skip to content

Instantly share code, notes, and snippets.

@FabienArcellier
Last active May 17, 2018 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FabienArcellier/9d5c61a04088cf044f2dbfb36203f641 to your computer and use it in GitHub Desktop.
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
#!/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