mirror of
https://github.com/samba-team/samba.git
synced 2025-12-12 12:23:50 +03:00
netcmd: auth policy: add OptionGroup classes for user, service and computer options
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
committed by
Andrew Bartlett
parent
0667708cef
commit
7c389e1921
@@ -171,6 +171,29 @@ class OptionParser(optparse.OptionParser):
|
||||
return super().check_values(values, args)
|
||||
|
||||
|
||||
class OptionGroup(optparse.OptionGroup):
|
||||
"""Samba OptionGroup base class.
|
||||
|
||||
Provides a generic set_option method to be used as Option callback,
|
||||
so that one doesn't need to be created for every available Option.
|
||||
|
||||
Also overrides the add_option method, so it correctly initialises
|
||||
the defaults on the OptionGroup.
|
||||
"""
|
||||
|
||||
def add_option(self, *args, **kwargs):
|
||||
"""Override add_option so it applies defaults during constructor."""
|
||||
opt = super().add_option(*args, **kwargs)
|
||||
default = None if opt.default == optparse.NO_DEFAULT else opt.default
|
||||
self.set_option(opt, opt.get_opt_string(), default, self.parser)
|
||||
return opt
|
||||
|
||||
def set_option(self, option, opt_str, arg, parser):
|
||||
"""Callback to set the attribute based on the Option dest name."""
|
||||
dest = option.dest or option._long_opts[0][2:].replace("-", "_")
|
||||
setattr(self, dest, arg)
|
||||
|
||||
|
||||
class SambaOptions(optparse.OptionGroup):
|
||||
"""General Samba-related command line options."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user