Added console app
* Added 'ceo --help' stub * Added 'ceo memberlist' command
This commit is contained in:
parent
9d3119274b
commit
5778d003c2
4
bin/ceo
4
bin/ceo
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import ceo.urwid.main
|
import ceo.main
|
||||||
ceo.urwid.main.start()
|
ceo.main.start()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
"""Console Interface"""
|
|
@ -0,0 +1,26 @@
|
||||||
|
import sys
|
||||||
|
from getopt import getopt
|
||||||
|
from ceo import members, terms
|
||||||
|
|
||||||
|
shortopts = [
|
||||||
|
]
|
||||||
|
|
||||||
|
longopts = [
|
||||||
|
]
|
||||||
|
|
||||||
|
def start():
|
||||||
|
(opts, args) = getopt(sys.argv[1:], shortopts, longopts)
|
||||||
|
if len(args) == 1:
|
||||||
|
if args[0] == 'memberlist':
|
||||||
|
mlist = members.list_term(terms.current()).values()
|
||||||
|
for member in mlist:
|
||||||
|
print '%s %s %s' % (
|
||||||
|
member['uid'][0].ljust(12),
|
||||||
|
member['cn'][0].ljust(30),
|
||||||
|
member.get('program', [''])[0]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print "Invalid argument '%s'" % args[0]
|
||||||
|
|
||||||
|
def help():
|
||||||
|
print 'ceo memberlist'
|
|
@ -0,0 +1,33 @@
|
||||||
|
import sys, ldap
|
||||||
|
from getpass import getpass
|
||||||
|
import ceo.urwid.main
|
||||||
|
import ceo.console.main
|
||||||
|
from ceo import ldapi, members
|
||||||
|
|
||||||
|
def start():
|
||||||
|
try:
|
||||||
|
if len(sys.argv) >= 2 and sys.argv[1] == '--help':
|
||||||
|
ceo.console.main.help()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
members.connect(AuthCallback())
|
||||||
|
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
ceo.urwid.main.start()
|
||||||
|
else:
|
||||||
|
ceo.console.main.start()
|
||||||
|
except ldap.LOCAL_ERROR, e:
|
||||||
|
print ldapi.format_ldaperror(e)
|
||||||
|
except ldap.INSUFFICIENT_ACCESS, e:
|
||||||
|
print ldapi.format_ldaperror(e)
|
||||||
|
print "You probably aren't permitted to do whatever you just tried."
|
||||||
|
print "Admittedly, ceo probably shouldn't have crashed either."
|
||||||
|
|
||||||
|
class AuthCallback:
|
||||||
|
def callback(self, error):
|
||||||
|
try:
|
||||||
|
sys.stderr.write("Password: ")
|
||||||
|
return getpass("")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print ""
|
||||||
|
sys.exit(1)
|
|
@ -1,5 +1,4 @@
|
||||||
import sys, random, ldap, urwid.curses_display, getpass
|
import sys, random, urwid.curses_display
|
||||||
from ceo import members, ldapi
|
|
||||||
from ceo.urwid.widgets import *
|
from ceo.urwid.widgets import *
|
||||||
from ceo.urwid.window import *
|
from ceo.urwid.window import *
|
||||||
from ceo.urwid import newmember, renew, info, search, positions, groups, shell
|
from ceo.urwid import newmember, renew, info, search, positions, groups, shell
|
||||||
|
@ -166,27 +165,7 @@ def run():
|
||||||
event_loop( ui )
|
event_loop( ui )
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
try:
|
ui.run_wrapper( run )
|
||||||
print "Connecting...\n",
|
|
||||||
sys.stdout.flush()
|
|
||||||
members.connect(AuthCallback())
|
|
||||||
print "done."
|
|
||||||
|
|
||||||
ui.run_wrapper( run )
|
|
||||||
except ldap.LOCAL_ERROR, e:
|
|
||||||
print ldapi.format_ldaperror(e)
|
|
||||||
except ldap.INSUFFICIENT_ACCESS, e:
|
|
||||||
print ldapi.format_ldaperror(e)
|
|
||||||
print "You probably aren't permitted to do whatever you just tried."
|
|
||||||
print "Admittedly, ceo probably shouldn't have crashed either."
|
|
||||||
|
|
||||||
class AuthCallback:
|
|
||||||
def callback(self, error):
|
|
||||||
try:
|
|
||||||
return getpass.getpass("Password: ")
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print ""
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
start()
|
start()
|
||||||
|
|
Loading…
Reference in New Issue