From 53e4159ec955c260b478b50bdd3c8e0b0495412f Mon Sep 17 00:00:00 2001 From: kakwa Date: Mon, 13 Jul 2015 10:18:17 +0200 Subject: [PATCH] simpler way to fill group hash in modify if key don't exist --- ldapcherry/__init__.py | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index 2ff8848..eabbc06 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -746,14 +746,10 @@ class LdapCherry(object): groups_add = self.roles.get_groups(roles_member) for b in groups_add: - if b not in groups_add: - groups_add[b] = [] - if b not in groups_keep: - groups_keep[b] = [] - if b not in groups_current: - groups_current[b] = [] - if b not in lonely_groups: - lonely_groups[b] = [] + for g in [groups_add, groups_keep, + groups_current, lonely_groups]: + if b not in g: + g[b] = [] tmp = \ Set(groups_add[b]) - \ Set(groups_keep[b]) - \ @@ -766,18 +762,10 @@ class LdapCherry(object): ) self.backends[b].add_to_groups(username, tmp) for b in groups_rm: - if b not in groups_remove: - groups_remove[b] = [] - if b not in groups_rm: - groups_rm[b] = [] - if b not in groups_add: - groups_add[b] = [] - if b not in groups_keep: - groups_keep[b] = [] - if b not in groups_current: - groups_current[b] = [] - if b not in lonely_groups: - lonely_groups[b] = [] + for g in [groups_remove, groups_rm, groups_add, + groups_keep, groups_current, lonely_groups]: + if b not in g: + g[b] = [] tmp = \ ( (Set(groups_rm[b]) | Set(groups_remove[b])) -