summaryrefslogtreecommitdiffstats
path: root/iw/upgrade_swap_gui.py
blob: 0a745e856962a7440a53b754d853aa6a1dc6e4d7 (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
from gtk import *
from iw_gui import *
from translate import _
import string
import isys 
import iutil
from log import log
import upgrade
from gnome.ui import *
from package_gui import queryUpgradeContinue
import gui

class UpgradeSwapWindow (InstallWindow):		

    def __init__ (self, ics):
	InstallWindow.__init__ (self, ics)

        ics.setTitle (_("Upgrade Swap Partition"))
        ics.setNextEnabled (1)
        ics.readHTML ("upswapfile")


    def getPrev (self):
        # we're doing an upgrade, offer choice of aborting upgrade.
        # we can't allow them to go back in install, since we've
        # started swap and mounted the systems filesystems
        # if we've already started an upgrade, cannot back out
        rc = queryUpgradeContinue(self.todo.intf)

        if not rc:
            raise gui.StayOnScreen
        else:
            import sys
            print _("Aborting upgrade")
            sys.exit(0)

    def getNext (self):
        #-If the user doesn't need to add swap, we don't do anything
        if not self.neededSwap:
            return None
        
        mnt, part, size = self.clist.get_row_data(self.row)
        val = int(self.entry.get_text())
        size = int(size)
        val = int(val)

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

            if rc == 1:
                raise gui.StayOnScreen
            else:
                # proceed because they decided not to have swapfile created
                threads_leave()
                self.todo.upgradeFindPackages()
                threads_enter()
                return None
        elif val > 2000 or val < 1:
            threads_leave()
            rc = self.swapWrongSize()
            threads_enter()
            raise gui.StayOnScreen

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

        else:
            threads_leave()
            if self.todo.setupFilesystems:
                upgrade.createSwapFile(self.todo.instPath, self.todo.fstab, mnt, val,
                                       self.todo.intf.progressWindow)
            self.todo.upgradeFindPackages()
            threads_enter()
        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):
        self.neededSwap = 0
        rc = upgrade.swapSuggestion(self.todo.instPath, self.todo.fstab)
	if not rc:
            threads_leave()
	    self.todo.upgradeFindPackages ()
            threads_enter()
            return None

        self.neededSwap = 1
        self.row = 0
        box = GtkVBox (FALSE, 5)
        box.set_border_width (5)

	label = GtkLabel (_("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)))

        label.set_alignment (0.5, 0.0)
        label.set_usize(400, 80)
        label.set_line_wrap (TRUE)
        box.pack_start(label, FALSE)

        hs = GtkHSeparator()
        box.pack_start(hs, FALSE)

        self.option1 = GtkRadioButton(None, (_("I want to create a swap file")))
        box.pack_start(self.option1, FALSE)

        (fsList, suggSize, suggMntPoint) = rc

        self.swapbox = GtkVBox(FALSE, 5)
        box.pack_start(self.swapbox, FALSE)
        

        label = GtkLabel (_("Select the partition to put the swap file on:"))
        a = GtkAlignment(0.2, 0.5)
        a.add(label)
        self.swapbox.pack_start(a, FALSE)

        titles = [(_("Mount Point")), (_("Partition")), (_("Free Space (MB)"))]        
        self.clist = GtkCList(3, titles)
        self.clist.connect("select-row", self.clist_cb)
        a = GtkAlignment(0.5, 0.5)
        a.add(self.clist)
        self.swapbox.pack_start(a, FALSE, TRUE, 10)

        count = 0
        for (mnt, part, size) in fsList:
            self.clist.append([mnt, part, str(size)])
            self.clist.set_row_data(count, [mnt, part, size])
            count = count + 1

        self.clist.select_row(0, 0)

        label = GtkLabel (_("It is recommended that your swap file be at least %d MB.  Please enter a size for the swap file:" % suggSize))
        label.set_usize(400, 40)
        label.set_line_wrap (TRUE)
        a = GtkAlignment(0.5, 0.5)
        a.add(label)
        self.swapbox.pack_start(a, FALSE, TRUE, 10)


        hbox = GtkHBox(FALSE, 5)
        a = GtkAlignment(0.4, 0.5)
        a.add(hbox)
        self.swapbox.pack_start(a, FALSE)

        label = GtkLabel (_("Swap file size (MB):"))
        hbox.pack_start(label, FALSE)

        self.entry = GtkEntry(4)
        self.entry.set_usize(40, 25)
        self.entry.set_text(str(suggSize))
        hbox.pack_start(self.entry, FALSE, TRUE, 10)

        self.option2 = GtkRadioButton(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.todo.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").getrc()
        return rc

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

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