/[gli]/trunk/src/fe/gtk/Partitioning.py
Gentoo

Contents of /trunk/src/fe/gtk/Partitioning.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 530 - (show annotations) (download) (as text)
Fri Apr 29 05:57:09 2005 UTC (15 years, 7 months ago) by agaffney
File MIME type: text/x-python
File size: 16566 byte(s)
Fixed missing int()s

1 import gtk
2 import GLIScreen
3 import GLIStorageDevice
4 import re
5 import PartitionButton
6 import PartProperties
7
8 class Panel(GLIScreen.GLIScreen):
9
10 title = "Partitioning"
11 part_buttons = {}
12 drives = []
13 devices = {}
14 active_device = ""
15 active_device_bytes_in_cylinder = 0
16 active_device_bytes_in_sector = 0
17 active_device_cylinders = 0
18 active_part_min_size = 0
19 active_part_max_size = 0
20 active_part_cur_size = 0
21 active_part_start_cyl = 0
22 active_part_minor = 0
23 colors = { 'ext2': '#0af2fe', 'ext3': '#0af2fe', 'unalloc': '#a2a2a2', 'unknown': '#ed03e0', 'free': '#ffffff', 'ntfs': '#f20600', 'fat': '#3d07f9', 'fat32': '#3d07f9', 'reiserfs': '#e9f704', 'linux-swap': '#12ff09' }
24 supported_filesystems = ['ext2', 'ext3', 'linux-swap', 'fat32', 'ntfs']
25
26 def __init__(self, controller, parent):
27 GLIScreen.GLIScreen.__init__(self, controller, show_title=False)
28 self._parent = parent
29
30 vert = gtk.VBox(False, 0)
31 vert.set_border_width(10)
32
33 content_str = """On this screen, you will be presented with a list of detected partitionable devices. Selecting
34 a device will show you the current partitions on it (if any) and allow you to add, remove, and
35 resize partitions.
36 """
37
38 content_label = gtk.Label(content_str)
39 vert.pack_start(content_label, expand=False, fill=False, padding=0) # This was removed for screen space
40 container = gtk.HBox(False, 0)
41 detected_dev_label = gtk.Label("Devices:")
42 container.pack_start(detected_dev_label, expand=False, fill=False, padding=10)
43 self.detected_dev_combo = gtk.combo_box_new_text()
44 self.detected_dev_combo.connect("changed", self.drive_changed)
45 container.pack_start(self.detected_dev_combo, expand=False, fill=False, padding=0)
46
47 vert.pack_start(container, expand=False, fill=False, padding=10)
48
49 # This builds the container for the "whole disk" display at the top
50 part_table_frame = gtk.Frame()
51 part_table_frame.set_shadow_type(gtk.SHADOW_IN)
52 self.part_table = gtk.Table(1, 1, False)
53 self.part_table.set_size_request(-1, 40)
54 part_table_frame.add(self.part_table)
55 vert.pack_start(part_table_frame, expand=False, fill=False, padding=5)
56
57 # This builds the partition info box
58 self.part_info_box = gtk.HBox(False, 0)
59 part_info_table = gtk.Table(6, 2, False)
60 part_info_table.set_col_spacings(10)
61 info_partition_label = gtk.Label("Partition:")
62 info_partition_label.set_alignment(0.0, 0.5)
63 self.info_partition = gtk.Label()
64 self.info_partition.set_alignment(0.0, 0.5)
65 info_type_label = gtk.Label("Type:")
66 info_type_label.set_alignment(0.0, 0.5)
67 self.info_type = gtk.Label()
68 self.info_type.set_alignment(0.0, 0.5)
69 info_filesystem_label = gtk.Label("Filesystem:")
70 info_filesystem_label.set_alignment(0.0, 0.5)
71 self.info_filesystem = gtk.Label()
72 self.info_filesystem.set_alignment(0.0, 0.5)
73 # info_start_label = gtk.Label("Start sector:")
74 # info_start_label.set_alignment(0.0, 0.5)
75 # self.info_start = gtk.Label()
76 # self.info_start.set_alignment(0.0, 0.5)
77 # info_end_label = gtk.Label("End sector:")
78 # info_end_label.set_alignment(0.0, 0.5)
79 # self.info_end = gtk.Label()
80 # self.info_end.set_alignment(0.0, 0.5)
81 info_size_label = gtk.Label("Size:")
82 info_size_label.set_alignment(0.0, 0.5)
83 self.info_size = gtk.Label()
84 self.info_size.set_alignment(0.0, 0.5)
85 part_info_table.attach(info_partition_label, 0, 1, 0, 1)
86 part_info_table.attach(self.info_partition, 1, 2, 0, 1)
87 part_info_table.attach(info_type_label, 0, 1, 1, 2)
88 part_info_table.attach(self.info_type, 1, 2, 1, 2)
89 part_info_table.attach(info_filesystem_label, 0, 1, 2, 3)
90 part_info_table.attach(self.info_filesystem, 1, 2, 2, 3)
91 # part_info_table.attach(info_start_label, 0, 1, 3, 4)
92 # part_info_table.attach(self.info_start, 1, 2, 3, 4)
93 # part_info_table.attach(info_end_label, 0, 1, 4, 5)
94 # part_info_table.attach(self.info_end, 1, 2, 4, 5)
95 part_info_table.attach(info_size_label, 0, 1, 5, 6)
96 part_info_table.attach(self.info_size, 1, 2, 5, 6)
97 self.part_info_box.pack_start(part_info_table, expand=False, fill=False)
98 vert.pack_start(self.part_info_box, expand=False, fill=False, padding=10)
99
100 # This builds the row of buttons
101 self.part_button_box = gtk.HBox(False, 0)
102 self.part_button_delete = gtk.Button(" Delete ")
103 self.part_button_delete.connect("clicked", self.part_button_delete_clicked)
104 self.part_button_box.pack_start(self.part_button_delete, expand=False, fill=False, padding=0)
105 self.part_button_properties = gtk.Button(" Properties ")
106 self.part_button_properties.connect("clicked", self.part_button_properties_clicked)
107 self.part_button_box.pack_start(self.part_button_properties, expand=False, fill=False, padding=10)
108 part_button_dump_info = gtk.Button(" Dump to console (debug) ")
109 part_button_dump_info.connect("clicked", self.dump_part_info_to_console)
110 self.part_button_box.pack_start(part_button_dump_info, expand=False, fill=False, padding=0)
111 vert.pack_start(self.part_button_box, expand=False, fill=False, padding=10)
112
113 # This builds the color key at the bottom
114 color_codes = [ { 'label': "Swap", 'color': '#12ff99' },
115 { 'label': "Ext2/3", 'color': '#0af2fe' },
116 # { 'label': "ReiserFS", 'color': '#e9f704' },
117 { 'label': "FAT", 'color': '#3d07f9' },
118 { 'label': "NTFS", 'color': '#f20600' },
119 { 'label': "Other", 'color': '#ed03e0' },
120 { 'label': "Free space", 'color': '#ffffff' },
121 { 'label': "Unallocated", 'color': '#a2a2a2' }
122 ]
123 color_codes_box = gtk.HBox(False, 0)
124 vert.pack_end(color_codes_box, expand=False, fill=False, padding=2)
125 for color in color_codes:
126 temp_xpm = [ "12 12 2 1",
127 "B c #000000",
128 "C c " + color['color'],
129 "BBBBBBBBBBBB",
130 "BCCCCCCCCCCB",
131 "BCCCCCCCCCCB",
132 "BCCCCCCCCCCB",
133 "BCCCCCCCCCCB",
134 "BCCCCCCCCCCB",
135 "BCCCCCCCCCCB",
136 "BCCCCCCCCCCB",
137 "BCCCCCCCCCCB",
138 "BCCCCCCCCCCB",
139 "BCCCCCCCCCCB",
140 "BBBBBBBBBBBB"
141 ]
142 pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(self.controller.window.window, None, temp_xpm)
143 tmp_image = gtk.Image()
144 tmp_image.set_from_pixmap(pixmap, mask)
145 color_codes_box.pack_start(tmp_image, expand=False, fill=False, padding=3)
146 color_codes_box.pack_start(gtk.Label(color['label']), expand=False, fill=False, padding=3)
147
148 self.add_content(vert)
149 # self.detected_dev_combo.set_active(0)
150
151 def drive_changed(self, combobox, data=None):
152 self.active_device = self.drives[self.detected_dev_combo.get_active()]
153 self.draw_part_box()
154 self.active_device_cylinders = self.devices[self.active_device].get_num_cylinders()
155 self.active_device_bytes_in_cylinder = self.devices[self.active_device].get_cylinder_size()
156 self.active_device_bytes_in_sector = self.devices[self.active_device].get_sector_size()
157 self.info_partition.set_text("")
158 self.info_type.set_text("")
159 self.info_filesystem.set_text("")
160 # self.info_start.set_text("")
161 # self.info_end.set_text("")
162 self.info_size.set_text("")
163 self.part_info_box.hide_all()
164 # self.resize_box.hide_all()
165 self.part_button_box.hide_all()
166 # self.part_mount_info_box.hide_all()
167
168 def part_selected(self, button, dev=None, minor=None):
169 minor = int(minor)
170 tmppart = self.devices[dev].get_partitions()[minor]
171 self.info_partition.set_text(dev + str(minor))
172 if int(minor) < 5:
173 if tmppart.get_type() == "extended":
174 self.info_type.set_text("Extended")
175 else:
176 self.info_type.set_text("Primary")
177 else:
178 self.info_type.set_text("Logical")
179 type = tmppart.get_type()
180 if type == "extended":
181 self.info_filesystem.set_text("N/A")
182 else:
183 self.info_filesystem.set_text(type)
184 start = tmppart.get_start()
185 end = tmppart.get_end()
186 # self.info_start.set_text(str(start))
187 # self.info_end.set_text(str(end))
188 # part_size = int(round(float(self.devices[dev].get_sector_size()) * (end - start + 1) / 1024 / 1024))
189 part_size = int(tmppart.get_mb())
190 self.info_size.set_text(str(part_size) + " MB")
191 self.active_part_minor = int(tmppart.get_minor())
192 self.part_button_delete.set_sensitive(True)
193 self.part_info_box.show_all()
194 self.part_button_box.show_all()
195
196 def unalloc_selected(self, button, dev=None, extended=False, mb=0, minor=0):
197 props = PartProperties.PartProperties(self, self.active_device, minor, 0, mb, "free", self.active_device_bytes_in_sector)
198 props.run()
199
200 def part_button_delete_clicked(self, button, data=None):
201 msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="Are you sure you want to delete " + self.active_device + str(self.active_part_minor))
202 resp = msgdlg.run()
203 msgdlg.destroy()
204 if resp == gtk.RESPONSE_YES:
205 self.devices[self.active_device].remove_partition(self.active_part_minor)
206 if self.active_part_minor > 4:
207 ext_part = self.devices[self.active_device].get_extended_partition()
208 if len(self.devices[self.active_device].get_partitions()[ext_part].get_logicals()) == 0:
209 self.devices[self.active_device].remove_partition(ext_part)
210 self.drive_changed(None)
211
212 def draw_part_box(self):
213 partlist = self.devices[self.active_device].get_ordered_partition_list()
214 tmpparts = self.devices[self.active_device].get_partitions()
215 cylinders = self.devices[self.active_device].get_num_cylinders()
216 sectors = self.devices[self.active_device].get_num_sectors()
217 total_mb = self.devices[self.active_device].get_total_mb()
218 for button in self.part_buttons.keys():
219 self.part_table.remove(self.part_buttons[button])
220 self.part_table.resize(1, 100)
221 self.part_buttons = {}
222 last_percent = 0
223 last_log_percent = 0
224 extended_part = 0
225 extended_table = None
226 for part in partlist:
227 tmppart = tmpparts[part]
228 if tmppart.get_type() == "free":
229 partsize = tmppart.get_mb()
230 percent = (float(partsize) / float(total_mb)) * 100
231 if percent < 1: percent = 1
232 percent = int(percent)
233 # print "minor: " + str(part) + ", mb: " + str(partsize) + ", percent: " + str(percent) + ", last_percent: " + str(last_percent)
234 if tmppart.is_logical():
235 tmpbutton = PartitionButton.Partition(color1=self.colors['unalloc'], color2=self.colors['unalloc'], label="", division=0)
236 tmpbutton.connect("clicked", self.unalloc_selected, self.active_device, False, partsize, part)
237 extended_table.attach(tmpbutton, last_log_percent, (last_log_percent + percent), 0, 1)
238 last_log_percent = last_log_percent + percent
239 else:
240 self.part_buttons['free_' + str(part)] = PartitionButton.Partition(color1=self.colors['unalloc'], color2=self.colors['unalloc'], label="", division=0)
241 if self.devices[self.active_device].get_partitions().has_key(1) and self.devices[self.active_device].get_partitions().has_key(2) and self.devices[self.active_device].get_partitions().has_key(3) and self.devices[self.active_device].get_partitions().has_key(4):
242 self.part_buttons['free_' + str(part)].connect("clicked", self.show_no_more_primary_message)
243 else:
244 self.part_buttons['free_' + str(part)].connect("clicked", self.unalloc_selected, self.active_device, False, partsize, part)
245 self.part_table.attach(self.part_buttons['free_' + str(part)], last_percent, (last_percent + percent), 0, 1)
246 last_percent = last_percent + percent
247 else:
248 partsize = tmppart.get_mb()
249 percent = (float(partsize) / float(total_mb)) * 100
250 if percent < 1: percent = 1
251 percent = int(percent)
252 tmpminor = int(tmppart.get_minor())
253 tmpdevice = self.active_device
254 # print "minor: " + str(tmpminor) + ", mb: " + str(partsize) + ", percent: " + str(percent) + ", last_percent: " + str(last_percent)
255 if tmppart.is_extended():
256 extended_table = gtk.Table(1, percent)
257 extended_table.set_border_width(3)
258 extended_part = tmpminor
259 self.part_buttons[tmpminor] = extended_table
260 self.part_table.attach(self.part_buttons[tmpminor], last_percent, (last_percent + percent), 0, 1)
261 last_percent = last_percent + percent
262 elif tmppart.is_logical():
263 tmpbutton = PartitionButton.Partition(color1=self.colors[tmppart.get_type()], color2=self.colors[tmppart.get_type()], label="", division=0)
264 if percent >= 15:
265 tmpbutton.set_label(tmpdevice + str(tmpminor))
266 extended_table.attach(tmpbutton, last_log_percent, (last_log_percent + percent), 0, 1)
267 last_log_percent = last_log_percent + percent
268 tmpbutton.connect("clicked", self.part_selected, tmpdevice, tmpminor)
269 else:
270 self.part_buttons[tmpminor] = PartitionButton.Partition(color1=self.colors[tmppart.get_type()], color2=self.colors[tmppart.get_type()], label="", division=0)
271 if percent >= 15:
272 self.part_buttons[tmpminor].set_label(tmpdevice + str(tmpminor))
273 self.part_buttons[tmpminor].connect("clicked", self.part_selected, tmpdevice, tmpminor)
274 self.part_table.attach(self.part_buttons[tmpminor], last_percent, (last_percent + percent), 0, 1)
275 last_percent = last_percent + percent
276 self.part_table.show_all()
277
278 def show_no_more_primary_message(self, button, data=None):
279 msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format="You cannot create more than 4 primary partitions. If you need more partitions, delete one or more and create logical partitions.")
280 msgdlg.run()
281 msgdlg.destroy()
282
283 def dump_part_info_to_console(self, button, data=None):
284 import pprint
285 pp = pprint.PrettyPrinter(indent=4)
286 pp.pprint(self.devices[self.active_device].get_install_profile_structure())
287
288 def part_button_properties_clicked(self, widget, data=None):
289 tmppart = self.devices[self.active_device].get_partitions()[self.active_part_minor]
290 # props = PartProperties.PartProperties(self, self.active_device, self.active_part_minor, tmppart.get_min_sectors_for_resize(), tmppart.get_max_sectors_for_resize(), tmppart.get_type(), self.active_device_bytes_in_sector)
291 props = PartProperties.PartProperties(self, self.active_device, self.active_part_minor, 0, tmppart.get_mb(), tmppart.get_type(), self.active_device_bytes_in_sector)
292 props.run()
293
294 def activate(self):
295 # self.controller.SHOW_BUTTON_EXIT = True
296 # self.controller.SHOW_BUTTON_HELP = True
297 # self.controller.SHOW_BUTTON_BACK = True
298 # self.controller.SHOW_BUTTON_FORWARD = True
299 # self.controller.SHOW_BUTTON_FINISH = False
300
301 if not len(self.drives):
302 part_load_error = 0
303 tmp_drives = GLIStorageDevice.detect_devices()
304 tmp_drives.sort()
305 for drive in tmp_drives:
306 # try:
307 self.devices[drive] = GLIStorageDevice.Device(drive)
308 self.devices[drive].set_partitions_from_disk()
309 self.detected_dev_combo.append_text(drive)
310 self.drives.append(drive)
311 # except:
312 # print "Exception received while loading partitions"
313 # if self.devices.has_key(drive): del self.devices[drive]
314 # part_load_error = 1
315 if part_load_error:
316 if len(self.drives):
317 msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_WARN, buttons=gtk.BUTTONS_OK, message_format="One or more drives' partition tables could not be read")
318 msgdlg.run()
319 msgdlg.destroy()
320 else:
321 msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format="The installer could not read the partition table on any detected drives. You will be forced to use the ugly mode.")
322 msgdlg.run()
323 msgdlg.destroy()
324 # self._parent.switch_screen(None, 1) # Switch to ugly screen
325 self._parent.radio_ugly.set_active(True)
326 self._parent.radio_pretty.set_sensitive(False)
327 self._parent.radio_ugly.set_sensitive(False)
328 return
329
330 if len(self.drives):
331 self.active_device = self.drives[0]
332 self.detected_dev_combo.set_active(0)
333 self.drive_changed(None)
334
335 def deactivate(self):
336 parts_tmp = {}
337 for part in self.devices.keys():
338 parts_tmp[part] = self.devices[part].get_install_profile_structure()
339 self.controller.install_profile.set_partition_tables(parts_tmp)
340
341 return True

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20