]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Removing max cycles in lib/pp_admintools/app/clean_empty_ldap_groups.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 15 Jun 2023 14:46:42 +0000 (16:46 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 15 Jun 2023 14:46:42 +0000 (16:46 +0200)
lib/pp_admintools/app/clean_empty_ldap_groups.py

index b25c3a8618ddece722318fc580ef7e131ebf1170..95fc4453fcfe1a6612b0e27b6d0b4c5fdd611e33 100644 (file)
@@ -27,10 +27,9 @@ from .ldap import BaseLdapApplication
 # from .ldap import FatalLDAPError
 from .ldap import LdapAppError
 from .. import pp
-from ..argparse_actions import LimitedIntegerOptionAction
 from ..xlate import XLATOR
 
-__version__ = '0.3.0'
+__version__ = '0.4.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -56,9 +55,6 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication):
 
     default_prompt_timeout = 10
 
-    default_max_cycles = 20
-    max_max_cycles = 1000
-
     group_object_classes = ('groupOfNames', 'groupOfUniqueNames', 'groupOfURLs', 'posixGroup')
     member_attributes = (
         'member', 'memberUid', 'memberURL', 'mgrpRFC822MailMember', 'uniqueMember')
@@ -69,10 +65,7 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication):
         self.dns_todo = CIStringSet()
         self.dns_done = CIStringSet()
 
-        self.current_cycle = 0
-        self.last_nr_groups_done = 0
         self._base_dn = None
-        self._max_cycles = self.default_max_cycles
         self.instance = None
         self.connect_info = None
 
@@ -106,29 +99,6 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication):
         else:
             self._base_dn = None
 
-    # -------------------------------------------
-    @property
-    def max_cycles(self):
-        """Define, that the given users will not be removed, bur deactivated instaed."""
-        return self._max_cycles
-
-    @max_cycles.setter
-    def max_cycles(self, value):
-        if value is None:
-            self._max_cycles = self.default_max_cycles
-            return
-        try:
-            v = int(value)
-            if v <= 0 or v > 1000:
-                msg = _(
-                    'The maximum number of cycles must not less or equal to zero and mast not be '
-                    'greater than {}.').format(self.max_max_cycles)
-                raise ValueError(msg)
-        except Exception as e:
-            msg = _('Got a {} for setting the maximum cycles:').format(e.__class__.__name__)
-            msg += ' ' + str(e)
-            raise CleanEmptyLdapGroupsUserError(msg)
-
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
@@ -143,10 +113,7 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication):
         res = super(CleanEmptyLdapGroupsApplication, self).as_dict(short=short)
 
         res['base_dn'] = self.base_dn
-        res['default_max_cycles'] = self.default_max_cycles
         res['group_object_classes'] = copy.copy(self.group_object_classes)
-        res['max_cycles'] = self.max_cycles
-        res['max_max_cycles'] = self.max_max_cycles
         res['member_attributes'] = copy.copy(self.member_attributes)
 
         return res
@@ -161,16 +128,6 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication):
             help=_('The base DN used as the root for the LDAP search.')
         )
 
-        cycles_help = _(
-            'The maximum number of iteration cycles for searching for empty groups. '
-            'It must not be less or equal to zero and must not be greater than {}.')
-        cycles_help = cycles_help.format(self.max_max_cycles)
-        cycles_help += ' ' + _('Default: {}.').format(self.default_max_cycles)
-
-        remove_group.add_argument(
-            '--cycles', dest='cycles', metavar=_('COUNT'), min_val=1, max_val=self.max_max_cycles,
-            action=LimitedIntegerOptionAction, help=cycles_help)
-
         super(CleanEmptyLdapGroupsApplication, self).init_arg_parser()
 
     # -------------------------------------------------------------------------
@@ -184,10 +141,6 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication):
         """Execute some steps before calling run()."""
         super(CleanEmptyLdapGroupsApplication, self).post_init()
 
-        cycles = getattr(self.args, 'cycles', None)
-        if cycles:
-            self.max_cycles = cycles
-
         self.base_dn = getattr(self.args, 'ldap_base_dn', None)
 
         self.check_instances()
@@ -302,7 +255,8 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication):
     def request_for_remove(self, dn):
         """Request from operator whther to really remove it."""
         print()
-        msg = self.colored(_('Do you really want to remove the group {!r}').format(dn), 'CYAN')
+        msg = _("Do you really want to remove the group '{}'")
+        msg = msg.format(self.colored(dn, 'CYAN'))
         msg += ' ' + _('[{yes}/{no}]?').format(
             yes=self.colored(_('yes'), 'RED'), no=self.colored(_('No'), 'GREEN')) + ' '
         return self.ask_for_yes_or_no(msg, default_on_empty=False)