~ubuntu-branches/ubuntu/vivid/openipmi/vivid

« back to all changes in this revision

Viewing changes to swig/python/openipmigui/_mc_pefparm.py

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2006-09-15 17:56:24 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060915175624-ljk0mg3xtcm65tvm
Tags: 2.0.7-1
* new upstream release from 2006-06-08
  Thanks to John Wright <john.wright hp.com> for initial work
  (closes: Bug#380149)
* updated Standards Version
* new binaries openipmicmd, openipmish, rmcp_ping

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# _mc_pefparm.py
 
2
#
 
3
# openipmi GUI handling for MC PEF parms
 
4
#
 
5
# Author: MontaVista Software, Inc.
 
6
#         Corey Minyard <minyard@mvista.com>
 
7
#         source@mvista.com
 
8
#
 
9
# Copyright 2005 MontaVista Software Inc.
 
10
#
 
11
#  This program is free software; you can redistribute it and/or
 
12
#  modify it under the terms of the GNU Lesser General Public License
 
13
#  as published by the Free Software Foundation; either version 2 of
 
14
#  the License, or (at your option) any later version.
 
15
#
 
16
#
 
17
#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
18
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
19
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
20
#  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 
21
#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
22
#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 
23
#  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
24
#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 
25
#  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 
26
#  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
#
 
28
#  You should have received a copy of the GNU Lesser General Public
 
29
#  License along with this program; if not, write to the Free
 
30
#  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
31
#
 
32
 
 
33
import sys
 
34
import OpenIPMI
 
35
import _oi_logging
 
36
import gui_errstr
 
37
import gui_list
 
38
import gui_popup
 
39
import gui_setdialog
 
40
 
 
41
class MCPEFData:
 
42
    def __init__(self, glist, pefc, parm, aidx, pname, ptype, origval):
 
43
        self.glist = glist
 
44
        self.pefc = pefc
 
45
        self.parm = parm
 
46
        self.aidx = aidx
 
47
        self.pname = pname
 
48
        self.ptype = ptype
 
49
        self.origval = origval
 
50
        self.currval = origval
 
51
        return
 
52
 
 
53
    def SetItem(self, idx):
 
54
        self.idx = idx;
 
55
        return
 
56
 
 
57
    def HandleMenu(self, event, idx, point):
 
58
        if (self.ptype == "bool"):
 
59
            menul = [ ("Toggle Value", self.togglevalue) ]
 
60
        elif (self.ptype == "enum"):
 
61
            menul = [ ]
 
62
            nval = [ 0 ]
 
63
            sval = [ "" ]
 
64
            val = 0;
 
65
            while (val != -1):
 
66
                rv = OpenIPMI.pefconfig_enum_val(self.parm, val, nval, sval)
 
67
                if (rv == 0):
 
68
                    menul.append( (sval[0] + " (" + str(val) + ")",
 
69
                                   self.setenum,
 
70
                                   val) )
 
71
                    pass
 
72
                val = nval[0];
 
73
                pass
 
74
            pass
 
75
        else:
 
76
            menul = [ ("Set Value", self.setvalue) ]
 
77
            pass
 
78
        gui_popup.popup(self.glist, event, menul, point)
 
79
        return
 
80
 
 
81
    def ok(self, vals):
 
82
        rv = self.pefc.set_val(self.parm, self.aidx, self.ptype, str(vals[0]))
 
83
        if (rv != 0):
 
84
            self.glist.SetError("Invalid data value: "
 
85
                                + OpenIPMI.get_error_string(rv))
 
86
            return
 
87
        self.currval = vals[0]
 
88
        self.glist.SetColumn(self.idx, 1, vals[0])
 
89
        return
 
90
    
 
91
    def setvalue(self, event):
 
92
        gui_setdialog.SetDialog("Set value for " + self.pname,
 
93
                                [ self.currval ], 1, self)
 
94
        return
 
95
 
 
96
    def setenum(self, val):
 
97
        rv = self.pefc.set_val(self.parm, self.aidx, "integer", str(val))
 
98
        if (rv != 0):
 
99
            self.glist.SetError("Could not set value to " + str(val) + ": "
 
100
                                + OpenIPMI.get_error_string(rv))
 
101
            return
 
102
        self.currval = val
 
103
        nval = [ 0 ]
 
104
        sval = [ "" ]
 
105
        OpenIPMI.pefconfig_enum_val(self.parm, val, nval, sval)
 
106
        self.glib.SetColumn(self.idx, 1, sval[0])
 
107
        return
 
108
    
 
109
    def togglevalue(self, event):
 
110
        if (self.currval == "true"):
 
111
            newval = "false"
 
112
        else:
 
113
            newval = "true"
 
114
            pass
 
115
        rv = self.pefc.set_val(self.parm, self.aidx, self.ptype, newval)
 
116
        if (rv != 0):
 
117
            self.glist.SetError("Could not toggle value: "
 
118
                                + OpenIPMI.get_error_string(rv))
 
119
            return
 
120
            
 
121
        self.currval = newval
 
122
        self.glist.SetColumn(self.idx, 1, newval)
 
123
        return
 
124
 
 
125
    pass
 
126
 
 
127
class MCPefParm(gui_list.List):
 
128
    def __init__(self, m, pef, pefc):
 
129
        gui_list.List.__init__(self,
 
130
                               "PEFPARMS for " + m.name,
 
131
                               [ ("Name", 250), ("Value", 250) ])
 
132
        self.pef = pef
 
133
        self.pefc = pefc
 
134
        
 
135
        i = 0
 
136
        j = 0
 
137
        rv = True
 
138
        v = [ 0 ]
 
139
        while (rv):
 
140
            lastv = v[0]
 
141
            rv = pefc.get_val(i, v)
 
142
            if (rv):
 
143
                vals = rv.split(" ", 2)
 
144
                if (len(vals) == 3):
 
145
                    # Valid parm
 
146
                    if (vals[1] == "integer"):
 
147
                        w = [ 0 ]
 
148
                        x = [ "" ]
 
149
                        err = OpenIPMI.pefconfig_enum_val(i, 0, w, x)
 
150
                        if (err != OpenIPMI.enosys):
 
151
                            vals[1] = "enum"
 
152
                            pass
 
153
                        pass
 
154
 
 
155
                    data = MCPEFData(self, pefc, i, lastv,
 
156
                                     vals[0], vals[1], vals[2])
 
157
 
 
158
                    if (v[0] == 0):
 
159
                        title = vals[0]
 
160
                    else:
 
161
                        x = [ "" ]
 
162
                        err = OpenIPMI.pefconfig_enum_idx(i, lastv, x)
 
163
                        if (err):
 
164
                            title = vals[0] + "[" + str(lastv) + "]"
 
165
                        else:
 
166
                            title = vals[0] + "[" + x[0] + "]"
 
167
                            pass
 
168
                        pass
 
169
                    if (vals[1] == "enum"):
 
170
                        nval = [ 0 ]
 
171
                        sval = [ "" ]
 
172
                        OpenIPMI.pefconfig_enum_val(data.parm, int(vals[2]),
 
173
                                                    nval, sval)
 
174
                        value = sval[0]
 
175
                        pass
 
176
                    else:
 
177
                        value = vals[2]
 
178
                        pass
 
179
 
 
180
                    self.add_data(title, [ value ], data)
 
181
                    
 
182
                    j += 1
 
183
                    if (v[0] == 0):
 
184
                        i += 1
 
185
                        pass
 
186
                    if (v[0] == -1):
 
187
                        i += 1
 
188
                        v[0] = 0
 
189
                        pass
 
190
                    pass
 
191
                else:
 
192
                    v[0] = 0
 
193
                    i += 1
 
194
                    pass
 
195
                pass
 
196
            pass
 
197
 
 
198
        self.AfterDone()
 
199
        return
 
200
 
 
201
    def save(self):
 
202
        rv = self.pef.set_config(self.pefc)
 
203
        if (rv != 0):
 
204
            self.errstr.SetError("Error setting config: "
 
205
                                 + OpenIPMI.get_error_string(rv))
 
206
            return
 
207
 
 
208
        # Don't forget to set self.pef to None when done so OnClose
 
209
        # doesn't clear it again
 
210
        self.pef = None
 
211
        self.Close()
 
212
        return
 
213
 
 
214
    def cancel(self):
 
215
        self.Close()
 
216
        return
 
217
 
 
218
    def do_on_close(self):
 
219
        # Do it here, not in cancel, to handle closing the window without
 
220
        # clicking on "save" or "cancel"
 
221
        if (self.pef):
 
222
            self.pef.clear_lock(self.pefc)
 
223
            self.pef = None
 
224
            pass
 
225
        self.pefc = None
 
226
        return
 
227
    
 
228
    pass