def create_user(ldap_server, user):
    old_user = find_user(ldap_server, config, user['USER_NAME'])

    if old_user is None:
        user['USER_ID'] = str(get_free_user_id(ldap_server))
        user['USER_UID'] = str(uuid.uuid4())
    else:
        user['USER_ID'] = old_user['uidNumber'][0]
        user['USER_UID'] = old_user['apple-generateduid'][0]

    group = find_group(l, config, user['USER_GROUP_NAME'])
    user['USER_GROUP_ID'] = group['gidNumber'][0]

    user['USER_PASSWORD_HASH'] = "{KERBEROS} " + user['USER_NAME']

    t = Template("../../config/plab-ldap/templates/user.ldif")
    t.replace(config)
    t.replace(user)
    insert_ldif(ldap_server, str(t))

    add_to_group(ldap_server, config, user['USER_NAME'], user['USER_GROUP_NAME'])

    # Get user and show details
    group = find_group(ldap_server, config, user['USER_GROUP_NAME'])
    user = find_user(ldap_server, config, user['USER_NAME'])

    pp = pprint.PrettyPrinter(indent = 4)

    print "Added user (" + user['uid'][0] + ") with id (" + str(user['uidNumber']) + ")"
from config import config
from template import Template
from ldap_utils import init_ldap, insert_ldif, add_to_group, find_user, find_group

import uuid

l = init_ldap(config)

group = {}
group['GROUP_NAME'] = 'admin'
group['GROUP_ID'] = '1100'
group['GROUP_LONGNAME'] = 'Administrators'
group['GROUP_UID'] = str(uuid.uuid4())

t = Template("../../config/plab-ldap/templates/group.ldif")
t.replace(config)
t.replace(group)
insert_ldif(l, str(t))


group = {}
group['GROUP_NAME'] = 'user'
group['GROUP_ID'] = '1101'
group['GROUP_LONGNAME'] = 'Users'
group['GROUP_UID'] = str(uuid.uuid4())

t = Template("../../config/plab-ldap/templates/group.ldif")
t.replace(config)
t.replace(group)
insert_ldif(l, str(t))