# -*- coding: utf-8 -*-
"""
+@summary: An application module for evaluating duplicate attributes, which should be unique.
+
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
@copyright: © 2023 by Frank Brehm, Berlin
-@summary: An application module for evaluating duplicate attributes, which should be unique
"""
from __future__ import absolute_import
# Standard modules
-import logging
import copy
+import logging
import re
import sys
-
-from numbers import Number
-
from functools import cmp_to_key
+from numbers import Number
# Third party modules
from fb_tools.xlate import format_list
# Own modules
-from ..xlate import XLATOR
-
from .ldap import BaseLdapApplication
+from ..xlate import XLATOR
-__version__ = '0.3.3'
+__version__ = '0.3.4'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# -------------------------------------------------------------------------
def __init__(self, appname=None, base_dir=None):
- """Constructor."""
+ """Construct this application object."""
self.uniq_attributes = copy.copy(self.default_uniq_attributes)
self.dependend_uniq_attribs = copy.copy(self.default_dependend_uniq_attribs)
self.result = {}
self.connect_info = None
desc = _(
- "Evaluating all LDAP entries, which are using duplicate attributes, which "
- "should be unique.")
+ 'Evaluating all LDAP entries, which are using duplicate attributes, which '
+ 'should be unique.')
super(EvalDuplicateAttribsApplication, self).__init__(
appname=appname, description=desc, base_dir=base_dir,
eval_group.add_argument(
'-U', '--uniq-attribs', nargs='*', dest='uniq_attribs', metavar=_('ATTRIBUTE'),
help=_(
- "All attribute types, which should be unique over the complete LDAP tree. "
- "Per default the following attribute types should be unique:"
+ 'All attribute types, which should be unique over the complete LDAP tree. '
+ 'Per default the following attribute types should be unique:'
) + ' ' + format_list(self.default_uniq_attributes, do_repr=True),
)
eval_group.add_argument(
'--dependend-attribs', nargs='*', dest='dependend_attribs', metavar=_('ATTRIBUTE'),
help=_(
- "All attribute types, where their uniqueness depends on an additional "
+ 'All attribute types, where their uniqueness depends on an additional '
"LDAP filter. For instance, the attribute 'gidNumber' should be unique for "
"all entries, which are using the objectClass 'posixGroup'. The value "
"for this argument should be in the form: 'ATTRIBUTE: \"FILTER\"'. For the latter "
"example this would be: 'gidNumber: \"objectClass=posixGroup\"' (which "
- "is also the default for this option). Please note, that this filter will "
- "be wrapped by parenthesis.")
+ 'is also the default for this option). Please note, that this filter will '
+ 'be wrapped by parenthesis.')
)
super(EvalDuplicateAttribsApplication, self).init_arg_parser()
# -------------------------------------------------------------------------
def post_init(self):
- """
- Method to execute before calling run().
- """
-
+ """Execute this before calling run()."""
super(EvalDuplicateAttribsApplication, self).post_init()
pat_dep_attribs = r'^(?P<attrib>[a-z](?:[a-z0-9-]*[a-z0-9])?):\s*'
pat_dep_attribs += r'(?P<quote>[\'"])?(?P<filter>.+)(?P=quote)?$'
if self.verbose > 2:
- LOG.debug("Pattern for verifying dependend unique attributes: {!r}".format(
+ LOG.debug('Pattern for verifying dependend unique attributes: {!r}'.format(
pat_dep_attribs))
re_dep_attribs = re.compile(pat_dep_attribs, re.IGNORECASE)
dep_attribs[attr_name] = attr_filter
else:
wrong_attribs = True
- msg = _("Wrong definition for a filter dependend unique attribute given:")
+ msg = _('Wrong definition for a filter dependend unique attribute given:')
msg += ' {!r}'.format(attrib)
LOG.error(msg)
if wrong_attribs:
# -------------------------------------------------------------------------
def _run(self):
- LOG.info("And here we go ...")
+ LOG.info('And here we go ...')
for attrib in self.uniq_attributes:
self.empty_line()
print(' * {}'.format(dn))
self.empty_line()
else:
- print(_("No duplicates for attribute {!r} found.").format(attrib))
+ print(_('No duplicates for attribute {!r} found.').format(attrib))
self.empty_line()
# =============================================================================
-if __name__ == "__main__":
+if __name__ == '__main__':
pass