-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmanage.py
executable file
·206 lines (202 loc) · 6.85 KB
/
manage.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env python
from PlayChess import create_admin, db, config
import re as regex
import sys
import subprocess
import getpass
USERNAME_REGEX = config.USERNAME_REGEX
TERMINAL_COLORS = config.TERMINAL_COLORS
if len(sys.argv) == 2:
if sys.argv[1] == "create_admin":
try:
while True:
print("Enter admin username : ", end="")
admin_username = str(input())
admin_password = str(getpass.getpass())
valid_username = bool(regex.match(USERNAME_REGEX, admin_username))
if valid_username:
if create_admin(db, admin_username, admin_password):
print(
TERMINAL_COLORS['CGREEN'] +
"Admin added successfully to database!" +
TERMINAL_COLORS['CEND']
)
break
else:
print(
TERMINAL_COLORS['CRED'] +
"This username already exits! Please try again!" +
TERMINAL_COLORS['CEND']
)
else:
print(
TERMINAL_COLORS['CRED'] +
"Such a username is invalid!" +
TERMINAL_COLORS['CEND']
)
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Exiting Process" +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "dev":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CBLUE'] +
"Running Gunicorn with 12 Threads" +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'dev'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Exiting Server..." +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "prod":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CBLUE'] +
"Running Gunicorn with 12 Threads" +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'prod'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Exiting Server..." +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "commitall":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CGREEN'] +
"Pushing changes to master branch and heroku..." +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'commitall'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Process Cancelled" +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "logs":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CGREEN'] +
"Opening Heroku logs......." +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'logs'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Closing Logs" +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "shell":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CGREEN'] +
"Starting Heroku Production Shell" +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'shell'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Closing Shell" +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "redis":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CBLUE'] +
"Running Redis Server" +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'redis'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Exiting Server..." +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "celery":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CBLUE'] +
"Running Celery Server" +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'celery'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Exiting Server..." +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
elif sys.argv[1] == "mongo":
try:
print(
TERMINAL_COLORS['CBOLD'] +
TERMINAL_COLORS['CBLUE'] +
"Running Mongo Server" +
TERMINAL_COLORS['CEND'] +
TERMINAL_COLORS['CEND']
)
subprocess.call(['./app.sh', 'mongo'])
except KeyboardInterrupt:
print(
TERMINAL_COLORS['CRED'] +
"Exiting Server..." +
TERMINAL_COLORS['CEND']
)
sys.exit(1)
else:
print(
TERMINAL_COLORS['CRED'] +
"Unrecognised Command" +
TERMINAL_COLORS['CEND']
)
elif len(sys.argv) == 1:
user_instruction = """
Below are list of available commands ->
1) python manage.py create_admin : Adds an admin
2) python manage.py commitall : Commits changes to both heroku and git repo.
3) python manage.py dev : Runs the development server
4) python manage.py prod : Runs the production server
5) python manage.py shell : Runs the production shell
6) python manage.py logs : Shows production logs
"""
print(TERMINAL_COLORS['CBLUE']+user_instruction+TERMINAL_COLORS['CEND'])
else:
print(
TERMINAL_COLORS['CRED'] +
"Unrecognised Command" +
TERMINAL_COLORS['CEND']
)