-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigparser.py
52 lines (40 loc) · 1.43 KB
/
configparser.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
import json, os
PATH = "config/effects.json"
def read_config_file():
"""
Reads the configuration file stored in config/
Returns string being read.
"""
effects_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), PATH)
# Open teh configuration file and read the contents.
config_file = open(effects_file)
config_data = config_file.read()
config_file.close()
return config_data
def parse_json_data(config_data):
"""
Parse the data formatted as json into respective
objects.
Currently prints the objects to the screen for testing.
"""
config_data = json.loads(config_data)
return config_data
def get_effects():
"""
High level function that parses the configuration content
and returns the result as a dictionary of effects.
"""
file_contents = read_config_file()
return parse_json_data(file_contents)
def update_config_file(data):
"""
Overwrites the configuration file containing the effects and
parameters with the new effects sent by the GUI interface.
data -- the effects and parameters data sent by the GUI
packaged in a JSON format.
"""
data_to_json = json.dumps(data)
effects_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), PATH)
# Write all the contents of the JSON into the configuration file.
with open(effects_file, "w") as config_file:
config_file.write(data_to_json)