def refresh_partitions(self): def list_compare(store, a, b): d1, m1 = store[a] d2, m2 = store[b] if m1 and not m2: return -1 elif not m1 and m2: return 1 else: return cmp(d1, d2) self.set_widgets_sensitive(self.sel_widgets, False) self.set_widgets_sensitive(self.mount_widgets, False) self.set_widgets_sensitive(self.unmount_widgets, False) if self.filter_entry: filter = self.filter_entry.get_text() else: filter = None old_device = self.get_device() store = gtk.ListStore(str, str) self.set_model(store) self.store = store self.sel = self.get_selection() self.selected = False store.set_sort_func(COLUMN_DEVICE, list_compare) store.set_sort_column_id(COLUMN_DEVICE, gtk.SORT_ASCENDING) partition_list(self.add_partition, old_device, filter=filter, fstype='ocfs2', async=True) if len(store): if not self.selected: self.sel.select_iter(store.get_iter_first()) else: self.update_info(None)
def format_partition(parent, device): partitions = [] def add_partition(device, fstype): partitions.append((device, fstype)) partition_list(add_partition, unmounted=True) if not partitions: error_box(parent, 'No unmounted partitions') return False def sort_partition(x, y): return cmp(x[0], y[0]) partitions.sort(sort_partition) dialog = Dialog(parent=parent, title='Format', buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dialog.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL)) dialog.set_default_response(gtk.RESPONSE_OK) table = gtk.Table(rows=5, columns=2) set_props(table, row_spacing=6, column_spacing=6, border_width=6, parent=dialog.vbox) widgets = [] for row, widget_type in enumerate(entries): widget = widget_type() label = gtk.Label() label.set_text_with_mnemonic(widget_type.label + ':') label.set_mnemonic_widget(widget) set_props(label, xalign=0.0) table.attach(label, 0, 1, row, row + 1) if widget_type == Device: widget.fill(partitions, device) if isinstance(widget, gtk.Entry): widget.set_activates_default(True) if isinstance(widget, gtk.SpinButton): attach_widget = gtk.HBox() attach_widget.pack_start(widget, expand=False, fill=False) else: attach_widget = widget table.attach(attach_widget, 1, 2, row, row + 1) widgets.append(widget) widgets[0].grab_focus() dialog.show_all() while 1: if dialog.run() != gtk.RESPONSE_OK: dialog.destroy() return False dev = widgets[0].get_device() msg = 'Are you sure you want to format %s?' % dev ask = gtk.MessageDialog(parent=dialog, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format=msg) if ask.run() == gtk.RESPONSE_YES: break else: ask.destroy() command = list(base_command) for widget in widgets[1:]: arg = widget.get_arg() if arg: command.extend(arg) command.append(dev) dialog.destroy() mkfs = Process(command, 'Format', 'Formatting...', parent, spin_now=True) success, output, k = mkfs.reap() if not success: error_box(parent, 'Format error: %s' % output) return False return True