forked from armadaplatform/armada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_develop.py
54 lines (41 loc) · 1.77 KB
/
command_develop.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
from __future__ import print_function
import json
import os
from colored import style, fore
def add_arguments(parser):
parser.add_argument('microservice_name',
nargs='?',
default=os.path.basename(os.getcwd()),
help='Name of the microservice to develop. '
'Default is the name of current directory.')
parser.add_argument('-v', '--volume', default=os.getcwd(),
help='Volume mounted to /opt/MICROSERVICE_NAME. Default is current directory path.')
parser.add_argument('--off', action='store_true',
help='Turn off development environment.')
def get_armada_develop_env_file_path():
return '/tmp/armada_develop_env_{}.json'.format(os.getppid())
def save_dev_env_vars(microservice_name, microservice_volume):
path = get_armada_develop_env_file_path()
with open(path, 'w') as f:
env_vars = {
'ARMADA_DEVELOP': '1',
'MICROSERVICE_NAME': microservice_name or '',
'MICROSERVICE_VOLUME': microservice_volume or '',
}
json.dump(env_vars, f)
def command_develop(args):
off = args.off
microservice_name = args.microservice_name
volume = args.volume
if off:
path = get_armada_develop_env_file_path()
if os.path.exists(path):
os.unlink(path)
return
current_dir_name = os.path.basename(os.getcwd())
if current_dir_name != microservice_name:
print(style.BOLD + fore.YELLOW
+ 'WARNING: Current working directory name "{}" does not match '
'microservice name "{}".'.format(current_dir_name, microservice_name)
+ style.RESET)
save_dev_env_vars(microservice_name, volume)