Add mysql database stuff
[mspang/pyceo.git] / ceo / urwid / main.py
index e852dfa..ba877f4 100644 (file)
@@ -1,8 +1,8 @@
-import sys, random, urwid.curses_display
+import os, grp, pwd, 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, library
+    shell, library, databases
 
 ui = urwid.curses_display.Screen()
 
@@ -59,7 +59,7 @@ def new_member(*args, **kwargs):
         newmember.SignPage,
         newmember.PassPage,
         newmember.EndPage,
-    ])
+    ], (60, 15))
 
 def new_club(*args, **kwargs):
     push_wizard("New Club Account", [
@@ -87,15 +87,19 @@ def renew_member(*args, **kwargs):
     push_wizard("Renew Membership", [
         renew.IntroPage,
         renew.UserPage,
+        renew.EmailPage,
+        renew.EmailDonePage,
         renew.TermPage,
         renew.PayPage,
         renew.EndPage,
-    ])
+    ], (60, 15))
 
 def renew_club_user(*args, **kwargs):
     push_wizard("Renew Club Rep Account", [
         renew.ClubUserIntroPage,
         renew.UserPage,
+        renew.EmailPage,
+        renew.EmailDonePage,
         (renew.TermPage, "clubuser"),
         (renew.EndPage, "clubuser"),
     ], (60, 15))
@@ -107,15 +111,13 @@ def display_member(data):
     ], (60, 15))
 
 def search_members(data):
-    menu = [
+    menu = make_menu([
         ("Members by term", search_term, None),
         ("Members by name", search_name, None),
         ("Members by group", search_group, None),
         ("Back", raise_back, None),
-    ]
-
-    listbox = urwid.ListBox( menu_items( menu ) )
-    push_window(listbox, "Search")
+    ])
+    push_window(menu, "Search")
 
 def search_name(data):
     push_wizard("By Name", [ search.NamePage ])
@@ -141,25 +143,67 @@ def change_shell(data):
         shell.EndPage
     ], (50, 20))
 
-def run():
-    menu = make_menu([
+def create_mysql_db(data):
+    push_wizard("Create MySQL database", [
+        databases.IntroPage,
+        databases.UserPage,
+        databases.EndPage,
+    ], (60, 15))
+
+def check_group(group):
+    try:
+        me = pwd.getpwuid(os.getuid()).pw_name
+        return me in grp.getgrnam(group).gr_mem
+    except KeyError:
+        pass
+
+def top_menu():
+    office_only = [
         ("New Member", new_member, None),
         ("New Club Rep", new_club_user, None),
         ("Renew Membership", renew_member, None),
         ("Renew Club Rep", renew_club_user, None),
         ("New Club", new_club, None),
-        ("Display Member", display_member, None),
-        ("Change Shell", change_shell, None),
-        ("Search", search_members, None),
+        ("Library", library.library, None),
+    ]
+    syscom_only = [
         ("Manage Club or Group Members", manage_group, None),
         ("Manage Positions", manage_positions, None),
         ("Manage Office Staff", groups.group_members, office_data),
         ("Manage Systems Committee", groups.group_members, syscom_data),
-        ("Library", library.library, None),
+    ]
+    unrestricted = [
+        ("Display Member", display_member, None),
+        ("Search", search_members, None),
+        ("Change Shell", change_shell, None),
+        ("Create MySQL database", create_mysql_db, None),
+    ]
+    footer = [
         ("Exit", raise_abort, None),
-    ])
-    push_window( menu, program_name() )
-    event_loop( ui )
+    ]
+    menu = None
+
+    # reorder the menu for convenience
+    if not check_group('office') and not check_group('syscom'):
+        menu = labelled_menu([
+            ('Unrestricted', unrestricted),
+            ('Office Staff', office_only),
+            ('Systems Committee', syscom_only),
+            (None, footer)
+        ])
+    else:
+        menu = labelled_menu([
+            ('Office Staff', office_only),
+            ('Unrestricted', unrestricted),
+            ('Systems Committee', syscom_only),
+            (None, footer)
+        ])
+
+    return menu
+
+def run():
+    push_window(top_menu(), program_name())
+    event_loop(ui)
 
 def start():
     ui.run_wrapper( run )