# 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
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')
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
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):
"""
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
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()
# -------------------------------------------------------------------------
"""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()
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)