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
367
368
369
370
371
372
373
|
# Text storage configuration spoke classes
#
# Copyright (C) 2012 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
# Red Hat Author(s): Jesse Keating <jkeating@redhat.com>
#
# Some of the code here is copied from pyanaconda/ui/gui/spokes/storage.py
# which has the same license and authored by David Lehman <dlehman@redhat.com>
#
from pyanaconda.ui.tui.spokes import NormalTUISpoke
from pyanaconda.ui.tui.simpleline import TextWidget, CheckboxWidget
from pykickstart.constants import AUTOPART_TYPE_LVM
from blivet.size import Size
from blivet.errors import StorageError
from pyanaconda.flags import flags
from pyanaconda.kickstart import doKickstartStorage
from pyanaconda.threads import threadMgr, AnacondaThread
from pykickstart.constants import *
import logging
log = logging.getLogger("anaconda")
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
P_ = lambda x, y, z: gettext.ldngettext("anaconda", x, y, z)
__all__ = ["StorageSpoke", "AutoPartSpoke"]
CLEARALL = _("Use All Space")
CLEARLINUX = _("Replace Existing Linux system(s)")
CLEARNONE = _("Use Free Space")
parttypes = {CLEARALL: CLEARPART_TYPE_ALL, CLEARLINUX: CLEARPART_TYPE_LINUX,
CLEARNONE: CLEARPART_TYPE_NONE}
class FakeDiskLabel(object):
def __init__(self, free=0):
self.free = free
class FakeDisk(object):
def __init__(self, name, size=0, free=0, partitioned=True, vendor=None,
model=None, serial=None, removable=False):
self.name = name
self.size = size
self.format = FakeDiskLabel(free=free)
self.partitioned = partitioned
self.vendor = vendor
self.model = model
self.serial = serial
self.removable = removable
@property
def description(self):
return "%s %s" % (self.vendor, self.model)
def getDisks(devicetree, fake=False):
if not fake:
disks = [d for d in devicetree.devices if d.isDisk and
d.size > 0 and
not d.format.hidden and
not (d.protected and
d.removable)]
else:
disks = []
disks.append(FakeDisk("sda", size=300000, free=10000, serial="00001",
vendor="Seagate", model="Monster"))
disks.append(FakeDisk("sdb", size=300000, free=300000, serial="00002",
vendor="Seagate", model="Monster"))
disks.append(FakeDisk("sdc", size=8000, free=2100, removable=True,
vendor="SanDisk", model="Cruzer", serial="00003"))
return disks
class StorageSpoke(NormalTUISpoke):
title = _("Install Destination")
category = "destination"
def __init__(self, app, data, storage, payload, instclass):
NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
self.selected_disks = self.data.ignoredisk.onlyuse[:]
self._ready = False
# This list gets set up once in initialize and should not be modified
# except perhaps to add advanced devices. It will remain the full list
# of disks that can be included in the install.
self.disks = []
self.errors = []
@property
def completed(self):
return bool(self.storage.rootDevice and not self.errors)
@property
def ready(self):
# By default, the storage spoke is not ready. We have to wait until
# storageInitialize is done.
return self._ready and not threadMgr.get("AnaStorageWatcher")
@property
def mandatory(self):
return True
@property
def showable(self):
return not flags.dirInstall
@property
def status(self):
""" A short string describing the current status of storage setup. """
msg = _("No disks selected")
if self.data.ignoredisk.onlyuse:
msg = P_(("%d disk selected"),
("%d disks selected"),
len(self.data.ignoredisk.onlyuse)) % len(self.data.ignoredisk.onlyuse)
if self.errors:
msg = _("Error checking storage configuration")
# Maybe show what type of clearpart and which disks selected?
elif self.data.autopart.autopart:
msg = _("Automatic partitioning selected")
else:
msg = _("Custom partitioning selected")
return msg
def _update_disk_list(self, disk):
""" Update self.selected_disks based on the selection."""
name = disk.name
# if the disk isn't already selected, select it.
if name not in self.selected_disks:
self.selected_disks.append(name)
# If the disk is already selected, deselect it.
elif name in self.selected_disks:
self.selected_disks.remove(name)
def _update_summary(self):
""" Update the summary based on the UI. """
count = 0
capacity = 0
free = Size(bytes=0)
# pass in our disk list so hidden disks' free space is available
free_space = self.storage.getFreeSpace(disks=self.disks)
selected = [d for d in self.disks if d.name in self.selected_disks]
for disk in selected:
capacity += disk.size
free += free_space[disk.name][0]
count += 1
summary = (P_(("%d disk selected; %s capacity; %s free ..."),
("%d disks selected; %s capacity; %s free ..."),
count) % (count, str(Size(spec="%s MB" % capacity)), free))
if len(self.disks) == 0:
summary = _("No disks detected. Please shut down the computer, connect at least one disk, and restart to complete installation.")
elif count == 0:
summary = (_("No disks selected; please select at least one disk to install to."))
# Append storage errors to the summary
if self.errors:
summary = summary + "\n" + "\n".join(self.errors)
return summary
def refresh(self, args = None):
NormalTUISpoke.refresh(self, args)
# Join the initialization thread to block on it
# This print is foul. Need a better message display
print(_("Probing storage..."))
threadMgr.wait("AnaStorageWatcher")
# synchronize our local data store with the global ksdata
# Commment out because there is no way to select a disk right
# now without putting it in ksdata. Seems wrong?
#self.selected_disks = self.data.ignoredisk.onlyuse[:]
self.autopart = self.data.autopart.autopart
message = self._update_summary()
# loop through the disks and present them.
for disk in self.disks:
c = CheckboxWidget(title="%i) %s" % (self.disks.index(disk) + 1,
disk.name),
completed=(disk.name in self.selected_disks))
self._window += [c, ""]
self._window += [TextWidget(message), ""]
return True
def input(self, args, key):
"""Grab the disk choice and update things"""
if key == "c":
if self.selected_disks:
newspoke = AutoPartSpoke(self.app, self.data, self.storage,
self.payload, self.instclass)
self.app.switch_screen_modal(newspoke)
self.apply()
self.execute()
self.close()
return None
try:
number = int(key)
self._update_disk_list(self.disks[number -1])
return None
except (ValueError, KeyError, IndexError):
return key
def apply(self):
if not flags.automatedInstall:
# default to using autopart for interactive installs
self.data.autopart.autopart = True
self.autopart = self.data.autopart.autopart
self.data.ignoredisk.onlyuse = self.selected_disks[:]
self.data.clearpart.drives = self.selected_disks[:]
self.data.autopart.type = AUTOPART_TYPE_LVM
if self.autopart:
self.clearPartType = CLEARPART_TYPE_ALL
else:
self.clearPartType = CLEARPART_TYPE_NONE
for disk in self.disks:
if disk.name not in self.selected_disks and \
disk in self.storage.devices:
self.storage.devicetree.hide(disk)
elif disk.name in self.selected_disks and \
disk not in self.storage.devices:
self.storage.devicetree.unhide(disk)
self.data.bootloader.location = "mbr"
self.storage.config.update(self.data)
# If autopart is selected we want to remove whatever has been
# created/scheduled to make room for autopart.
# If custom is selected, we want to leave alone any storage layout the
# user may have set up before now.
self.storage.config.clearNonExistent = self.data.autopart.autopart
def execute(self):
print(_("Generating updated storage configuration"))
try:
doKickstartStorage(self.storage, self.data, self.instclass)
except StorageError as e:
log.error("storage configuration failed: %s" % e)
print _("storage configuration failed: %s") % e
self.errors = [str(e)]
self.data.clearpart.type = CLEARPART_TYPE_ALL
self.data.clearpart.initAll = False
self.storage.config.update(self.data)
self.storage.autoPartType = self.data.clearpart.type
self.storage.reset()
self._ready = True
else:
print(_("Checking storage configuration..."))
(self.errors, warnings) = self.storage.sanityCheck()
self._ready = True
for e in self.errors:
log.error(e)
print e
for w in warnings:
log.warn(w)
print w
def initialize(self):
NormalTUISpoke.initialize(self)
threadMgr.add(AnacondaThread(name="AnaStorageWatcher",
target=self._initialize))
self.selected_disks = self.data.ignoredisk.onlyuse[:]
# Probably need something here to track which disks are selected?
def _initialize(self):
# Secondary initialize so wait for the storage thread
# to complete before populating our disk list
threadMgr.wait("AnaStorageThread")
self.disks = sorted(getDisks(self.storage.devicetree),
key=lambda d: d.name)
self._update_summary()
self._ready = True
class AutoPartSpoke(NormalTUISpoke):
title = _("Autopartitioning Options")
category = "destination"
def __init__(self, app, data, storage, payload, instclass):
NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
self.clearPartType = self.data.clearpart.type
@property
def indirect(self):
return True
@property
def completed(self):
return True # We're always complete
def refresh(self, args = None):
NormalTUISpoke.refresh(self, args)
# synchronize our local data store with the global ksdata
self.clearPartType = self.data.clearpart.type
# I dislike "is None", but bool(0) returns false :(
if self.clearPartType is None:
# Default to clearing everything.
self.clearPartType = CLEARPART_TYPE_ALL
self.parttypelist = sorted(parttypes.keys())
for parttype in self.parttypelist:
c = CheckboxWidget(title="%i) %s" % (self.parttypelist.index(parttype) + 1,
parttype),
completed=(parttypes[parttype] == self.clearPartType))
self._window += [c, ""]
message = _("Installation requires partitioning of your hard drive. Select what space to use for the install target.")
self._window += [TextWidget(message), ""]
return True
def apply(self):
self.data.clearpart.type = self.clearPartType
self.data.clearpart.initAll = True
def input(self, args, key):
"""Grab the choice and update things"""
if key == "c":
self.apply()
self.close()
return False
try:
number = int(key)
self.clearPartType = parttypes[self.parttypelist[number -1]]
self.apply()
self.close()
return False
except (ValueError, KeyError, IndexError):
return key
|