aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelley Spoon <kelley.spoon@linaro.org>2018-12-21 15:24:28 -0600
committerKelley Spoon <kelley.spoon@linaro.org>2018-12-27 12:34:54 +0000
commitf3e4f4bb8a5deff92bc371bd6bb1e06b8ae8e912 (patch)
treebc9588dde550d72bd2a80acdd1bf433ccbc8564c
parent3a06fa8eae18e3fed5d319a6f15877f35ea7c307 (diff)
downloadlinaro-git-tools-f3e4f4bb8a5deff92bc371bd6bb1e06b8ae8e912.tar.gz
MemberList: generate an identities.yaml file for Members from LDAPHEADmaster
This script builds an identities.yaml file for Member user accounts in our LDAP database. Change-Id: Id20ba6ed8f1937d24bcd6cbdc5e1f2a19214ca9e
-rwxr-xr-xmember_list.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/member_list.py b/member_list.py
new file mode 100755
index 0000000..6e8cb01
--- /dev/null
+++ b/member_list.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+
+import linaro_ldap
+import yaml
+from jinja2 import Template
+import os
+
+OUTFILE = "member-identities.yaml"
+
+if os.path.isfile(OUTFILE):
+ os.unlink(OUTFILE)
+
+tmpl = Template(u'''\
+- profile:
+ name: {{ username }}
+ enrollments:
+ - organization: {{ org }}
+ email:
+ - {{ email }}
+
+''')
+
+def getKey(item):
+ return item[0]
+
+def getPersonKey(item):
+ try:
+ return item[1]['gecos'][0].lstrip()
+ except KeyError:
+ return "None"
+
+def get_member_ous(ldap):
+ result = ldap.do_complex_query( search_filter='(organizationalStatus=*)', attrlist=['ou','description'])
+
+ member_list = []
+ for x in result:
+ member_list.append( (x[1]['description'][0], x[1]['ou'][0]) )
+
+ member_list = sorted(member_list, key=getKey)
+ return member_list
+
+
+member_ou_list = get_member_ous(linaro_ldap)
+
+for member in member_ou_list:
+ people = linaro_ldap.do_complex_query( \
+ base = 'ou=%s,ou=accounts,dc=linaro,dc=org' % member[1], \
+ search_filter='(objectClass=inetOrgPerson)', \
+ attrlist=['uid','gecos','mail'])
+
+ s_people = sorted(people, key=getPersonKey)
+
+ for person in s_people:
+ try:
+ uid = person[1]['gecos'][0]
+ email = person[1]['mail'][0]
+ foo = tmpl.render(
+ username=uid,
+ org=member[0],
+ email=email
+ )
+ with open( OUTFILE, 'a') as outfile:
+ outfile.write(foo)
+ except KeyError:
+ pass