Added console app
authorDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Fri, 11 Jan 2008 04:59:25 +0000 (23:59 -0500)
committerDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Fri, 11 Jan 2008 04:59:25 +0000 (23:59 -0500)
* Added 'ceo --help' stub
* Added 'ceo memberlist' command

bin/ceo
ceo/console/__init__.py [new file with mode: 0644]
ceo/console/main.py [new file with mode: 0644]
ceo/main.py [new file with mode: 0644]
ceo/urwid/main.py

diff --git a/bin/ceo b/bin/ceo
index 727f974..0a7e84f 100755 (executable)
--- 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 (file)
index 0000000..2d956cc
--- /dev/null
@@ -0,0 +1 @@
+"""Console Interface"""
diff --git a/ceo/console/main.py b/ceo/console/main.py
new file mode 100644 (file)
index 0000000..0fb3528
--- /dev/null
@@ -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 (file)
index 0000000..9830e18
--- /dev/null
@@ -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)
index f34f190..d604073 100644 (file)
@@ -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()