-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetDefaults.py
More file actions
40 lines (34 loc) · 1.13 KB
/
setDefaults.py
File metadata and controls
40 lines (34 loc) · 1.13 KB
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
import os
import secrets
import shutil
import sys
serverEnv = len(sys.argv) > 1 and sys.argv[1] == "server"
if serverEnv: # if server environment run on port 2016 (glynny)
host = "0.0.0.0"
port = 2016
url_prefix = "/script"
else: # else run localhost
host = "127.0.0.1"
port = 5000
url_prefix = ""
# Remove existing "instance" directory if it exists and create a new one
if os.path.exists("instance"):
shutil.rmtree("instance")
os.mkdir("instance")
# Generate a random secret key and write the configuration values to a .env file
secret_key = secrets.token_hex()
with open(".env", "w") as env_file:
env_file.writelines(
[
f"SECRET_KEY = '{secret_key}'\n",
f"HOST = {host}\n",
f"PORT = {port}\n",
f"URL_PREFIX = {url_prefix}\n",
]
)
with open("./static/constants.js", "w") as file:
file.write(f"const URL_PREFIX = '{url_prefix}';\n")
# Print a message indicating the environment and defaults instantiated
environment_name = "Server Environment" if serverEnv else "Development Environment"
msg = f"{environment_name} defaults instantiated"
print(msg)