source: trunk/debathena/debathena/moira-gui/xmoira @ 24608

Revision 24608, 6.7 KB checked in by broder, 14 years ago (diff)
In xmoira, prefer a glade file in the cwd to one installed globally. If someone is doing testing or development of xmoira, then any glade file in their current working directory is likely to be more current than the one installed with the package.
  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2
3
4import gtk
5import gtk.glade
6import os
7import sys
8import pwd
9import re
10
11moiraClientName = "xmoira"
12if os.path.exists("xmoira.glade"):
13    gladeFile = "xmoira.glade"
14else:
15    gladeFile = "/usr/share/debathena-moira-gui/xmoira.glade"
16
17import moira
18from _moira import MoiraException
19import mrclient
20
21class XMoira():
22    def __init__(self):
23        self.widgets = gtk.glade.XML(gladeFile)
24        self.window = self.widgets.get_widget("mainWindow")
25        self.widgets.signal_autoconnect(self)
26        self.clientName = moiraClientName
27        self.connected = False
28        try:
29            self.currentUser = mrclient.krb_user()
30        except mrclient.MoiraClientException:
31            self.errorDialog("Unable to obtain username from Kerberos.\nDo you have valid tickets?", True)
32            sys.exit(255) # We're not in a main loop, don't call gtk.main_quit()
33        self.window.show()
34        self.widgets.get_widget("lblUserName").set_text("User: " + self.currentUser)
35        self.staleTabs = {"tabChpobox": True,
36                          "tabChfn": True,
37                          "tabChsh": True}
38        self.tabCallbacks = {"tabChpobox": self.refreshChpoboxTab,
39                             "tabChfn": self.refreshChfnTab,
40                             "tabChsh": self.refreshChshTab}
41
42        self.radioBtnQueries = {"rbChpoboxPobox": ('spop', None),
43                                "rbChpoboxSplit": ('spob', 'SPLIT'),
44                                "rbChpoboxSmtp": ('spob', 'SMTP')}
45        self.pageChanged(self.widgets.get_widget("nbMain"), None, 0)
46
47
48    def errorDialog(self, errstr, fatal=False):
49        button = gtk.BUTTONS_OK
50        if fatal:
51            button = gtk.BUTTONS_CLOSE
52        msg = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
53                                gtk.MESSAGE_ERROR, button,
54                                "Error: %s" % errstr)
55        msg.set_title("Error")
56        msg.run()
57        msg.destroy()
58
59    def validateEmail(self, str):
60        try:
61            currUser = mrclient.krb_user()
62        except mrclient.MoiraClientException, e:
63            self.errorDialog(e.args[1])
64            return None
65        try:
66            validatedStr = mrclient.validate_pobox_smtp(currUser, str)
67        except mrclient.MoiraClientException, e:
68            self.errorDialog(e.args[1])
69            return None
70        return validatedStr
71
72    def applyChsh(self, button):
73        print self.widgets.get_widget('cbChshUnixShell').child.get_text()
74        print self.widgets.get_widget('cbChshWindowsShell').child.get_text()
75
76
77    def applyChfn(self, button):
78        argList = {}
79        for textEntry in self.widgets.get_widget_prefix("entChfn"):
80            mrfield = textEntry.name.replace('entChfn_', '')
81            argList[mrfield] = textEntry.get_text()
82        argList['login'] = self.currentUser
83        result = None
84        try:
85            result = moira.query('ufbl', None, **argList)
86        except MoiraException, e:
87            self.errorDialog(e.args[1])
88        if result == []:
89            msg = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
90                                    gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
91                                    "Your finger information has been updated.")
92            msg.set_title("Confirmation")
93            msg.run()
94            msg.destroy()
95           
96        self.refreshChfnTab()
97       
98    def applyChpobox(self, button):
99        for radioButton in self.widgets.get_widget_prefix("rbChpobox"):
100            if radioButton.get_active():
101                (query, type) = self.radioBtnQueries[radioButton.name]
102                textEntry = self.widgets.get_widget(radioButton.name.replace("rb", "ent"))
103                if not textEntry:
104                    self.errorDialog("You did not enter an e-mail address")
105                    return
106                validated = self.validateEmail(textEntry.get_text())
107                if not validated:
108                    return
109                if type == None:
110                    self.query(query, mrclient.krb_user())
111                else:
112                    self.query(query, self.currentUser, type, validated)
113                self.refreshChpoboxTab()
114
115
116    def chpoboxToggleHandler(self, button):
117        textEntry = self.widgets.get_widget(button.name.replace("rb", "ent"))
118        if textEntry != None:
119            textEntry.set_property("visible", button.get_active())
120
121    def refreshChfnTab(self):
122        gfbl = self.query('gfbl', self.currentUser)[0]
123        for textEntry in self.widgets.get_widget_prefix("entChfn"):
124            textEntry.set_text(gfbl[textEntry.name.replace('entChfn_', '')])
125        self.widgets.get_widget('lblChfnLastUpdated').set_text("Last modified %s by %s" % (gfbl['modtime'], gfbl['modby'].replace('@ATHENA.MIT.EDU', '')))
126
127    def refreshChshTab(self):
128        gual = self.query('gual', self.currentUser)[0]
129        self.widgets.get_widget('cbChshUnixShell').child.set_text(gual['shell'])
130        self.widgets.get_widget('cbChshWindowsShell').child.set_text(gual['winconsoleshell'])
131
132
133    def refreshChpoboxTab(self):
134        gpob = self.query('gpob', self.currentUser)[0]
135        english = " ".join((gpob['type'], gpob['address']))
136        if gpob['type'] == "IMAP" or gpob['type'] == "EXCHANGE":
137            english = "Your mail is not forwarded."
138        if gpob['type'] == "SMTP":
139            english = "Your mail is being forwarded to %s." % gpob['box']
140        if gpob['type'] == "SPLIT":
141            english = "Your mail is being split between your MIT account\nand %s." % gpob['box']
142        self.widgets.get_widget("lblChpoboxCurrentSetting").set_text(english)
143
144    def pageChanged(self, notebook, page, page_num):
145        tabName = notebook.get_nth_page(page_num).name
146        if not self.staleTabs[tabName]:
147            return
148        self.tabCallbacks[tabName]()
149        self.staleTabs[tabName] = False
150
151    def connect(self):
152        if self.connected:
153            return
154        moira.connect()
155        moira.auth(self.clientName)
156        self.connected = True
157
158    def query(self, query, *argList):
159        if not self.connected:
160            self.connect()
161        result = []
162        try:
163            result = moira.query(query, *argList)
164        except MoiraException, e:
165            msg = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
166                                    gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
167                                    "Error: %s" % e.args[1])
168            msg.set_title("Error")
169            msg.run()
170            msg.destroy()
171        return result
172           
173
174    def run(self):
175        gtk.main()
176
177    def quit(self, widget=None, event=None):
178        gtk.main_quit()
179
180if __name__ == "__main__":
181    if not os.path.exists(gladeFile):
182        print "Unable to load Glade file " + gladeFile
183        sys.exit(255)
184    xmoira = XMoira()
185    xmoira.run()
Note: See TracBrowser for help on using the repository browser.