summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2014-03-31 11:18:05 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2014-03-31 11:18:05 (GMT)
commit510eda789540bfbc24ae95a7120e1c0b69227857 (patch)
tree631b6218607ccda7169addfd4441a3f85425d827
parentecf6af37bf6c739e92e52c02dedf4f5693e75791 (diff)
downloadpfwbged.ocrloader-510eda789540bfbc24ae95a7120e1c0b69227857.zip
pfwbged.ocrloader-510eda789540bfbc24ae95a7120e1c0b69227857.tar.gz
pfwbged.ocrloader-510eda789540bfbc24ae95a7120e1c0b69227857.tar.bz2
add command line parsing to generate-ldap-users
-rw-r--r--generate-ldap-users.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/generate-ldap-users.py b/generate-ldap-users.py
index 4f70f67..35b0591 100644
--- a/generate-ldap-users.py
+++ b/generate-ldap-users.py
@@ -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