-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit.py
executable file
·65 lines (43 loc) · 1.44 KB
/
init.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
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import subprocess
import sys
import os
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def launch_cmd(cmd: str):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate()
p_status = p.wait()
if stderr and stderr != '':
print(bcolors.WARNING + stdout.decode("utf-8"))
if stdout and stdout != b'' and stdout != stderr :
print(f"{bcolors.OKGREEN} {stdout}")
def virtual_env_init() -> None:
if os.path.isdir('venv'):
print('venv already exits, skipping virtualenv init')
print(bcolors.OKBLUE +'virtual env init')
cmd = 'python3 -m venv venv'
launch_cmd( cmd )
def install_python_deps() -> None:
cmd = './venv/bin/pip install -r requirements.txt'
print(bcolors.OKBLUE +'install python packages')
launch_cmd( cmd )
def install_ansible_deps() -> None:
cmd = './venv/bin/ansible-galaxy install -p env/common/roles/ -r env/common/requirements.yml'
print(bcolors.OKBLUE +'install ansible roles')
launch_cmd( cmd )
def main() -> None:
virtual_env_init()
install_python_deps()
install_ansible_deps()
print( 'to use virtual environment: source venv/bin/activate')
if __name__ == '__main__':
main()