Kill Bartle's hybrid main.py
[mspang/pyceo.git] / bin / ceo
1 #!/usr/bin/python
2
3 import sys, ldap
4 from getpass import getpass
5 import ceo.urwid.main
6 import ceo.console.main
7 from ceo import ldapi, members, library
8
9 def start():
10     try:
11         print "Reading config file...",
12         members.configure()
13         library.configure()
14
15         print "Connecting to LDAP..."
16         members.connect(AuthCallback())
17
18         if len(sys.argv) == 1:
19           ceo.urwid.main.start()
20         else:
21           ceo.console.main.start()
22     except ldap.LOCAL_ERROR, e:
23         print ldapi.format_ldaperror(e)
24     except ldap.INSUFFICIENT_ACCESS, e:
25         print ldapi.format_ldaperror(e)
26         print "You probably aren't permitted to do whatever you just tried."
27         print "Admittedly, ceo probably shouldn't have crashed either."
28
29 class AuthCallback:
30     def callback(self, error):
31         try:
32             print "Password: ",
33             return getpass("")
34         except KeyboardInterrupt:
35             print ""
36             sys.exit(1)
37
38 if __name__ == '__main__':
39     start()