forked from daavelino/vulnerability-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
64 lines (51 loc) · 1.77 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
import platform
import os
import subprocess
import sys
from pathlib import Path
global PROJECT_NAME
global PROJECT_DIR
global HOME_DIR
HOME_DIR = Path(os.getcwd())
PROJECT_NAME="base"
PROJECT_DIR = Path(os.path.join(HOME_DIR, PROJECT_NAME,))
def get_environment():
'''Returns a dictionary with relevant information about OS environment'''
env = dict()
env['system'] = platform.system()
if env['system'] == 'Linux':
env['system version'] = platform.linux_distribution()
if env['system'] == 'Windows':
env['system version'] = platform.linux_distribution()
return(env)
def run():
env = get_environment()
target = Path(os.path.join(os.getcwd(), 'venv',))
# base/ dir was not found...
if not Path(PROJECT_DIR).is_dir():
print("Missing project's files. Maybe you miss to run\n")
print('python setup.py build')
print('\nExiting.')
sys.exit(1)
# venv/ dir was not found...
if not target.is_dir():
print("Missing venv structure. Creating...")
os.mkdir(target)
if env['system'] == 'Linux':
os.system('python -m venv venv')
print("venv created.")
print("Please, run this script again.")
sys.exit(1)
else:
if 'venv' in sys.prefix: # venv is loaded:
os.chdir(PROJECT_DIR)
os.system('python manage.py runserver')
else:
print("\n[Warning] Virtual Environment not load yet. Please, load venv by running:\n")
if env['system'] == 'Linux':
print(' source venv/bin/activate\n')
if env['system'] == 'Windows':
print(' venv\\Scripts\\activate.bat\n')
print("and run this script again.")
sys.exit(1)
run()