summaryrefslogtreecommitdiffstats
path: root/iw/rootpartition_gui.py
blob: ac141996dc443098200511f209f92ac1dcf867be (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
from gtk import *
from iw_gui import *
from thread import *
import isys
from translate import _
import gui
from fdisk_gui import *
import isys
import iutil

CHOICE_FDISK = 1
CHOICE_DDRUID = 2
CHOICE_AUTOPART = 3


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

        self.todo = ics.getToDo ()
        ics.setTitle (_("Confirm Partitioning Selection"))
        ics.readHTML ("partition")
	ics.setNextEnabled (TRUE)
        
    def getScreen (self):
        return self.window

    def getPrev (self):
        return PartitionWindow

class PartitionWindow (InstallWindow):
    swapon = 0
    def __init__ (self, ics):
	InstallWindow.__init__ (self, ics)

        self.todo = ics.getToDo ()
        ics.setTitle (_("Disk Druid"))
        ics.readHTML ("partition")
	ics.setNextEnabled (FALSE)
	self.skippedScreen = 0
        self.swapon = 0

    def checkSwap (self):
        if PartitionWindow.swapon or (iutil.memInstalled() > 34000):
	    return 1

        threads_leave ()
	message = gui.MessageWindow(_("Low Memory"),
		   _("As you don't have much memory in this machine, we "
		     "need to turn on swap space immediately. To do this "
		     "we'll have to write your new partition table to the "
		     "disk immediately. Is that okay?"), "okcancel")

	if (message.getrc () == 1):
	    threads_enter ()
	    return 0

	self.todo.fstab.savePartitions()
	self.todo.fstab.turnOnSwap(self.todo.intf.waitWindow)
	self.todo.ddruidAlreadySaved = 1
	PartitionWindow.swapon = 1

        threads_enter ()

        return 1

    def getNext (self):
	if not self.running: return 0
	self.todo.fstab.runDruidFinished()

        # FIXME
	#if not self.skippedScreen:
	    #win = self.todo.ddruid.getConfirm ()
	    #if win:
		#bin = GtkFrame (None, _obj = win)
		#bin.set_shadow_type (SHADOW_NONE)
		#window = ConfirmPartitionWindow
		#window.window = bin
		#return window

	bootPartition = None
	rootPartition = None

        if not self.checkSwap ():
            return PartitionWindow

        if self.todo.fstab.rootOnLoop():
            return LoopSizeWindow

        return None

    def enableCallback (self, value):
        self.ics.setNextEnabled (value)

    def getScreen (self):
	self.running = 0
	if not self.todo.fstab.getRunDruid(): return None
	self.running = 1
	return self.todo.fstab.runDruid(self.enableCallback)

class LoopSizeWindow(InstallWindow):
    def __init__ (self, ics):
	InstallWindow.__init__ (self, ics)
        ics.readHTML ("loopback")

    def getNext (self):
        self.todo.fstab.setLoopbackSize (self.sizeAdj.value, self.swapAdj.value)

    def Spinchanged(self, *args):
        swapsize = self.swapAdj.value
        rootsize = self.sizeAdj.value
        totalmax = self.upper
        
        if swapsize + rootsize > totalmax:
            rootsize = totalmax - swapsize
            
        if rootsize < 0:
            rootsize = self.sizeAdj.lower
                
        # set adjustment, trigger clipping and read new value
        self.sizeAdj.set_value(rootsize)
        rootsize = self.sizeAdj.value

        # if still too big try smallest swap and loopback size possible
        if rootsize + swapsize > totalmax:
            swapsize = self.swapAdj.lower
                    
        self.swapAdj.set_value(swapsize)

    def getScreen (self):
        # XXX error check mount that this check tries
        if self.todo.setupFilesystems:
            avail = apply(isys.spaceAvailable, self.todo.fstab.getRootDevice())
        else:
            # test mode
            avail = 5000
	(size, swapSize) = self.todo.fstab.getLoopbackSize()
	if not size:
	    size = avail / 2
	    swapSize = 32

        vbox = GtkVBox (FALSE, 5)
        
        label = GtkLabel (
		_("You've chosen to put your root filesystem in a file on "
		  "an already-existing DOS or Windows filesystem. How large, "
		  "in megabytes, should would you like the root filesystem "
		  "to be, and how much swap space would you like? They must "
		  "total less then %d megabytes in size.") % (avail, ))
        label.set_usize (400, -1)
        label.set_line_wrap (TRUE)
        vbox.pack_start (label, FALSE, FALSE)

	self.upper = avail
	if avail > 2000:
	    self.upper = 2000


        # XXX lower is 150
        self.sizeAdj = GtkAdjustment (value = size, lower = 150, upper = self.upper, step_incr = 1)
        self.sizeSpin = GtkSpinButton (self.sizeAdj, digits = 0)
        self.sizeSpin.set_usize (100, -1)
        self.sizeSpin.set_numeric(1)
        self.sizeSpin.connect("changed", self.Spinchanged)
        
        self.swapAdj = GtkAdjustment (value = swapSize, lower = 16, upper = self.upper, step_incr = 1)
        self.swapSpin = GtkSpinButton (self.swapAdj, digits = 0)
        self.swapSpin.set_usize (100, -1)
        self.swapSpin.set_numeric(1)
        self.swapSpin.connect("changed", self.Spinchanged)
        
        table = GtkTable ()

        label = GtkLabel (_("Root filesystem size:"))
        label.set_alignment (1.0, 0.5)
        table.attach (label, 0, 1, 0, 1, xpadding=5, ypadding=5)
        table.attach (self.sizeSpin, 1, 2, 0, 1, xpadding=5, ypadding=5)

        label = GtkLabel (_("Swap space size:"))
        label.set_alignment (1.0, 0.5)
        table.attach (label, 0, 1, 1, 2, xpadding=5, ypadding=5)
        table.attach (self.swapSpin, 1, 2, 1, 2, xpadding=5, ypadding=5)

        align = GtkAlignment ()
        align.add (table)
        align.set (0, 0, 0.5, 0.5)
        vbox.pack_start (align, FALSE, FALSE)

	self.ics.setNextEnabled (TRUE)

        return vbox
        
class AutoPartitionWindow(InstallWindow):
    def getPrev(self):
	self.druid = None
	self.beingDisplayed = 0

    def getNext(self):
	if not self.beingDisplayed: return
###
###    msf - 05/11/2000 - removed this block shouldnt be needed with changes
###
#
#	if not self.__dict__.has_key("manuallyPartitionddruid"):
#            # if druid wasn't running, must have been in autopartition mode
#            # clear fstab cache so we don't get junk from attempted
#            # autopartitioning
#            print "number 1"
#            clearcache = not self.todo.fstab.getRunDruid()
#	    self.todo.fstab.setRunDruid(1)
#            self.todo.fstab.setReadonly(0)
#            #print "Rescanning partitions 1 - ", clearcache
#            self.todo.fstab.rescanPartitions(clearcache)
#	    self.todo.instClass.removeFromSkipList("format")
	if AutoPartitionWindow.manuallyPartitionddruid.get_active():
            if self.druid:
                del self.druid
            # see comment above about clearing cache

            if self.lastChoice != CHOICE_DDRUID:
                clearcache = 1
            else:
                clearcache = 0
#            clearcache = not self.todo.fstab.getRunDruid()
	    self.todo.fstab.setRunDruid(1)
            self.todo.fstab.setReadonly(0)
            #print "Rescanning partitions 2 - ", clearcache
	    self.todo.fstab.rescanPartitions(clearcache)
	    self.todo.instClass.removeFromSkipList("format")
            self.lastChoice = CHOICE_DDRUID
        elif AutoPartitionWindow.manuallyPartitionfdisk.get_active():
            self.todo.fstab.setRunDruid(1)
            self.todo.fstab.setReadonly(1)
            self.lastChoice = CHOICE_FDISK
	else:
	    self.todo.fstab.setRunDruid(0)
	    self.todo.fstab.setDruid(self.druid, self.todo.instClass.raidList)
	    self.todo.fstab.formatAllFilesystems()
	    self.todo.instClass.addToSkipList("format")
            self.lastChoice = CHOICE_AUTOPART

	self.beingDisplayed = 0
	return None

    def __init__(self, ics):
	InstallWindow.__init__(self, ics)
        ics.setTitle (_("Automatic Partitioning"))
	self.druid = None
	self.beingDisplayed = 0
        self.lastChoice = None

    def getScreen (self):   

        # XXX hack
        if self.todo.instClass.clearType:
            self.ics.readHTML (self.todo.instClass.clearType)

	todo = self.todo
	self.druid = None

# user selected an install type which had predefined partitioning
# attempt to automatically allocate these partitions.
#
# if this fails we drop them into disk druid
#
        attemptedPartitioningandFailed = 0
	if self.todo.instClass.partitions:
	    self.druid = \
		todo.fstab.attemptPartitioning(todo.instClass.partitions,
                                               todo.instClass.fstab,
					       todo.instClass.clearParts)

            if not self.druid:
                attemptedPartitioningandFailed = 1

#
# if no warning text means we have carte blanc to blow everything away
# without telling user
#
	if not todo.getPartitionWarningText() and self.druid:

            self.ics.setNextEnabled (TRUE)

	    self.todo.fstab.setRunDruid(0)
	    self.todo.fstab.setDruid(self.druid)
	    self.todo.fstab.formatAllFilesystems()
	    self.todo.instClass.addToSkipList("format")
	    return

#
# see what means the user wants to use to partition
#
        self.todo.fstab.setRunDruid(1)
        self.todo.fstab.setReadonly(0)

        if self.druid:
            self.ics.setTitle (_("Automatic Partitioning"))
            label = \
                  GtkLabel(_("%s\n\nIf you don't want to do this, you can continue with "
                             "this install by partitioning manually, or you can go back "
                             "and perform a fully customized installation.") % 
                           (_(todo.getPartitionWarningText()), ))
        else:
            if attemptedPartitioningandFailed:
                self.ics.setTitle (_("Automatic Partitioning Failed"))
                label = GtkLabel(_("\nThere is not sufficient disk space in "
                                   "order to automatically partition your disk. "
                                   "You will need to manually partition your "
                                   "disks for Red Hat Linux to install."
                                   "\n\nPlease choose the tool you would like to "
                                   "use to partition your system for Red Hat Linux."))
            else:
                self.ics.setTitle (_("Manual Partitioning"))
                label = GtkLabel(_("\nPlease choose the tool you would like to "
                                   "use to partition your system for Red Hat Linux."))
            
        label.set_line_wrap(TRUE)
        label.set_alignment(0.0, 0.0)
        label.set_usize(380, -1)
            
        box = GtkVBox (FALSE)
	box.pack_start(label, FALSE)
        box.set_border_width (5)

        radioBox = GtkVBox (FALSE)

        if self.druid:
            self.continueChoice = GtkRadioButton (None, _("Automatically partition and REMOVE DATA"))
            radioBox.pack_start(self.continueChoice, FALSE)
            firstbutton = self.continueChoice
        else:
            firstbutton = None
        
	AutoPartitionWindow.manuallyPartitionddruid = GtkRadioButton(
		firstbutton, _("Manually partition with Disk Druid"))

        if self.lastChoice == CHOICE_DDRUID:
            AutoPartitionWindow.manuallyPartitionddruid.set_active(1)

        if firstbutton == None:
            secondbutton = AutoPartitionWindow.manuallyPartitionddruid
        else:
            secondbutton = firstbutton
            
	radioBox.pack_start(AutoPartitionWindow.manuallyPartitionddruid, FALSE)
	AutoPartitionWindow.manuallyPartitionfdisk = GtkRadioButton(
		secondbutton, _("Manually partition with fdisk [experts only]"))
	radioBox.pack_start(AutoPartitionWindow.manuallyPartitionfdisk, FALSE)

        if self.lastChoice == CHOICE_FDISK:
            AutoPartitionWindow.manuallyPartitionfdisk.set_active(1)
            
	align = GtkAlignment()
	align.add(radioBox)
	align.set(0.5, 0.5, 0.0, 0.0)

	box.pack_start(align, TRUE, TRUE)
	box.set_border_width (5)

        self.ics.setNextEnabled (TRUE)

	self.beingDisplayed = 1
	return box