add command line parsing to generate-ldap-users
This commit is contained in:
parent
ecf6af37bf
commit
510eda7895
|
@ -1,11 +1,25 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
import optparse
|
||||
import os
|
||||
import ldap
|
||||
import sys
|
||||
|
||||
ldap_conn = ldap.initialize('ldap://ldap.pcf.be')
|
||||
ldap_conn.simple_bind_s('cn=ldap,ou=ouAdmin,ou=ouUsers,dc=win,dc=info,dc=pcf', sys.argv[1])
|
||||
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--template', dest='template_filename', default='ocrloader.ini')
|
||||
parser.add_option('--output', dest='output_filename',
|
||||
default='ocrloader-complete.ini')
|
||||
parser.add_option('--ldap-uri', dest='ldap_uri', default='ldap://ldap.pcf.be')
|
||||
parser.add_option('--binddn', dest='binddn',
|
||||
default='cn=ldap,ou=ouAdmin,ou=ouUsers,dc=win,dc=info,dc=pcf')
|
||||
parser.add_option('--bindpw', dest='bindpw')
|
||||
(options, args) = parser.parse_args()
|
||||
if not options.bindpw:
|
||||
parser.error('Missing LDAP bind password')
|
||||
|
||||
ldap_conn = ldap.initialize(options.ldap_uri)
|
||||
ldap_conn.simple_bind_s(options.binddn, options.bindpw)
|
||||
|
||||
usernames = []
|
||||
|
||||
|
@ -21,8 +35,8 @@ for entry in ldap_conn.search_s("dc=win,dc=info,dc=pcf", ldap.SCOPE_SUBTREE, "ob
|
|||
continue
|
||||
usernames.append(username)
|
||||
|
||||
fd = file('ocrloader-complete.ini', 'w')
|
||||
print >> fd, file('ocrloader.ini').read()
|
||||
fd = file(options.output_filename, 'w')
|
||||
print >> fd, file(options.template_filename).read()
|
||||
|
||||
for username in usernames:
|
||||
print username
|
||||
|
|
Reference in New Issue