-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursively_dcu.py
49 lines (37 loc) · 1.26 KB
/
recursively_dcu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
import os
import re
import subprocess
# Brings up dockers with the _component suffix
COMPONENT_SUFFIX = r'.+_component$'
def execute(cmd):
popen = subprocess.Popen(
cmd, stdout=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line
popen.stdout.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
def get_dirs(parent_dir = "."):
return [o for o in os.listdir(parent_dir) if os.path.isdir(os.path.join(parent_dir, o))]
def get_component_dirs():
child_dirs = get_dirs()
return [c for c in child_dirs if re.match(COMPONENT_SUFFIX, c)]
def bring_docker_up(child_dir, parent_dir="."):
old_dir = os.getcwd()
os.chdir("{}/{}".format(parent_dir, child_dir))
try:
for line in execute(["docker-compose", "up", "-d"]):
print(line.strip())
except subprocess.CalledProcessError as e:
print("Bringing docker up for {} failed: {}".format(child_dir, e))
os.chdir(old_dir)
def main():
dirs = get_component_dirs()
for d in dirs:
print("---{}---".format(d))
bring_docker_up(d)
print("-------")
if __name__ == "__main__":
main()