def tune_action(widget_type, parent, device): try: widget = widget_type(device) except ocfs2.error: desc = widget_type.label.replace('_', '') desc = desc.lower() error_box(parent, 'Could not get current %s for device %s' % (desc, device)) return False dialog = Dialog(parent=parent, title=widget_type.title, 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=1, columns=2) set_props(table, row_spacing=6, column_spacing=6, border_width=6, parent=dialog.vbox) label = gtk.Label() label.set_text_with_mnemonic(widget_type.label + ':') set_props(label, xalign=0.0) table.attach(label, 0, 1, 0, 1) label.set_mnemonic_widget(widget) table.attach(widget, 1, 2, 0, 1) if isinstance(widget, gtk.Entry): widget.set_activates_default(True) widget.grab_focus() dialog.show_all() while 1: if dialog.run() != gtk.RESPONSE_OK: dialog.destroy() return False new_label = widget.get_text() if not new_label: if widget_type.empty_ok: msg = ('Are you sure you want to clear the %s on %s?' % (widget_type.lower(), device)) 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() else: error_box(dialog, '%s cannot be empty.' % widget_type.lower().ucfirst()) else: break command = list(base_command) command.extend(widget.get_arg()) command.append(device) dialog.destroy() tunefs = Process(command, widget_type.title, widget_type.action + '...', parent, spin_now=True) success, output, k = tunefs.reap() if not success: error_box(parent, 'File system tune error: %s' % output) return False return True
def node_query(self, title='Node Attributes', defaults=None, editing=False): existing_names = {} existing_ip_addrs = {} for row in self.store: name = row[COLUMN_NAME] ip_addr = row[COLUMN_IP_ADDRESS] if not (editing and name == defaults[COLUMN_NAME]): existing_names[name] = 1 if not (editing and ip_addr == defaults[COLUMN_IP_ADDRESS]): existing_ip_addrs[ip_addr] = name dialog = Dialog(parent=self, title=title, 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=4, columns=2) set_props(table, row_spacing=4, column_spacing=4, border_width=4, parent=dialog.vbox) widgets = [] for row, field in enumerate(fields): if field.widget_type is None: widgets.append(None) continue label = gtk.Label(field.title + ':') set_props(label, xalign=1.0) table.attach(label, 0, 1, row, row + 1) widget = field.widget_type() table.attach(widget, 1, 2, row, row + 1) if field.column == COLUMN_NAME: widget.set_max_length(o2cb.O2NM_MAX_NAME_LEN) elif field.column == COLUMN_IP_PORT: widget.set_numeric(True) adjustment = gtk.Adjustment(PORT_DEFAULT, PORT_MINIMUM, PORT_MAXIMUM, 1, 100) widget.set_adjustment(adjustment) widget.set_value(PORT_DEFAULT) widgets.append(widget) if defaults: for w, d in zip(widgets, defaults): if w and d: w.set_text(d) dialog.show_all() while 1: if dialog.run() != gtk.RESPONSE_OK: dialog.destroy() return None ip_port = widgets[COLUMN_IP_PORT].get_text() name = widgets[COLUMN_NAME].get_text() if not name: error_box(dialog, 'Node name not specified') continue try: ip_addr = widgets[COLUMN_IP_ADDRESS].get_text() except (IPMissing, IPError), msg: error_box(dialog, msg[0]) continue if name in existing_names: error_box(dialog, 'Node %s already exists in the configuration' % name) elif ip_addr in existing_ip_addrs: error_box( dialog, 'IP %s is already assigned to node %s' % (ip_addr, existing_ip_addrs[ip_addr])) else: break
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
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
def tune_action(widget_type, parent, device): try: widget = widget_type(device) except ocfs2.error: desc = widget_type.label.replace('_', '') desc = desc.lower() error_box(parent, 'Could not get current %s for device %s' % (desc, device)) return False dialog = Dialog(parent=parent, title=widget_type.title, 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=1, columns=2) set_props(table, row_spacing=6, column_spacing=6, border_width=6, parent=dialog.vbox) label = gtk.Label() label.set_text_with_mnemonic(widget_type.label + ':') set_props(label, xalign=0.0) table.attach(label, 0, 1, 0, 1) label.set_mnemonic_widget(widget) table.attach(widget, 1, 2, 0, 1) if isinstance(widget, gtk.Entry): widget.set_activates_default(True) widget.grab_focus() dialog.show_all() while 1: if dialog.run() != gtk.RESPONSE_OK: dialog.destroy() return False new_label = widget.get_text() if not new_label: if widget_type.empty_ok: msg = ('Are you sure you want to clear the %s on %s?' % (widget_type.lower(), device)) 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() else: error_box( dialog, '%s cannot be empty.' % widget_type.lower().ucfirst()) else: break command = list(base_command) command.extend(widget.get_arg()) command.append(device) dialog.destroy() tunefs = Process(command, widget_type.title, widget_type.action + '...', parent, spin_now=True) success, output, k = tunefs.reap() if not success: error_box(parent, 'File system tune error: %s' % output) return False return True
def node_query(self, title='Node Attributes', defaults=None, editing=False): existing_names = {} existing_ip_addrs = {} for row in self.store: name = row[COLUMN_NAME] ip_addr = row[COLUMN_IP_ADDRESS] if not (editing and name == defaults[COLUMN_NAME]): existing_names[name] = 1 if not (editing and ip_addr == defaults[COLUMN_IP_ADDRESS]): existing_ip_addrs[ip_addr] = name dialog = Dialog(parent=self, title=title, 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=4, columns=2) set_props(table, row_spacing=4, column_spacing=4, border_width=4, parent=dialog.vbox) widgets = [] for row, field in enumerate(fields): if field.widget_type is None: widgets.append(None) continue label = gtk.Label(field.title + ':') set_props(label, xalign=1.0) table.attach(label, 0, 1, row, row + 1) widget = field.widget_type() table.attach(widget, 1, 2, row, row + 1) if field.column == COLUMN_NAME: widget.set_max_length(o2cb.O2NM_MAX_NAME_LEN) elif field.column == COLUMN_IP_PORT: widget.set_numeric(True) adjustment = gtk.Adjustment(PORT_DEFAULT, PORT_MINIMUM, PORT_MAXIMUM, 1, 100) widget.set_adjustment(adjustment) widget.set_value(PORT_DEFAULT) widgets.append(widget) if defaults: for w, d in zip(widgets, defaults): if w and d: w.set_text(d) dialog.show_all() while 1: if dialog.run() != gtk.RESPONSE_OK: dialog.destroy() return None ip_port = widgets[COLUMN_IP_PORT].get_text() name = widgets[COLUMN_NAME].get_text() if not name: error_box(dialog, 'Node name not specified') continue try: ip_addr = widgets[COLUMN_IP_ADDRESS].get_text() except (IPMissing, IPError), msg: error_box(dialog, msg[0]) continue if name in existing_names: error_box(dialog, 'Node %s already exists in the configuration' % name) elif ip_addr in existing_ip_addrs: error_box(dialog, 'IP %s is already assigned to node %s' % (ip_addr, existing_ip_addrs[ip_addr])) else: break