-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_env.py
executable file
·44 lines (33 loc) · 985 Bytes
/
make_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
42
43
44
#!/usr/bin/env python3
import os, sys, base64
FILENAME='.env'
def noop(s): return s
def lower(s): return s.lower()
def _bool(s):
return {'t':'true',
'y':'true',
'n':'false',
'f': 'false'}.get(s.lower(), s.lower())
VARS = (('HOST', 'Hostname', lower),
)
def random_pw():
with open('/dev/urandom', 'rb') as f:
return base64.urlsafe_b64encode(f.read(12))
print ("""
Making the ENV file...
""")
if os.path.exists(FILENAME):
print (".env file exists, either remove or edit directly")
sys.exit(0)
vars = dict((var,_filter(input(prompt + "? ").strip())) for var, prompt, _filter in VARS)
# for pw in ('DB_PASS',
# 'POSTGRES_PASSWORD',
# 'ADMIN_PASS'):
# vars[pw] = random_pw()
with open (FILENAME, 'w') as f:
for k,v in sorted(vars.items()):
strVal = v
if isinstance(v, bytes):
strVal=v.decode('ascii')
f.write("%s=%s\n" % (k,strVal))
sys.exit(0)