From: Frank Brehm Date: Tue, 30 Jul 2024 12:39:22 +0000 (+0200) Subject: Adding new command line option '--one' to bin/clean-empty-ldap-groups X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=8bc497514871d13c4899a67b4f01c664636b06fb;p=pixelpark%2Fpp-admin-tools.git Adding new command line option '--one' to bin/clean-empty-ldap-groups --- diff --git a/lib/pp_admintools/app/__init__.py b/lib/pp_admintools/app/__init__.py index 8a71eed..aa899de 100644 --- a/lib/pp_admintools/app/__init__.py +++ b/lib/pp_admintools/app/__init__.py @@ -39,7 +39,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.10.0' +__version__ = '0.10.1' # ============================================================================= @@ -218,7 +218,7 @@ class BaseDPXApplication(FbConfigApplication): def check_output_file(self, ofile, must_exists=False, must_absolute=False): """Check all nessacary thinks about an output file, before it can be used.""" if ofile is None: - msg = _('The output file to chack must not be None.') + msg = _('The output file to check must not be None.') raise TypeError(msg) ofile = Path(ofile) diff --git a/lib/pp_admintools/app/clean_empty_ldap_groups.py b/lib/pp_admintools/app/clean_empty_ldap_groups.py index 45f8f7e..5355da0 100644 --- a/lib/pp_admintools/app/clean_empty_ldap_groups.py +++ b/lib/pp_admintools/app/clean_empty_ldap_groups.py @@ -27,7 +27,7 @@ from .ldap import BaseLdapApplication from .. import pp from ..xlate import XLATOR -__version__ = '0.5.1' +__version__ = '0.6.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -60,6 +60,7 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication): self._base_dn = None self.instance = None self.connect_info = None + self.only_one = False list_oc = format_list(self.group_object_classes, do_repr=True) list_attr = format_list(self.member_attributes, do_repr=True) @@ -110,6 +111,19 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication): return res + # ------------------------------------------------------------------------- + def init_arg_parser(self): + """Public available method to initiate the argument parser.""" + group_title = _('Options for {}').format(self.appname) + app_group = self.arg_parser.add_argument_group(group_title) + + app_group.add_argument( + '-1', '--one', dest='only_one', action='store_true', + help=_('Delete only the first found empty group and exit.'), + ) + + super(CleanEmptyLdapGroupsApplication, self).init_arg_parser() + # ------------------------------------------------------------------------- def _verify_instances(self): @@ -121,6 +135,10 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication): """Execute some steps before calling run().""" super(CleanEmptyLdapGroupsApplication, self).post_init() + only_one = getattr(self.args, 'only_one', False) + if only_one: + self.only_one = True + self.check_instances() self.instance = self.ldap_instances[0] @@ -172,6 +190,8 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication): msg = _('Lap {} on searching for empty groups to remove.').format(i) LOG.info(msg) self.remove_empty_groups() + if self.only_one: + break # ------------------------------------------------------------------------- def get_empty_groups(self): @@ -198,6 +218,8 @@ class CleanEmptyLdapGroupsApplication(BaseLdapApplication): """Ask for removing and remove it then.""" for dn in self.dns_todo: self.remove_empty_group(dn) + if self.only_one: + break # ------------------------------------------------------------------------- def remove_empty_group(self, dn):