-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.py
54 lines (39 loc) · 1.08 KB
/
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
45
46
47
48
49
50
51
52
53
54
import json
env_file = "env.json"
info = {"music_home": ""}
def save(file, environment):
f = open(file, 'w')
f.write(json.dumps(environment))
f.close()
def load_json(file):
with open(file) as json_file:
try:
json_data = json.load(json_file)
except ValueError:
print("Error parsing environment file!")
return {}
return json_data
def load_environment():
file = env_file
try:
env = load_json(file)
except IOError:
f = open(file, 'w')
f.close()
env = {}
return env
def wizard(environment):
new_definition = environment
for key, value in environment.items():
if not value:
new_value = input("Enter value for %s: " % key)
new_definition[key] = new_value
return new_definition
def get_environment():
definition = info
environment = load_environment()
definition.update(environment)
updated_environment = wizard(definition)
save(env_file, updated_environment)
return updated_environment
print(get_environment())