summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-07 13:56:01 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-07 13:56:01 +0000
commita8c1bbcb6b20d60926be7b80dda0c6d77871b600 (patch)
tree782e34a2457d3a4aedea0a0876890a28550cd49a
parent5660589ce87e80f0a4bf58d19802a758329b8ff5 (diff)
downloadpykolab-a8c1bbcb6b20d60926be7b80dda0c6d77871b600.tar.gz
Add the normalization for dictionaries to utils, as it proves useful in more then just LDAP result normalization.
Also add the conversion between a domain name space and a standard root dn distilled from that domain name space
-rw-r--r--pykolab/utils.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index c784bf9..9a92ab3 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -4,6 +4,7 @@ import getpass
import os
from pykolab import constants
+from pykolab.translate import _
def ask_question(question, default="", password=False):
"""
@@ -70,6 +71,32 @@ def ask_confirmation(question, default="y", all_inclusive_no=True):
answer = False
print >> sys.stderr, _("Please answer 'yes' or 'no'.")
+def normalize(_dictionary):
+ dictionary = {}
+
+ for key in _dictionary.keys():
+ if type(_dictionary[key]) == list:
+ if len(_dictionary[key]) == 1:
+ dictionary[key.lower()] = ''.join(_dictionary[key])
+ else:
+ dictionary[key.lower()] = _dictionary[key]
+ else:
+ # What the heck?
+ dictionary[key.lower()] = _dictionary[key]
+
+ if dictionary.has_key('sn'):
+ dictionary['surname'] = dictionary['sn'].replace(' ', '')
+
+ if dictionary.has_key('mail'):
+ if len(dictionary['mail']) > 0:
+ if len(dictionary['mail'].split('@')) > 1:
+ dictionary['domain'] = dictionary['mail'].split('@')[1]
+
+ if not dictionary.has_key('domain') and dictionary.has_key('standard_domain'):
+ dictionary['domain'] = dictionary['standard_domain']
+
+ return dictionary
+
def parse_input(_input, splitchars= [ ' ' ]):
"""
Split the input string using the split characters defined
@@ -103,6 +130,9 @@ def pop_empty_from_list(_input_list):
if not item == '':
_output_list.append(item)
+def standard_root_dn(domain):
+ return 'dc=%s' %(',dc='.join(domain.split('.')))
+
def is_service(services):
"""
Checks each item in list services to see if it has a RC script in