summaryrefslogtreecommitdiffstats
path: root/textw/upgrade_text.py
blob: 36d529fda0140f19cf0935dcd8acf2b5efffb635 (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
from snack import *
from translate import _
import string
import isys
import iutil
from log import log
from constants_text import *
import upgrade

class UpgradeSwapWindow:
    def __call__ (self, dir, screen, todo):
	if dir == -1:
	    raise ValueError, "this can't happen"

	rc = upgrade.swapSuggestion(todo.instPath, todo.fstab)
	if not rc:
	    todo.upgradeFindPackages ()
	    return INSTALL_OK

	(fsList, suggSize, suggMntPoint) = rc

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

	tb = TextboxReflowed(60, text)
	amount = Entry(10, scroll = 0)
	amount.set(str(suggSize))

	l = len(fsList)
	scroll = 0
	if l > 4:
	    l = 4
	    scroll = 1
	listbox = Listbox(l, scroll = scroll)

	liLabel = Label("%-25s %-15s %8s" % (_("Mount Point"), 
			_("Partition"), _("Free Space")))

	count = 0
	for (mnt, part, size) in fsList:
	    listbox.append("%-25s /dev/%-10s %6dMB" % (mnt, part, size), count)

	    if (mnt == suggMntPoint):
		listbox.setCurrent(count)

	    count = count + 1

	buttons = ButtonBar(screen, [(_("OK"), "ok"), (_("Skip"), "skip"),  
			     (_("Back"), "back") ] )

	amGrid = Grid(2, 2)
	amGrid.setField(Label(_("Suggested size (MB):")), 0, 0, anchorLeft = 1,
			padding = (0, 0, 1, 0))
	amGrid.setField(Label(str(suggSize)), 1, 0, anchorLeft = 1)
	amGrid.setField(Label(_("Swap file size (MB):")), 0, 1, anchorLeft = 1,
			padding = (0, 0, 1, 0))
	amGrid.setField(amount, 1, 1)
	
	liGrid = Grid(1, 2)
	liGrid.setField(liLabel, 0, 0)
	liGrid.setField(listbox, 0, 1)

	g = GridFormHelp(screen, _("Add Swap"), "upgradeswap", 1, 4)
	g.add(tb, 0, 0, anchorLeft = 1, padding = (0, 0, 0, 1))
	g.add(amGrid, 0, 1, padding = (0, 0, 0, 1))
	g.add(liGrid, 0, 2, padding = (0, 0, 0, 1))
	g.add(buttons, 0, 3, anchorLeft = 1, growx = 1)

	while 1:
	    result = g.run()

	    if (buttons.buttonPressed(result)):
		result = buttons.buttonPressed(result)

	    if result == "back":
		screen.popWindow()
		return INSTALL_BACK
	    elif result == "skip":
		screen.popWindow()
		return INSTALL_OK

	    val = amount.value()
	    try:
		val = int(val)
	    except ValueError:
		todo.intf.messageWindow(_("Error"),
		    _("The value you entered is not a valid number."))

	    if type(val) == type(1):
		(mnt, part, size) = fsList[listbox.current()]
		if size < (val - 16):
		    todo.intf.messageWindow(_("Error"),
			_("There is not enough space on the device you "
			  "selected for the swap partition."))
		else:
		    screen.popWindow()
		    upgrade.createSwapFile(todo.instPath, todo.fstab, mnt, val,
					   todo.intf.progressWindow)
		    todo.upgradeFindPackages ()
		    return INSTALL_OK

	raise ValueError
	
class UpgradeExamineWindow:
    def __call__ (self, dir, screen, todo):
	if dir == -1:
            # msf dont go back!
            rc = ButtonChoiceWindow(screen, _("Proceed with upgrade?"),
                            _("The filesystems of the Linux installation "
                              "you have chosen to upgrade have already been "
                              "mounted. You cannot go back past this point. "
                              "\n\n") +
                              _("If you would like to exit the upgrade select "
                              "Exit, or choose Ok to continue with the "
                              "upgrade."),
                               [ _("Ok"), _("Exit") ], width = 50)

            if rc == 'ok':
                return INSTALL_OK
            else:
                import sys
                sys.exit(0)
           
	    # Hack to let backing out of upgrades work properly
	    from fstab import NewtFstab
	    if todo.fstab:
		todo.fstab.turnOffSwap()
	    todo.fstab = NewtFstab(todo.setupFilesystems, 
                                   todo.serial, 0, 0,
                                   todo.intf.waitWindow,
                                   todo.intf.messageWindow,
                                   todo.intf.progressWindow,
                                   not todo.expert,
                                   todo.method.protectedPartitions(),
                                   todo.expert, 1)

	    return INSTALL_NOOP

        parts = todo.upgradeFindRoot ()

        if not parts:
            ButtonChoiceWindow(screen, _("Error"),
                               _("You don't have any Linux partitions. You "
                                 "can't upgrade this system!"),
                               [ _("Back") ], width = 50)
            return INSTALL_BACK
        
        if len (parts) > 1:
            height = min (len (parts), 12)
            if height == 12:
                scroll = 1
            else:
                scroll = 0

	    partList = []
	    for (drive, fs) in parts:
		partList.append(drive)

            (button, choice) = \
                ListboxChoiceWindow(screen, _("System to Upgrade"),
                                    _("What partition holds the root partition "
                                      "of your installation?"), partList, 
                                    [ _("OK"), _("Back") ], width = 30,
                                    scroll = scroll, height = height,
				    help = "multipleroot")
            if button == string.lower (_("Back")):
                return INSTALL_BACK
            else:
                root = parts[choice]
        else:
            root = parts[0]
            (drive, fs) = root

            # terrible hack - need to fix in future
            # if we're skipping confirm upgrade window, we must be in
            # upgradeonly mode, so don't display this window either
            if not todo.instClass.skipStep('confirm-upgrade'):
                rc = ButtonChoiceWindow (screen, _("Upgrade Partition"),
                                         _("Going to upgrade partition /dev/") + drive,
                                         buttons = [ _("Ok"), _("Back") ])
                if rc  == string.lower (_("Back")):
                    return INSTALL_BACK

        todo.upgradeMountFilesystems (root)

class CustomizeUpgradeWindow:
    def __call__ (self, screen, todo, indiv):
        rc = ButtonChoiceWindow (screen, _("Customize Packages to Upgrade"),
                                 _("The packages you have installed, "
                                   "and any other packages which are "
                                   "needed to satisfy their "
                                   "dependencies, have been selected "
                                   "for installation. Would you like "
                                   "to customize the set of packages "
                                   "that will be upgraded?"),
                                 buttons = [ _("Yes"), _("No"), _("Back") ],
				help = "custupgrade")

        if rc == string.lower (_("Back")):
            return INSTALL_BACK

        if rc == string.lower (_("No")):
            indiv.set (0)
        else:
            indiv.set (1)

        return INSTALL_OK