class SambaOption(optparse.Option):
+ ATTRS = optparse.Option.ATTRS + ["validators"]
TYPES = optparse.Option.TYPES + ("bytes",)
TYPE_CHECKER = copy(optparse.Option.TYPE_CHECKER)
TYPE_CHECKER["bytes"] = check_bytes
+ def run_validators(self, opt, value):
+ """Runs the list of validators on the current option."""
+ validators = getattr(self, "validators") or []
+ for validator in validators:
+ validator(opt, value)
+
+ def convert_value(self, opt, value):
+ """Override convert_value to run validators just after.
+
+ This can also be done in process() but there we would have to
+ replace the entire method.
+ """
+ value = super().convert_value(opt, value)
+ self.run_validators(opt, value)
+ return value
+
class SambaOptions(optparse.OptionGroup):
"""General Samba-related command line options."""
class Option(SambaOption):
- ATTRS = SambaOption.ATTRS + ["validators"]
SUPPRESS_HELP = optparse.SUPPRESS_HELP
- def run_validators(self, opt, value):
- """Runs the list of validators on the current option."""
- validators = getattr(self, "validators") or []
- for validator in validators:
- validator(opt, value)
-
- def convert_value(self, opt, value):
- """Override convert_value to run validators just after.
-
- This can also be done in process() but there we would have to
- replace the entire method.
- """
- value = super().convert_value(opt, value)
- self.run_validators(opt, value)
- return value
-
class PlainHelpFormatter(optparse.IndentedHelpFormatter):
"""This help formatter does text wrapping and preserves newlines."""