Remove python-pam dependency
[mspang/pyceo.git] / bin / ceoquery
1 #!/usr/bin/python
2 """
3 ceoquery - a script to lookup member and account information
4 """
5 import os, sys
6 from ceo import members, terms
7
8 try:
9     members.connect()
10 except Exception, e:
11     print "ceoquery: %s" % e
12     sys.exit(1)
13
14 def usage():
15     print "Usage: ceoquery memberlist|termusers"
16
17 if len(sys.argv) < 2:
18     usage()
19
20 elif sys.argv[1] == 'memberlist':
21     
22     current_term = terms.current()
23     members = members.list_term(current_term)
24     for member in members.values():
25         if 'program' in member:
26             program = member['program'][0]
27         else:
28             program = ''
29         print "%s|%s|%s" % (member['cn'][0], program, member['uid'][0])
30
31 elif sys.argv[1] == 'allmembers':
32
33     pass
34
35 elif sys.argv[1] == 'booklist':
36
37     pass
38
39 elif sys.argv[1] == 'allusers':
40
41     pass
42
43 elif sys.argv[1] == 'termusers':
44
45     if len(sys.argv) > 2:
46         term = sys.argv[2]
47     else:
48         term = terms.current()
49
50     members = members.list_term(term)
51     for member in members:
52         print member
53
54 else:
55
56     usage()
57