]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding command line parameter '--yes' for LDAP apps.
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Sep 2022 14:49:11 +0000 (16:49 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Sep 2022 14:49:11 +0000 (16:49 +0200)
lib/pp_admintools/app/ldap.py

index 883ca411d5fa388c9fdbb5c071b47a368fe84989..5f20b71a184ce736f2f6bb7149ae57104e139659 100644 (file)
@@ -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