summaryrefslogtreecommitdiffstats
path: root/textw/partitioning.py
blob: 465aac9cd173c519fd77453bf68642be9c83d2bf (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
#import gettext
import iutil
import os
import isys
from snack import *
from textw.constants import *
from newtpyfsedit import fsedit        
from text import _

class PartitionMethod:
    def __call__(self, screen, todo):
	if not todo.expert or todo.instClass.partitions:
	    todo.skipFdisk = 1
	    return INSTALL_NOOP

	rc = ButtonChoiceWindow(screen, _("Disk Setup"),
	    _("Disk Druid is a tool for partitioning and setting up mount "
	      "points. It is designed to be easier to use than Linux's "
	      "traditional disk partitioning sofware, fdisk, as well "
	      "as more powerful. However, there are some cases where fdisk "
	      "may be preferred.\n"
	      "\n"
	      "Which tool would you like to use?"),
	    [ (_("Disk Druid"), "dd") , (_("fdisk"), "fd"), 
	      (_("Back"), "back") ], width = 50)

	if rc == "back":
	    return INSTALL_BACK
	elif rc == "dd":
	    todo.skipFdisk = 1
	else:
	    todo.skipFdisk = 0

	return INSTALL_OK

class ManualPartitionWindow:
    def __call__(self, screen, todo):
	if todo.skipFdisk: return INSTALL_NOOP
	
	drives = todo.drives.available ()
	driveNames = drives.keys()
	driveNames.sort (isys.compareDrives)

	choices = []
	haveEdited = 0

	for device in driveNames:
	    descrip = drives[device]
	    if descrip:
		choices.append("/dev/%s - %s" % (device, descrip))
	    else:
		choices.append("/dev/%s" % (device,))

        button = None
	while button != "done" and button != "back":
	    (button, choice) = \
		 ListboxChoiceWindow(screen, _("Disk Setup"),
		_("To install Red Hat Linux, you must have at least one "
		     "partition of 150 MB dedicated to Linux. We suggest "
		     "placing that partition on one of the first two hard "
		     "drives in your system so you can boot into Linux "
		     "with LILO."), choices,
		[ (_("Done"), "done") , (_("Edit"), "edit"), 
		  (_("Back"), "back") ], width = 50)

	    if button != "done" and button != "back":
		haveEdited = 1
		todo.ddruidReadOnly = 1
		todo.ddruid = None	# free our fd's to the hard drive
		device = driveNames[choice]
		screen.suspend ()
		if os.access("/sbin/fdisk", os.X_OK):
		    path = "/sbin/fdisk"
		else:
		    path = "/usr/sbin/fdisk"
                    
                try:
                    isys.makeDevInode(device, '/tmp/' + device)
                except:
                    # XXX FIXME
                    pass
		iutil.execWithRedirect (path, [ path, "/tmp/" + device ])
                try:
                    os.remove ('/tmp/' + device)
                except:
                    # XXX fixme
                    pass
		screen.resume ()

        if haveEdited:
	    drives = todo.drives.available ().keys ()
	    drives.sort (isys.compareDrives)

	    fstab = []
	    for mntpoint, (dev, fstype, reformat) in todo.mounts.items ():
		fstab.append ((dev, mntpoint))

	    todo.ddruid = fsedit(0, drives, fstab, todo.zeroMbr,
				 todo.ddruidReadOnly)

	if button == "back":
	    return INSTALL_BACK

	return INSTALL_OK

class AutoPartitionWindow:
    def __call__(self, screen, todo):
        fstab = []
        for mntpoint, (dev, fstype, reformat) in todo.mounts.items ():
            fstab.append ((dev, mntpoint))

        if not todo.ddruid:
            drives = todo.drives.available ().keys ()
            drives.sort (isys.compareDrives)
            todo.ddruid = fsedit(0, drives, fstab, todo.zeroMbr,
				 todo.ddruidReadOnly)
	    if not todo.instClass.finishPartitioning(todo.ddruid):
		todo.log ("Autopartitioning FAILED\n")

	if not todo.getPartitionWarningText(): 
	    return INSTALL_NOOP

	(rc, choice) = ListboxChoiceWindow(screen, _("Automatic Partitioning"),
	    _("%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(), ),
	    [_("Continue"), _("Manually partition")], 
	    buttons = basicButtons, default = _("Continue"))

	if (rc == "back"): return INSTALL_BACK

        if (choice == 1):
            drives = todo.drives.available ().keys ()
            drives.sort (isys.compareDrives)
            todo.ddruid = fsedit(0, drives, fstab, 0, todo.ddruidReadOnly)
	    todo.manuallyPartition()

class PartitionWindow:
    def __call__(self, screen, todo):
	dir = INSTALL_NOOP
	if not todo.getSkipPartitioning():
	    dir = todo.ddruid.edit ()

	todo.resetMounts()
	for partition, mount, fstype, size in todo.ddruid.getFstab ():
	    todo.addMount(partition, mount, fstype)

        return dir

class TurnOnSwapWindow:

    beenTurnedOn = 0

    def __call__(self, screen, todo):
	if self.beenTurnedOn or (iutil.memInstalled() > 34000):
	    return INSTALL_NOOP

        if not todo.instClass.earlySwapOn:
	    rc = ButtonChoiceWindow(screen, _("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?"),
		       [ (_("Yes"), "yes"), (_("No"), "back") ], width = 50)

	    if (rc == "back"):
		return INSTALL_BACK

	todo.ddruid.save ()
	todo.makeFilesystems (createFs = 0)
	todo.ddruidAlreadySaved = 1
	self.beenTurnedOn = 1

	return INSTALL_OK

class FormatWindow:
    def __call__(self, screen, todo):
        tb = TextboxReflowed (55,
                              _("What partitions would you like to "
                                "format? We strongly suggest formatting "
                                "all of the system partitions, including "
                                "/, /usr, and /var. There is no need to "
                                "format /home or /usr/local if they have "
                                "already been configured during a "
                                "previous install."))

        height = min (screen.height - 12, len (todo.mounts.items()))
        
        ct = CheckboxTree(height = height)

        mounts = todo.mounts.keys ()
        mounts.sort ()

        for mount in mounts:
            (dev, fstype, format) = todo.mounts[mount]
            if fstype == "ext2":
                ct.append("/dev/%s   %s" % (dev, mount), mount, format)

        cb = Checkbox (_("Check for bad blocks during format"))

        bb = ButtonBar (screen, ((_("OK"), "ok"), (_("Back"), "back")))

        g = GridForm (screen, _("Choose Partitions to Format"), 1, 4)
        g.add (tb, 0, 0, (0, 0, 0, 1))
        g.add (ct, 0, 1)
        g.add (cb, 0, 2, (0, 0, 0, 1))
        g.add (bb, 0, 3, growx = 1)

        result = g.runOnce()

        for mount in todo.mounts.keys ():
            (dev, fstype, format) = todo.mounts[mount]
            if fstype == "ext2":
                todo.mounts[mount] = (dev, fstype, 0)

        for mount in ct.getSelection():
            (dev, fstype, format) = todo.mounts[mount]
            todo.mounts[mount] = (dev, fstype, 1)

        todo.badBlockCheck = cb.selected ()

        rc = bb.buttonPressed (result)

        if rc == "back":
            return INSTALL_BACK
        return INSTALL_OK