#!/usr/bin/python # This script extract a list of contributors from ldap # It prints the result on stderr # run ./ldap-names.py 2> list.txt import sys import os import random from getpass import getpass, getuser try: import ldap except ImportError, e: print "Please install python-ldap before running this program" sys.exit(1) basedn="dc=mageia,dc=org" peopledn="ou=people,%s" % basedn uris=['ldap://ldap.mageia.org:389'] random.shuffle(uris) uri = " ".join(uris) timeout=5 def print_group(ld, groupname, grouptxt): filter="(&(objectClass=inetOrgPerson)(cn=*)(memberOf=cn=" + groupname + ",ou=Group,dc=mageia,dc=org))" res = ld.search_s(peopledn, ldap.SCOPE_ONELEVEL, filter, ['uid','cn','uidNumber','gidNumber']) d = {} for result in res: dn, entry = result d[entry['cn'][0]] = grouptxt + ' | ' + entry['cn'][0] + ' <' + entry['uid'][0] + '>' for key in sorted(d.iterkeys()): print >> sys.stderr, d[key] if len(sys.argv) != 1: sys.exit(1) try: ld = ldap.initialize(uri) ld.set_option(ldap.OPT_NETWORK_TIMEOUT, timeout) ld.set_option(ldap.OPT_X_TLS_ALLOW, True) ld.start_tls_s() binddn = "uid=%s,%s" % (getuser(),peopledn) bindpw = getpass("Please enter password for %s (hit ENTER if another user): " % binddn) if bindpw == '': u = raw_input("Enter login name: ") binddn = "uid=%s,%s" % (u, people) bindpw = getpass("Password for %s: " % binddn) ld.bind_s(binddn, bindpw) print_group(ld, 'mga-packagers-committers', 'Packager') print_group(ld, 'mga-i18n', 'Translator') print_group(ld, 'mga-web', 'Web') print_group(ld, 'mga-sysadmin', 'Sysadmin') print_group(ld, 'mga-qa', 'Quality Assurance') ld.unbind_s() except Exception, e: print "Error" raise sys.exit(0) # vim:ts=4:sw=4:et:ai:si