-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate_env.py
41 lines (33 loc) · 1.28 KB
/
generate_env.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
"""Generate a bash script that sets up environment variables if it doesn't already exist."""
import random
def get_random_string(length, allowed_chars):
return ''.join(random.choice(allowed_chars) for _ in range(length))
def main():
filepath = 'project.env'
try:
open(filepath, 'r')
print(f"Environment file `{filepath}` already found. Skipping file generation.")
except FileNotFoundError:
response = ""
while response not in ("y", "n"):
response = input("Is this a dev environment (enable debug mode)? (y/N) ").strip().lower()
if response == "":
response = "n"
if response == "y":
debug_string = "DJANGO_DEBUG=1"
else:
debug_string = "DJANGO_DEBUG=0"
domain = input("Domain (default: localhost): ").strip()
if domain == "":
domain = "localhost"
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#%^&*(-_=+)' # Removed $ because docker compose is stupid
with open(filepath, 'w') as outfile:
outfile.write(f'''
DJANGO_PROJECT_DIR=comics
DJANGO_SECRET={get_random_string(50, chars)}
{debug_string}
SITE_DOMAIN={domain}
''')
print("Created environment file successfully.")
if __name__ == "__main__":
main()