I am using the python LDIF parser (link) to edit some attributes and generate a modified version of the file.
My LDIF file is
# entry-id: 1
dn: cn=Directory Administrators, dc=organization,dc=corp
nsUniqueId: 2947f1b3-1dd211b2-80b89250-3a51c428
objectClass: top
objectClass: groupofuniquenames
cn: Directory Administrators
creatorsName: cn=directory manager
modifiersName: cn=directory manager
createTimestamp: 20151110180921Z
modifyTimestamp: 20151110180921Z
# entry-id: 2
dn: cn=214-All-Matrix-100342-ALXD,ou=groups,dc=organization,dc=corp
modifyTimestamp: 20190905182416Z
modifiersName: cn=directory manager
owner: uid=hwuebker,ou=people,dc=organization,dc=corp
nsUniqueId: 4350c83d-1dd211b2-80a59250-3a51c428
uniqueMember: uid=anthonys,ou=people,dc=organization,dc=corp
GroupType: Core
Application: AppUID
adminGroupAdmin: cn=IDM System Managers,ou=groups,dc=organization,dc=corp
# entry-id: 3
dn: uid=twalsh,ou=people,dc=organization,dc=corp
nsUniqueId: 3df58701-1dd211b2-80489250-3a51c428
modifyTimestamp: 20180606194655Z
modifiersName: cn=directory manager
initials: 1
Document: 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAAC
AAAAAQAAAAAAAAAAEAAAAgAAAAIAAAD+////AAAAAAAAAACAAAAA////////////////////////
/////////////////////////////////////////////////////////AAAAAA==
Document: RE E-mail details .msg
My Python Code sofar for LDIF parser is
parser = MyLDIF(open(fileName, 'rb'), sys.stdout)
parser.parse()
#LDIF Parser go through records
for dn, entry in parser.parse():
Doc = entry['Document']
uidList= entry['uid']
uid = uidList[0]
DocValue = Doc[0]
DocSource = Doc[1]
writer = LDIFWriter(open("data.ldif", "ab"))
writer.unparse(dn, {
"nsUniqueId": entry['nsUniqueId'],
"Docs": entry['Document'],
})
As the 1st & 2nd entry doesn't have a DOCUMENT attribute, this throws an error.
Doc = entry['Document']
KeyError: 'Document'
How can I manipulate the 3rd entry while copying the 1st and 2nd entry without any changes?