Skip to content

Instantly share code, notes, and snippets.

@FabienArcellier FabienArcellier/system.py
Last active May 17, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.