-
Notifications
You must be signed in to change notification settings - Fork 129
/
run.py
76 lines (58 loc) · 1.94 KB
/
run.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
66
67
68
69
70
71
from adhrit.installer import main
import configparser, webbrowser
from subprocess import Popen, PIPE
from sys import platform
import os,time, requests
try:
import requests
from requests.exceptions import ConnectionError
except ImportError:
print (ImportError('Modules not yet installed!'))
def get_config_data(key):
check_deps = configparser.ConfigParser()
check_deps.read('config')
return check_deps.get('config-data', str(key))
def check_running_process(process):
cmd = 'pgrep -f '+ process
process = Popen(cmd, shell=True, stdout=PIPE,
stderr=PIPE)
my_pid, err = process.communicate()
if len(my_pid.splitlines()) >0:
return True
else:
return False
dep_check = get_config_data('dependencies_status')
if dep_check != 'complete':
print('[**] Currently Installed dependencies does not meet the requirement of the tool.\n-> Initiating installation of dependencies')
print('Host OS: ' + 'MacOS' if platform=="darwin" else 'Linux' )
main()
dep_check = get_config_data('dependencies_status')
if dep_check == 'complete':
# Check if Flask app is already running
if not check_running_process('python3 app.py'):
b = Popen(['python3 app.py &'], stdin=PIPE, shell=True)
while(True):
url = 'http://localhost:5000/'
try:
req = requests.get(url)
if req.status_code == 200:
b.communicate(input=b'\n')
break
except ConnectionError as e:
time.sleep(1)
os.system('sudo lsof -t -i tcp:4200 | xargs kill -9') #To kill any ng s if present
working_dir = os.getcwd()
os.chdir(working_dir + '/frontend')
a = Popen(['ng','s','--host','0.0.0.0'])
while(True):
url = 'http://localhost:4200/'
try:
req = requests.get(url)
if req.status_code == 200:
a.communicate(input=b'\n')
os.chdir(working_dir)
break
# from requests.exceptions import ConnectionError
except ConnectionError as e:
time.sleep(2)
webbrowser.open('http://localhost:4200/', new=2)