forked from IBM/watson-stt-wer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
50 lines (40 loc) · 1.61 KB
/
config.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
import configparser
STT_SECTION_KEY="SpeechToText"
TRANSCRIPTIONS_SECTION_KEY="Transcriptions"
OUTPUT_SECTION_KEY="ErrorRateOutput"
TRANSFORMATIONS_SECTION_KEY="Transformations"
class Config:
config = None
def __init__(self, config_file:str):
# (interpolation=None) so that '%' is not treated like an environment variable
# inline_comment_prefixes allows comments inline, after the value
self.config_file = config_file
self.config = configparser.ConfigParser(interpolation=None, inline_comment_prefixes='#;')
self.config.read(config_file)
def getBoolean(self, section, key, default_value=None):
return self.getValue(section, key, default_value) == "True"
def getValue(self, section, key, default_value=None):
value = None
if section in self.config:
list = self.config[section]
value = list.get(key, default_value)
return value
def getKeys(self, section):
if section in self.config:
return [key for key,value in self.config.items(section)]
return None
def setValue(self, section:str, key:str, value:str):
if section in self.config:
self.config.set(section, key, value)
def writeFile(self, file_name:str):
with open(file_name, 'w') as configfile:
self.config.write(configfile)
#value = None
if section in self.config:
self.config.set(section, key, value)
return
def writeFile(self, file:str):
#value = None
with open(file, 'w') as configfile:
self.config.write(configfile)
return