From 24589c75325cc6c6d3075f259b63e4b781b702ec Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 6 Sep 2022 16:49:11 +0200 Subject: [PATCH] Adding command line parameter '--yes' for LDAP apps. --- lib/pp_admintools/app/ldap.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 883ca41..5f20b71 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -18,7 +18,7 @@ except ImportError: from pathlib2 import Path # Third party modules -from fb_tools.common import pp +from fb_tools.common import pp, to_bool from fb_tools.cfg_app import FbConfigApplication from fb_tools.errors import FbAppError @@ -36,7 +36,7 @@ from ..config.ldap import LdapConnectionInfo, LdapConfiguration # rom ..config.ldap import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS from ..config.ldap import DEFAULT_TIMEOUT, MAX_TIMEOUT -__version__ = '0.2.1' +__version__ = '0.2.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -158,6 +158,7 @@ class BaseLdapApplication(FbConfigApplication): self._password_file = None self.ldap_instances = [] + self._yes = False super(BaseLdapApplication, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, @@ -194,6 +195,16 @@ class BaseLdapApplication(FbConfigApplication): self._password_file = path + # ----------------------------------------------------------- + @property + def yes(self): + """Assume 'yes' as an answer to all questions.""" + return self._yes + + @yes.setter + def yes(self, value): + self._yes = to_bool(value) + # ------------------------------------------------------------------------- def as_dict(self, short=True): """ @@ -212,6 +223,7 @@ class BaseLdapApplication(FbConfigApplication): res['show_cmdline_ldap_timeout'] = self.show_cmdline_ldap_timeout res['use_default_ldap_connection'] = self.use_default_ldap_connection res['use_multiple_ldap_connections'] = self.use_multiple_ldap_connections + res['yes'] = self.yes return res @@ -230,6 +242,9 @@ class BaseLdapApplication(FbConfigApplication): group_title = _('Options fo LDAP connections') ldap_group = self.arg_parser.add_argument_group(group_title) + ldap_group.add_argument( + '-y', '--yes', '--assume-yes', action="store_true", dest="yes", help=argparse.SUPPRESS) + if self.use_default_ldap_connection: ldap_host = LdapConfiguration.default_ldap_server @@ -355,6 +370,8 @@ class BaseLdapApplication(FbConfigApplication): self._init_default_connection() + self.yes = self.args.yes + if self.use_default_ldap_connection: self.ldap_instances = ['default'] return -- 2.39.5