config: BaseOption.set now also set parser option value
This commit is contained in:
parent
8438f95e68
commit
e058d315d4
1 changed files with 18 additions and 12 deletions
|
@ -90,22 +90,28 @@ class BaseOption:
|
||||||
|
|
||||||
def set(self, value):
|
def set(self, value):
|
||||||
""" Set option value to config file """
|
""" Set option value to config file """
|
||||||
assert self.config.config_parser, "Can set option value only if configuration file is configured"
|
assert self.config.config_parser or (self.config.options and not self.no_arg), (
|
||||||
|
"Can't set option value: configuration file not configured, not options (or no argument)")
|
||||||
if value == '':
|
if value == '':
|
||||||
value = None
|
value = None
|
||||||
|
|
||||||
if value == self.default or value is None:
|
if self.config.config_parser:
|
||||||
# Remove option from config
|
if value == self.default or value is None:
|
||||||
self.config.config_parser.remove_option(
|
# Remove option from config (is section exists)
|
||||||
self.section.name, self.name)
|
if self.config.config_parser.has_section(self.section.name):
|
||||||
else:
|
self.config.config_parser.remove_option(
|
||||||
# Store option to config
|
self.section.name, self.name)
|
||||||
if not self.config.config_parser.has_section(self.section.name):
|
else:
|
||||||
self.config.config_parser.add_section(self.section.name)
|
# Store option to config
|
||||||
|
if not self.config.config_parser.has_section(self.section.name):
|
||||||
|
self.config.config_parser.add_section(self.section.name)
|
||||||
|
|
||||||
self.config.config_parser.set(
|
self.config.config_parser.set(
|
||||||
self.section.name, self.name, self.to_config(value)
|
self.section.name, self.name, self.to_config(value)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.config.options and not self.no_arg:
|
||||||
|
setattr(self.config.options, self.parser_dest, value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parser_action(self):
|
def parser_action(self):
|
||||||
|
|
Loading…
Reference in a new issue