forked from roguelike2d/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigReader.py
50 lines (35 loc) · 1.39 KB
/
ConfigReader.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
"""
Reads in simple config files
"""
import configparser
class ConfigReader:
DATA_FOLDUER = "TekkenData/"
values = {}
def __init__(self, filename):
self.path = ConfigReader.DATA_FOLDUER + filename + ".ini"
self.parser = configparser.ConfigParser()
try:
self.parser.read(self.path)
except:
print("Error reading config data from " + self.path + ". Using default values.")
def get_property(self, section, property_string, default_value):
try:
if type(default_value) is bool:
value = self.parser.getboolean(section, property_string)
else:
value = self.parser.get(section, property_string)
except:
value = default_value
if section not in self.parser.sections():
self.parser.add_section(section)
self.parser.set(section, property_string, str(value))
return value
def set_property(self, section, property_string, value):
self.parser.set(section, property_string, str(value))
def add_comment(self, comment):
if 'Comments' not in self.parser.sections():
self.parser.add_section('Comments')
self.parser.set('Comments', '; ' + comment, "")
def write(self):
with open(self.path, 'w') as fw:
self.parser.write(fw)