From 3cb3c55f70d181a878d7b78d7e01e86095e2b355 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 20 Oct 2022 17:38:07 +0200 Subject: [PATCH] Adding query for executing yes or no in bin/mirror-ldap-instance --- lib/pp_admintools/app/__init__.py | 7 +------ lib/pp_admintools/app/mirror_ldap.py | 20 +++++++++++++++++--- lib/pp_admintools/app/remove_ldap_user.py | 14 ++------------ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/pp_admintools/app/__init__.py b/lib/pp_admintools/app/__init__.py index 68c128d..19da056 100644 --- a/lib/pp_admintools/app/__init__.py +++ b/lib/pp_admintools/app/__init__.py @@ -26,7 +26,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.5.0' +__version__ = '0.5.1' # ============================================================================= @@ -59,11 +59,6 @@ class BaseDPXApplication(FbConfigApplication): argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None, config_dir=DEFAULT_CONFIG_DIR): - self.init_yes_no_lists() - - self._yes = False - self._prompt_timeout = self.default_prompt_timeout - super(BaseDPXApplication, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, description=description, cfg_class=cfg_class, initialized=False, diff --git a/lib/pp_admintools/app/mirror_ldap.py b/lib/pp_admintools/app/mirror_ldap.py index 1b3c859..58ef7f1 100644 --- a/lib/pp_admintools/app/mirror_ldap.py +++ b/lib/pp_admintools/app/mirror_ldap.py @@ -24,6 +24,7 @@ from functools import cmp_to_key from fb_tools.common import pp # from fb_tools.collections import FrozenCIStringSet, CIStringSet, CIDict from fb_tools.collections import CIDict, CIStringSet +from fb_tools.errors import AbortAppError, TimeoutOnPromptError from ..xlate import XLATOR @@ -34,7 +35,7 @@ from .ldap import BaseLdapApplication from ..argparse_actions import NonNegativeItegerOptionAction from ..argparse_actions import LimitedFloatOptionAction -__version__ = '0.4.0' +__version__ = '0.4.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -206,10 +207,23 @@ class MirrorLdapApplication(BaseLdapApplication): # ------------------------------------------------------------------------- def _run(self): + src_url = self.cfg.ldap_connection[self.src_instance].url + tgt_url = self.cfg.ldap_connection[self.tgt_instance].url + msg = _( + "Start mirroring LDAP instance {src!r} ({src_url}) to instance {tgt!r} ({tgt_url}) " + "[{yes}/{no}]?").format( + src=self.src_instance, src_url=src_url, tgt=self.tgt_instance, tgt_url=tgt_url, + yes=self.colored(_('yes'), 'RED'), no=self.colored(_('No'), 'GREEN')) + ' ' + + self.empty_line() + answer = self.ask_for_yes_or_no(msg) + if not answer: + self.empty_line() + LOG.error(_("Interrupted on demand.")) + self.exit(3) + if not self.quiet and not self.force: self.empty_line() - src_url = self.cfg.ldap_connection[self.src_instance].url - tgt_url = self.cfg.ldap_connection[self.tgt_instance].url msg = _( "Start mirroring LDAP instance {src!r} ({src_url}) to instance {tgt!r} " "({tgt_url}) ...").format( diff --git a/lib/pp_admintools/app/remove_ldap_user.py b/lib/pp_admintools/app/remove_ldap_user.py index 23adbbc..f89b610 100644 --- a/lib/pp_admintools/app/remove_ldap_user.py +++ b/lib/pp_admintools/app/remove_ldap_user.py @@ -24,7 +24,7 @@ from ..xlate import XLATOR from .ldap import LdapAppError, FatalLDAPError from .ldap import BaseLdapApplication -__version__ = '0.5.5' +__version__ = '0.5.7' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -277,17 +277,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): msg = _("Remove [{yes}/{no}]?") msg = msg.format( yes=self.colored(_('yes'), 'RED'), no=self.colored(_('No'), 'GREEN')) + ' ' - try: - return self.ask_for_yes_or_no(msg) - except (TimeoutOnPromptError, AbortAppError) as e: - if self.deactivate: - msg = _("Abort deactivating by {cls}: {e}") - else: - msg = _("Abort removing by {cls}: {e}") - LOG.error(msg.format(cls=e.__class__.__name__, e=e)) - return False - - return True + return self.ask_for_yes_or_no(msg) # ------------------------------------------------------------------------- def eval_user_dns(self, user): -- 2.39.5