-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
49 lines (42 loc) · 1.93 KB
/
settings.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
import sys
if sys.version_info.major == 3:
import configparser
else:
import ConfigParser as configparser
class FallbackConfigParser(configparser.RawConfigParser, object):
def get(self, section, option, **kwargs):
if self.has_section(section) and self.has_option(section, option):
return super(FallbackConfigParser, self).get(section, option)
else:
return kwargs.get('fallback', None)
def getint(self, section, option, **kwargs):
if self.has_section(section) and self.has_option(section, option):
return super(FallbackConfigParser, self).getint(section, option)
else:
return kwargs.get('fallback', None)
def getfloat(self, section, option, **kwargs):
if self.has_section(section) and self.has_option(section, option):
return super(FallbackConfigParser, self).getfloat(section, option)
else:
return kwargs.get('fallback', None)
def getboolean(self, section, option, **kwargs):
if self.has_section(section) and self.has_option(section, option):
return super(FallbackConfigParser, self).getboolean(section,
option,
**kwargs)
else:
return kwargs.get('fallback', None)
config = FallbackConfigParser(defaults={'active': 'False', 'loglevel': 'INFO',
'profile': 'simubot'})
read = config.read('config.ini')
if 'config.ini' not in read:
with open('config.ini', 'w+') as fp:
del config.defaults()['active']
_, configparser.DEFAULTSECT = configparser.DEFAULTSECT, 'general'
config.add_section("restAPI")
config.set("restAPI", "active", True)
config.write(fp)
configparser.DEFAULTSECT = _
config.defaults()['active'] = 'False'
fp.seek(0)
config.readfp(fp)