]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding new command line option '--one' to bin/clean-empty-ldap-groups
authorFrank Brehm <frank@brehm-online.com>
Tue, 30 Jul 2024 12:39:22 +0000 (14:39 +0200)
committerFrank Brehm <frank@brehm-online.com>
Tue, 30 Jul 2024 12:39:22 +0000 (14:39 +0200)
lib/pp_admintools/app/__init__.py
lib/pp_admintools/app/clean_empty_ldap_groups.py

index 8a71eedd4b14b0bad853bf6a7ecd9a985e2dbf07..aa899dedecfdf2a25494a36a7d54873e1607cccc 100644 (file)
@@ -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)
index 45f8f7e57c47f5ee4f5dc145f43244aef46ad358..5355da09a144c9a616e21416ccab807860fb5921 100644 (file)
@@ -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):