-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.py
executable file
·55 lines (43 loc) · 1.13 KB
/
entrypoint.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
# coding: utf-8
from __future__ import print_function
import os
import sys
COMMANDS = {
'start': ('python', ['/app/smtp_catcher/start.py']),
'shell': '/bin/sh',
}
def default_action():
"""
Executed when no arguments are passed or argument is not recognized
"""
print("Available commands:")
for c in COMMANDS.keys():
print(">", c)
def prepare_command(command):
if command not in COMMANDS:
print("Unknown command:", command)
return None, None
cmd = COMMANDS[command]
if type(cmd) == str:
return cmd, []
return cmd[0], cmd[1]
def main():
sys_args = sys.argv
if sys_args[0] == 'python':
sys_args = sys_args[1:]
if sys_args[0] == __file__:
sys_args = sys_args[1:]
if len(sys_args) == 0:
default_action()
return
else:
command, args = prepare_command(sys_args[0])
if command is None:
default_action()
return
args += sys_args[1:]
print("Executing:\n>", command, ' '.join(args))
os.execvp(command, [command] + args)
if __name__ == '__main__':
main()