Reuse defaults from ConfigParser.SafeConfigParser
This commit is contained in:
parent
98089681bd
commit
cce6d80aaa
|
@ -25,18 +25,18 @@ BMConfigDefaults = {
|
|||
"receive": 3,
|
||||
},
|
||||
"network": {
|
||||
"bind": '',
|
||||
"bind": "",
|
||||
"dandelion": 90,
|
||||
},
|
||||
"inventory": {
|
||||
"storage": "sqlite",
|
||||
"acceptmismatch": False,
|
||||
"acceptmismatch": "False",
|
||||
},
|
||||
"knownnodes": {
|
||||
"maxnodes": 20000,
|
||||
},
|
||||
"zlib": {
|
||||
'maxsize': 1048576
|
||||
"maxsize": 1048576
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,9 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
|
|||
|
||||
_temp = {}
|
||||
|
||||
def __init__(self):
|
||||
ConfigParser.SafeConfigParser.__init__(self, defaults=BMConfigDefaults)
|
||||
|
||||
def set(self, section, option, value=None):
|
||||
if self._optcre is self.OPTCRE or value:
|
||||
if not isinstance(value, basestring):
|
||||
|
@ -137,19 +140,11 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
|
|||
ConfigParser.ConfigParser.read(self, filenames)
|
||||
for section in self.sections():
|
||||
for option in self.options(section):
|
||||
try:
|
||||
if not self.validate(
|
||||
section, option,
|
||||
ConfigParser.ConfigParser.get(self, section, option)
|
||||
):
|
||||
try:
|
||||
newVal = BMConfigDefaults[section][option]
|
||||
except KeyError:
|
||||
continue
|
||||
ConfigParser.ConfigParser.set(
|
||||
self, section, option, newVal)
|
||||
except ConfigParser.InterpolationError:
|
||||
continue
|
||||
if not self.validate(
|
||||
section, option,
|
||||
ConfigParser.ConfigParser.get(self, section, option)
|
||||
):
|
||||
self.remove_option(section, option)
|
||||
|
||||
def save(self):
|
||||
"""Save the runtime config onto the filesystem"""
|
||||
|
|
Reference in New Issue
Block a user