Resolves issue where CEO would not start
[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
8
9 def start():
10     try:
11         if len(sys.argv) == 1:
12           print "Reading config file...",
13           members.configure()
14
15           print "Connecting to LDAP..."
16           members.connect(AuthCallback())
17
18           ceo.urwid.main.start()
19         else:
20           members.configure()
21           members.connect(AuthCallback())
22           ceo.console.main.start()
23     except ldap.LOCAL_ERROR, e:
24         print ldapi.format_ldaperror(e)
25     except ldap.INSUFFICIENT_ACCESS, e:
26         print ldapi.format_ldaperror(e)
27         print "You probably aren't permitted to do whatever you just tried."
28         print "Admittedly, ceo probably shouldn't have crashed either."
29
30 class AuthCallback:
31     def callback(self, error):
32         try:
33             print "Password: ",
34             return getpass("")
35         except KeyboardInterrupt:
36             print ""
37             sys.exit(1)
38
39 if __name__ == '__main__':
40     start()