I am having a difficult time splitting an LDIF file with thousands of entries into multiple dictionaries. For example, my LDIF file looks like:
dn: value
ou: value
objectClass: value
entryUUID: value
creatorname: value
entryNNN: value
modifierName: value
modifyTimestamp: value
dn: value
ou: value
…
…
…
What I would like to do is separate lines starting with "dn:" and every line under into separate dictionaries. For Example:
ldap_core_record_1 = {'dn:': 'value', 'ou:': 'value',...}
ldap_core_record_2 = {'dn:': 'value', 'ou:': 'value',...}
Here's the code I have so far:
def parse_LDAP_Core_Schema():
LDAP_CORE_LIST = []
LDAP_CORE_DICT = {}
LDAP_CORE_FILE = '/…/…/…/…/ldap_core_backup.ldif' """This is the LDAP generated from slapcat"""
with open(LDAP_CORE_FILE, 'r') as LDAP_CORE_OBJECT:
LDAP_CORE_LIST = LDAP_CORE_OBJECT.readlines()
for line in LDAP_CORE_LIST:
if line.startswith("dn: "):
From there, I'm stumped. I don't know how to properly splice a List as I've only been using Python for a short while. I'm using Python 3.4.2 unfortunately.