-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_heroku.py
28 lines (23 loc) · 1.04 KB
/
setup_heroku.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
import subprocess, os
def touch(file, content=""):
with open(file, 'w') as fp:
fp.write(content)
pass
def install(package):#python -m pipenv install <name(s)>
subprocess.run(['python', '-m', 'pipenv', 'install', package])
os.system("python -m pipenv run pip freeze > requirments.txt")
#subprocess.run(['python', '-m', 'pipenv', 'run', 'pip', 'freeze', '>', 'requirments.txt'])
def setup(name):
touch('Procfile', 'web: gunicorn --pythonpath src '+name+'.wsgi --log-file -')
touch('env.txt', 'DISABLE_COLLECTSTATIC = 1')
lines = []
with open(os.path.join("src", name, "settings.py"), 'r') as fp:
lines = fp.readlines()
index = lines.index(" 'django.middleware.security.SecurityMiddleware',\n")
lines[index] = lines[index]+"\t'whitenoise.middleware.WhiteNoiseMiddleware',\n"
with open(os.path.join("src", name, "settings.py"), 'w') as fp:
fp.writelines(lines)
if __name__ == '__main__':
install('whitenoise')
install('gunicorn')
setup('main')