Added console app
[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
6
7 def start():
8     try:
9         if len(sys.argv) >= 2 and sys.argv[1] == '--help':
10           ceo.console.main.help()
11           sys.exit(0)
12
13         members.connect(AuthCallback())
14
15         if len(sys.argv) == 1:
16           ceo.urwid.main.start()
17         else:
18           ceo.console.main.start()
19     except ldap.LOCAL_ERROR, e:
20         print ldapi.format_ldaperror(e)
21     except ldap.INSUFFICIENT_ACCESS, e:
22         print ldapi.format_ldaperror(e)
23         print "You probably aren't permitted to do whatever you just tried."
24         print "Admittedly, ceo probably shouldn't have crashed either."
25
26 class AuthCallback:
27     def callback(self, error):
28         try:
29             sys.stderr.write("Password: ")
30             return getpass("")
31         except KeyboardInterrupt:
32             print ""
33             sys.exit(1)