From 5778d003c2a12959bd97d6c5fdce5d8100850a8a Mon Sep 17 00:00:00 2001 From: David Bartley Date: Thu, 10 Jan 2008 23:59:25 -0500 Subject: [PATCH] Added console app * Added 'ceo --help' stub * Added 'ceo memberlist' command --- bin/ceo | 4 ++-- ceo/console/__init__.py | 1 + ceo/console/main.py | 26 ++++++++++++++++++++++++++ ceo/main.py | 33 +++++++++++++++++++++++++++++++++ ceo/urwid/main.py | 25 ++----------------------- 5 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 ceo/console/__init__.py create mode 100644 ceo/console/main.py create mode 100644 ceo/main.py diff --git a/bin/ceo b/bin/ceo index 727f97411..0a7e84f26 100755 --- a/bin/ceo +++ b/bin/ceo @@ -1,3 +1,3 @@ #!/usr/bin/python -import ceo.urwid.main -ceo.urwid.main.start() +import ceo.main +ceo.main.start() diff --git a/ceo/console/__init__.py b/ceo/console/__init__.py new file mode 100644 index 000000000..2d956cc54 --- /dev/null +++ b/ceo/console/__init__.py @@ -0,0 +1 @@ +"""Console Interface""" diff --git a/ceo/console/main.py b/ceo/console/main.py new file mode 100644 index 000000000..0fb352842 --- /dev/null +++ b/ceo/console/main.py @@ -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' diff --git a/ceo/main.py b/ceo/main.py new file mode 100644 index 000000000..9830e1819 --- /dev/null +++ b/ceo/main.py @@ -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) diff --git a/ceo/urwid/main.py b/ceo/urwid/main.py index f34f19014..d6040736b 100644 --- a/ceo/urwid/main.py +++ b/ceo/urwid/main.py @@ -1,5 +1,4 @@ -import sys, random, ldap, urwid.curses_display, getpass -from ceo import members, ldapi +import sys, random, urwid.curses_display from ceo.urwid.widgets import * from ceo.urwid.window import * from ceo.urwid import newmember, renew, info, search, positions, groups, shell @@ -166,27 +165,7 @@ def run(): event_loop( ui ) def start(): - try: - 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) + ui.run_wrapper( run ) if __name__ == '__main__': start()