Compare commits
2 commits
68c2103c58
...
1276d587a4
Author | SHA1 | Date | |
---|---|---|---|
|
1276d587a4 | ||
|
98bb0d8d0f |
2 changed files with 50 additions and 0 deletions
|
@ -385,6 +385,55 @@ class IntegerOption(BaseOption):
|
||||||
print("Invalid answer. Must a integer value")
|
print("Invalid answer. Must a integer value")
|
||||||
|
|
||||||
|
|
||||||
|
class OctalOption(BaseOption):
|
||||||
|
"""Octal configuration option class"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def octal(value):
|
||||||
|
"""Convert integer of integer string as octal string"""
|
||||||
|
return int(str(value), 8)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _from_config(self):
|
||||||
|
"""Get option value from ConfigParser"""
|
||||||
|
value = self.config.config_parser.getint(self.section.name, self.name)
|
||||||
|
print(value)
|
||||||
|
return self.octal(value)
|
||||||
|
|
||||||
|
def to_config(self, value=None):
|
||||||
|
"""Format value as stored in configuration file"""
|
||||||
|
value = value if value is not None else self.get()
|
||||||
|
return oct(value)[2:] if value is not None else ""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parser_type(self):
|
||||||
|
return self.octal
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parser_help(self):
|
||||||
|
"""Get option help message in arguments parser options"""
|
||||||
|
if self.arg_help and self.default is not None:
|
||||||
|
# pylint: disable=consider-using-f-string
|
||||||
|
return "{} (Default: {})".format(
|
||||||
|
self.arg_help, re.sub(r"%([^%])", r"%%\1", oct(self._default_in_config)[2:])
|
||||||
|
)
|
||||||
|
if self.arg_help:
|
||||||
|
return self.arg_help
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _ask_value(self, prompt=None, **kwargs):
|
||||||
|
"""Ask to user to enter value of this option and return it"""
|
||||||
|
default_value = kwargs.pop("default_value", self.get())
|
||||||
|
while True:
|
||||||
|
value = super()._ask_value(prompt, default_value=default_value, **kwargs)
|
||||||
|
if value in ["", None, default_value]:
|
||||||
|
return default_value
|
||||||
|
try:
|
||||||
|
return self.octal(value)
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid answer. Must an octal value")
|
||||||
|
|
||||||
|
|
||||||
class PasswordOption(StringOption):
|
class PasswordOption(StringOption):
|
||||||
"""Password configuration option class"""
|
"""Password configuration option class"""
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance
|
||||||
"""Configure options on registered mylib.Config object"""
|
"""Configure options on registered mylib.Config object"""
|
||||||
section = super().configure(
|
section = super().configure(
|
||||||
just_try_help=kwargs.pop("just_try_help", "Just-try mode: do not really send report"),
|
just_try_help=kwargs.pop("just_try_help", "Just-try mode: do not really send report"),
|
||||||
|
loaded_callback=self.initialize,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue