summaryrefslogtreecommitdiffstats
path: root/iw/upgrade_swap_gui.py
blob: 02fede2472ac8b92174808217e67c93aad65bca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#
# upgrade_swap_gui.py: dialog for adding swap files for 2.4
#
# Mike Fulbright <msf@redhat.com>
#
# Copyright 2001-2002 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import string
import isys 
import iutil
import upgrade
import gui
import gobject
import gtk
from iw_gui import *
from packages import queryUpgradeContinue
from flags import flags

from rhpl.translate import _, N_

class UpgradeSwapWindow (InstallWindow):		
    windowTitle = N_("Upgrade Swap Partition")
    htmlTag = "upswapfile"

    def getNext (self):
        #-If the user doesn't need to add swap, we don't do anything
        if not self.neededSwap:
            return None

        if self.option2.get_active():
            rc = self.warning()

            if rc == 0:
                raise gui.StayOnScreen
            else:
                return None

	selection = self.view.get_selection()
	(model, iter) = selection.get_selected()
	if iter:
	    mnt = model.get_value(iter, 0)
	    part = model.get_value(iter, 1)
	    size = int(model.get_value(iter, 2))
            val = int(self.entry.get_text())
	else:
	    raise RuntimeError, "unknown value for upgrade swap location"

        if val > 2000 or val < 1:
            rc = self.swapWrongSize()
            raise gui.StayOnScreen

        elif (val+16) > size:
            rc = self.swapTooBig()
            raise gui.StayOnScreen            

        else:
            if flags.setupFilesystems:
                upgrade.createSwapFile(self.instPath, self.fsset, mnt, val)
            self.dispatch.skipStep("addswap", 1)
                
        return None

    def toggle (self, data):
        self.swapbox.set_sensitive(self.option1.get_active())

    def clist_cb(self, clist, row, col, data):
        self.row = row
    
    def getScreen (self, intf, fsset, instPath, swapInfo, dispatch):

#
# use to test function
#
#	fslist = [('/', 'hda1', 1000)]
#	fslist.append(('/var', 'hda2', 100))
#	fslist.append(('/opt', 'hda3', 500))
#	swapInfo = (fslist, 1000, '/var')
	
        self.neededSwap = 0
        self.fsset = fsset
        self.instPath = instPath
        self.intf = intf
        self.dispatch = dispatch
        
        rc = swapInfo

        self.neededSwap = 1
        self.row = 0
        box = gtk.VBox (False, 5)
        box.set_border_width (5)

	label = gtk.Label (_("The 2.4 kernel needs significantly more "
                            "swap than older kernels, as much as twice "
                            "as much swap space as RAM on the system.  "
                            "You currently have %dMB of swap configured, but "
                            "you may create additional swap space on one of "
                            "your file systems now.")
                          % (iutil.swapAmount() / 1024) +
                          _("\n\nThe installer has detected %s MB of RAM.\n") %
                          (iutil.memInstalled()/1024))

        label.set_alignment (0.5, 0.0)
#        label.set_size_request(400, 200)
        label.set_line_wrap (True)
        box.pack_start(label, False)

        hs = gtk.HSeparator()
        box.pack_start(hs, False)

        self.option1 = gtk.RadioButton(None,
                                      (_("I _want to create a swap file")))
        box.pack_start(self.option1, False)

        (fsList, suggSize, suggMntPoint) = rc

        self.swapbox = gtk.VBox(False, 5)
        box.pack_start(self.swapbox, False)
        

        label = gui.MnemonicLabel (_("Select the _partition to put the swap file on:"))
        a = gtk.Alignment(0.2, 0.5)
        a.add(label)
        self.swapbox.pack_start(a, False)

	self.store = gtk.ListStore(gobject.TYPE_STRING,
				   gobject.TYPE_STRING,
				   gobject.TYPE_STRING)

        for (mnt, part, size) in fsList:
	    iter = self.store.append()
	    self.store.set_value(iter, 0, mnt)
	    self.store.set_value(iter, 1, part)
	    self.store.set_value(iter, 2, str(size))

	self.view=gtk.TreeView(self.store)
        label.set_mnemonic_widget(self.view)

	i = 0
	for title in [(_("Mount Point")), (_("Partition")), (_("Free Space (MB)"))]:
	    col = gtk.TreeViewColumn(title, gtk.CellRendererText(), text=i)
	    self.view.append_column(col)
	    i = i + 1

	sw = gtk.ScrolledWindow()
	sw.add(self.view)
	sw.set_shadow_type(gtk.SHADOW_IN)
	sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
	sw.set_size_request(300, 90)
	a = gtk.Alignment(0.5, 0.5)
        a.add(sw)
        self.swapbox.pack_start(a, False, True, 10)

	rootiter = self.store.get_iter_first()
	sel = self.view.get_selection()
	sel.select_iter(rootiter)

        label = gtk.Label (_("It is recommended that your swap file be at "
                            "least %d MB.  Please enter a size for the swap "
                            "file:") % suggSize)
        label.set_size_request(400, 40)
        label.set_line_wrap (True)
        a = gtk.Alignment(0.5, 0.5)
        a.add(label)
        self.swapbox.pack_start(a, False, True, 10)


        hbox = gtk.HBox(False, 5)
        a = gtk.Alignment(0.4, 0.5)
        a.add(hbox)
        self.swapbox.pack_start(a, False)

        label = gui.MnemonicLabel (_("Swap file _size (MB):"))
        hbox.pack_start(label, False)

        self.entry = gtk.Entry(4)
        label.set_mnemonic_widget(self.entry)
        self.entry.set_size_request(40, 25)
        self.entry.set_text(str(suggSize))
        hbox.pack_start(self.entry, False, True, 10)

        self.option2 = gtk.RadioButton(self.option1,
                                      (_("I _don't want to create a swap "
                                         "file")))
        box.pack_start(self.option2, False, True, 20)

        self.option1.connect("toggled", self.toggle)
        return box


    def warning(self):
        rc = self.intf.messageWindow(_("Warning"), 
                    _("It is stongly recommended that you create a swap "
                      "file.  Failure to do so could cause the installer "
                      "to abort abnormally.  Are you sure that you wish "
                      "to continue?"), type = "yesno")
        return rc

    def swapWrongSize(self):
        rc = self.intf.messageWindow(_("Warning"), 
                    _("The swap file must be between 1 and 2000 MB in size."),
                       type = "okcancel")
        return rc

    def swapTooBig(self):
        
        rc = self.intf.messageWindow(_("Warning"), 
                    _("There is not enough space on the device you "
			  "selected for the swap partition."),
                       type = "okcancel")
        return rc