-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldif2csv.py
47 lines (40 loc) · 1.63 KB
/
ldif2csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# LDIF to CSV Converter
import csv
import sys
# Skip entries
skip = [ "dn", "loginShell","gid", "cn",
"userPassword","uidNumber", "gidNumber",
"homeDirectory", "displayName",
"objectClass", "uidNumber" ]
# CSV Header
header = [ "First Name", "Last Name", "Login ID", "Mobile No.",
"Email ID", "Profile", "Password Policy (y/n)" ]
def write_file():
with open('ldif.csv','wb') as output_file:
with open(inputfile) as input_file:
writer = csv.writer(output_file,
quoting=csv.QUOTE_MINIMAL)
writer.writerow(header)
myrow = []
for line in input_file:
if not line.strip():
writer.writerow(myrow)
myrow = []
continue
atribute, value = line.split(":")
if atribute in skip: continue
if 'pwdPolicySubentry' == atribute:
value = "Yes"
else:
pass #myrow.append(value.strip())
myrow.append(value.strip())
writer.writerow(myrow)
if __name__ == '__main__':
if len(sys.argv) != 2:
print "\nUsage\n\t{0} <ldif_file>\n".format(sys.argv[0])
raise SystemExit(1)
else:
inputfile = sys.argv[1]
write_file()
print "Exported in file : ldif.csv"