Re-build so debian.csclub include library as a dependency
[public/pyceo-broken.git] / ceo / urwid / shell.py
1 import urwid, ldap, pwd, os
2 from ceo import members, terms, ldapi
3 from ceo.urwid.widgets import *
4 from ceo.urwid.window import *
5
6 class IntroPage(WizardPanel):
7     def init_widgets(self):
8         self.widgets = [
9             urwid.Text( "Changing Login Shell" ),
10             urwid.Divider(),
11             urwid.Text( "You can change your shell here. Request more shells "
12                         "by emailing systems-committee." )
13         ]
14     def focusable(self):
15         return False
16
17 class YouPage(WizardPanel):
18     def init_widgets(self):
19         you = pwd.getpwuid(os.getuid()).pw_name
20         self.userid = LdapWordEdit(csclub_uri, csclub_base, 'uid',
21             "Username: ", you)
22
23         self.widgets = [
24             urwid.Text( "Member Information" ),
25             urwid.Divider(),
26             self.userid,
27         ]
28     def check(self):
29         self.state['userid'] = self.userid.get_edit_text()
30         self.state['member'] = None
31         if self.state['userid']:
32             self.state['member'] = members.get(self.userid.get_edit_text())
33         if not self.state['member']:
34             set_status("Member not found")
35             self.focus_widget(self.userid)
36             return True
37
38 class ShellPage(WizardPanel):
39     def init_widgets(self):
40         self.midtext = urwid.Text("")
41
42         self.widgets = [
43             urwid.Text("Choose a Shell"),
44             urwid.Divider(),
45         ]
46
47         def set_shell(radio_button, new_state, shell):
48             if new_state:
49                 self.state['shell'] = shell
50
51         radio_group = []
52         self.shells = members.get_shells()
53         self.shellw = [ urwid.RadioButton(radio_group, shell,
54             on_state_change=set_shell, user_data=shell)
55             for shell in self.shells ]
56
57         self.widgets.extend(self.shellw)
58     def set_shell(self, shell):
59         i = self.shells.index(shell)
60         self.shellw[i].set_state(True)
61     def focusable(self):
62         return True
63     def activate(self):
64         self.set_shell(self.state['member']['loginShell'][0])
65
66 class EndPage(WizardPanel):
67     def init_widgets(self):
68         self.headtext = urwid.Text("")
69         self.midtext = urwid.Text("")
70
71         self.widgets = [
72             self.headtext,
73             urwid.Divider(),
74             self.midtext,
75         ]
76     def focusable(self):
77         return False
78     def activate(self):
79         problem = None
80         try:
81             user, shell = self.state['userid'], self.state['shell']
82             members.set_shell(user, shell)
83             self.headtext.set_text("Login Shell Changed")
84             self.midtext.set_text("The shell for %s has been changed to %s."
85                                   % (user, shell))
86         except ldap.LDAPError, e:
87             problem = ldapi.format_ldaperror(e)
88         except members.MemberException, e:
89             problem = str(e)
90         if problem:
91             self.headtext.set_text("Failed to Change Shell")
92             self.midtext.set_text("Perhaps you don't have permission to change %s's shell? "
93                     "The error was:\n\n%s" % (user, problem))
94     def check(self):
95         pop_window()