From f0384baf43934fb81a7eb2e6e7b721c2126265de Mon Sep 17 00:00:00 2001
From: Maxi Schulz <maximilian.schulz@hs-hannover.de>
Date: Fri, 10 Oct 2014 16:20:51 +0200
Subject: [PATCH] [TASK] Improves ldap loader update logging

---
 hshetl/loaders.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/hshetl/loaders.py b/hshetl/loaders.py
index 6324758..5e871e2 100644
--- a/hshetl/loaders.py
+++ b/hshetl/loaders.py
@@ -382,10 +382,10 @@ class LdapLoader(AbstractLoader):
             attributes = modlist.modifyModlist(old_entity_dict, entity_dict)
             try:
                 if self.dry:
-                    logging.info('Would modify dn {} with {} '.format(dn, str(attributes)))
+                    logging.info('Would modify dn {} with {} '.format(dn, self._generate_modify_logging(attributes, old_entity_dict, entity_dict)))
                 else:
                     connection.modify_s(dn, attributes)
-                    logging.info('Modified dn {} with {} '.format(dn, str(attributes)))
+                    logging.info('Modified dn {} with {} '.format(dn, self._generate_modify_logging(attributes, old_entity_dict, entity_dict)))
             except Exception, e:
                 logging.warn('Update failed for dn \'' + dn + '\': ' + str(e))
 
@@ -438,3 +438,14 @@ class LdapLoader(AbstractLoader):
             elif element == None:
                 data[key] = ''
         return data
+
+    def _generate_modify_logging(self, attributes, old, new):
+        '''Generates a nicer representation of the executed query than str(attributes) would'''
+        changed_attributes = []
+        output = ''
+        for operation in attributes:
+            if operation[1] not in changed_attributes:
+                changed_attributes.append(operation[1])
+        for attribute in changed_attributes:
+            output += attribute + ': ' + old[attribute] + ' -> ' + new[attribute] + ', '
+        return output[:-2]
-- 
GitLab