-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose.py
executable file
·55 lines (42 loc) · 1.7 KB
/
compose.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
50
51
52
53
54
55
#!/usr/bin/env python
import os, argparse
################################################################################
############################## ARGS
################################################################################
def options():
parser = argparse.ArgumentParser()
parser.add_argument("compose", help="compose filename")
parser.add_argument("command", help="command name")
parser.add_argument("-p", "--project", type=str, default="api-plugin", help="project name")
parser.add_argument("-d", "--directory", type=str, default="compose", help="compose directory")
parser.add_argument("-o", "--option", nargs='+', type=str, default="", help="options")
return parser.parse_args()
################################################################################
############################## Functions
################################################################################
def command_mapper(cmd_name):
if cmd_name == "rm":
return "rm -f"
elif cmd_name == "up":
return "up -d --no-recreate"
return cmd_name
def handler(filepath, project, cmd_name, options):
command = command_mapper(cmd_name)
options = " ".join(options)
cmd = "docker-compose %s %s %s %s" % (filepath, project, command, options)
print cmd
os.system(cmd)
MULTIPLE = {
"srm": ["stop", "rm"],
"restart": ["stop", "rm", "up"]
}
def main():
args = options()
filepath = "-f %s/%s.yml" % (args.directory, args.compose)
project = "-p %s" % args.project
commands = [args.command]
if args.command in MULTIPLE :
commands = MULTIPLE[args.command]
for cmd in commands :
handler(filepath, project, cmd, args.option)
main()