Fix deadlock bug when daemonizing
[mspang/pyceo.git] / ceo / main.py
1 import sys, ldap
2 from getpass import getpass
3 import ceo.urwid.main
4 import ceo.console.main
5 from ceo import ldapi, members, library
6
7 def start():
8     try:
9         print "Reading config file...",
10         #XXX this should really all be done through one big config file
11         members.configure()
12         library.configure() 
13         print "read."
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)