def create_list_item(self, next_part, win, list_area): '''Add an entry for next_part (a PartitionInfo or SliceInfo) to the DiskWindow ''' next_part.is_dirty = False next_part.restorable = True next_part.orig_offset = next_part.offset.size_as("gb") next_part.orig_size = next_part.size.size_as("gb") next_part.orig_type = next_part.type list_item = ListItem(list_area, window=win, data_obj=next_part) list_item.key_dict.update(DiskWindow.ADD_KEYS) list_item.on_make_inactive = on_leave_part_field list_item.on_make_inactive_kwargs = {"field" : list_item} edit_field = EditField(self.edit_area, window=list_item, numeric_pad=" ", validate=decimal_valid, on_exit=on_exit_edit, error_win=self.error_win, add_obj=False, data_obj=next_part) edit_field.right_justify = True edit_field.validate_kwargs["disk_win"] = self edit_field.key_dict.update(DiskWindow.ADD_KEYS) self.update_part(part_field=list_item) return list_item
def _show(self): '''Create a list of NICs to choose from. If more than 15 NICs are found, create a scrolling region to put them in ''' self.nic = self.install_profile.nic if self.nic.type != NetworkInfo.MANUAL: raise SkipException if len(self.ether_nics) == 1: self.set_nic_in_profile(self.ether_nics[0]) raise SkipException try: selected_nic_name = self.nic.nic_name except AttributeError: selected_nic_name = "" y_loc = 1 y_loc += self.center_win.add_paragraph(NICSelect.PARAGRAPH, y_loc) selected_nic = 0 y_loc += 1 max_nics = min(NICSelect.MAX_NICS, self.center_win.area.lines - y_loc) if len(self.ether_nics) > max_nics: columns = self.win_size_x - NICSelect.LIST_OFFSET win_area = WindowArea(lines=max_nics, columns=columns, y_loc=y_loc, x_loc=NICSelect.LIST_OFFSET, scrollable_lines=len(self.ether_nics)) window = ScrollWindow(win_area, window=self.center_win) y_loc = 0 else: window = self.center_win for nic in self.ether_nics: self.list_area.y_loc = y_loc self.list_area.columns = len(nic) + 1 list_item = ListItem(self.list_area, window=window, text=nic, data_obj=nic) if nic == selected_nic_name: selected_nic = list_item y_loc += 1 self.main_win.do_update() self.center_win.activate_object(selected_nic)
def display_help_topics(self): '''Display the help topics screen.''' self.main_win.set_header_text(HelpScreen.HELP_HEADER) y_loc = 1 y_loc += self.center_win.add_paragraph(HelpScreen.INTRO, y_loc, 1, max_x=(self.win_size_x - 1)) y_loc += 1 area = WindowArea(scrollable_lines=(len(self.help_info) + 1), y_loc=y_loc, x_loc=0) logging.debug("lines=%s", len(self.help_dict)) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) # add the entries to the screen logging.debug("range=%s", len(self.help_info)) for idx, info in enumerate(self.help_info): # create ListItem for each help topic topic_format = info[1] help_topic = self.get_help_topic(info[0]) help_topic = topic_format % help_topic hilite = min(self.win_size_x, textwidth(help_topic) + 1) list_item = ListItem(WindowArea(1, hilite, idx, 0), window=self.scroll_region, text=help_topic) help_screens = info[0] logging.debug("help_screens=%s", list(help_screens)) logging.debug("self.screen_last=%s", self.screen_last) if self.screen_last in help_screens: logging.debug("Set cur_help_idx = %s", idx) self.cur_help_idx = idx logging.debug("beg_y=%d, beg_x=%d", *list_item.window.getbegyx()) self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object(self.cur_help_idx)
def make_field(self, label, description, y_loc, max_y, max_x, description_start, default_val, is_ip=True): '''Create a list item with 'label', add an editable field with 'default_val', and add additional 'description' text following it ''' self.list_area.y_loc = y_loc list_item = ListItem(self.list_area, text=label, data_obj=label, window=self.center_win) if is_ip: validate = incremental_validate_IP else: validate = None edit_field = EditField(self.edit_area, window=list_item, text=default_val, validate=validate, error_win=self.main_win.error_line, data_obj=label.rstrip(":")) self.center_win.add_paragraph(description, y_loc, description_start, max_y=(y_loc + max_y), max_x=max_x) return edit_field
def pop_up(self, header, question, left_btn_txt, right_btn_txt, color=None): '''Suspend the current screen, setting the header to 'header', presenting the 'question,' and providing two 'buttons'. Returns True if the RIGHT button is selected, False if the LEFT is selected. The LEFT button is initially selected. ''' # Hide the cursor, storing its previous state (visibility) so # it can be restored when finished. Then, move the cursor # to the default position (in case this terminal type does not support # hiding the cursor entirely) try: old_cursor_state = curses.curs_set(0) except curses.error: old_cursor_state = 2 cursor_loc = curses.getsyx() curses.setsyx(self.cursor_pos[0], self.cursor_pos[1]) # Add the header, a border, and the question to the window self.popup_win.window.border() header_x = (self.popup_win.area.columns - textwidth(header)) / 2 self.popup_win.add_text(header, 0, header_x) y_loc = 2 y_loc += self.popup_win.add_paragraph(question, y_loc, 2) y_loc += 2 # Set the background color based on the parameter given, or choose # a default based on the theme. Set the highlight_color by flipping # the A_REVERSE bit of the color if color is None: color = self.popup_win.color self.popup_win.set_color(color) highlight_color = color ^ curses.A_REVERSE # Create two "buttons" of equal size by finding the larger of the # two, and centering them max_len = max(textwidth(left_btn_txt), textwidth(right_btn_txt)) left_btn_txt = " [ %s ]" % left_btn_txt.center(max_len) right_btn_txt = " [ %s ]" % right_btn_txt.center(max_len) button_len = textwidth(left_btn_txt) + 1 win_size = self.popup_win.window.getmaxyx() left_area = WindowArea(1, button_len, y_loc, (win_size[1] / 2) - (button_len + 2)) left_button = ListItem(left_area, window=self.popup_win, text=left_btn_txt, color=color, highlight_color=highlight_color) right_area = WindowArea(1, button_len, y_loc, win_size[1] / 2 + 2) right_button = ListItem(right_area, window=self.popup_win, text=right_btn_txt, color=color, highlight_color=highlight_color) # Highlight the left button, clear any errors on the screen, # and display the pop up self.popup_win.activate_object(left_button) self.popup_win.no_ut_refresh() self.error_line.clear_err() self.do_update() self._active_win = self.popup_win # Loop until the user selects an option. input_key = None while input_key != curses.KEY_ENTER: input_key = self.getch() input_key = self.popup_win.process(input_key) if input_key == curses.KEY_LEFT: self.popup_win.activate_object(left_button) elif input_key == curses.KEY_RIGHT: self.popup_win.activate_object(right_button) self.do_update() self._active_win = self.central_area user_selected = (self.popup_win.get_active_object() is right_button) # Clear the pop up and restore the previous screen, including the # cursor position and visibility self.popup_win.clear() self.central_area.redrawwin() curses.setsyx(cursor_loc[0], cursor_loc[1]) try: curses.curs_set(old_cursor_state) except curses.error: pass self.do_update() return user_selected
def _show(self): ''' Prepare the editable fields for day, month, year, hour and minute ''' y_loc = 1 y_loc += self.center_win.add_paragraph(DateTimeScreen.PARAGRAPH, y_loc) os.environ["TZ"] = self.install_profile.system.tz_timezone now = datetime.datetime.now() logging.debug("now year month day hour minute: %s %s %s %s %s", now.year, now.month, now.day, now.hour, now.minute) # Only update saved values if this is first time on screen or # if we have saved offset in profile (F2, return to screen) # update_vals = False if self.saved_year is None: update_vals = True showtime = now elif self.install_profile.system.time_offset != 0: showtime = now + self.install_profile.system.time_offset update_vals = True self.install_profile.system.time_offset = 0 if update_vals: self.saved_year = str(showtime.year) self.saved_month = str(showtime.month) self.saved_day = str(showtime.day) self.saved_hour = str(showtime.hour) self.saved_minute = str(showtime.minute) self.saved_days_in_month = calendar.monthrange( showtime.year, showtime.month)[1] logging.debug("starting year month day hour minute:_%s_%s_%s_%s_%s", self.saved_year, self.saved_month, self.saved_day, self.saved_hour, self.saved_minute) logging.debug("starting days_in_month: %s", self.saved_days_in_month) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.year_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.year_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.YEAR_TEXT) self.year_edit = EditField(self.year_edit_area, window=self.year_list, validate=year_valid, error_win=self.year_err, on_exit=year_on_exit, text=self.saved_year) self.year_edit.clear_on_enter = True self.center_win.add_text(DateTimeScreen.YEAR_FORMAT, y_loc, self.info_offset) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.month_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.month_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.MONTH_TEXT) self.month_edit = EditField(self.edit_area, window=self.month_list, validate=month_valid, error_win=self.month_err, on_exit=month_on_exit, text=self.saved_month, numeric_pad="0") self.month_edit.clear_on_enter = True self.month_edit.right_justify = True self.center_win.add_text("(1-12)", y_loc, self.info_offset) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.day_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.day_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.DAY_TEXT) self.day_edit = EditField(self.edit_area, window=self.day_list, validate=day_valid, error_win=self.day_err, on_exit=day_on_exit, text=self.saved_day, numeric_pad="0") self.day_edit.clear_on_enter = True self.day_edit.right_justify = True self.month_edit.validate_kwargs["date_time"] = self self.month_edit.validate_kwargs["year_edit"] = self.year_edit self.month_edit.validate_kwargs["day_edit"] = self.day_edit self.year_edit.validate_kwargs["date_time"] = self self.year_edit.validate_kwargs["month_edit"] = self.month_edit self.year_edit.validate_kwargs["day_edit"] = self.day_edit self.day_edit.validate_kwargs["date_time"] = self self.day_edit.validate_kwargs["year_edit"] = self.year_edit self.day_edit.validate_kwargs["month_edit"] = self.month_edit self.date_range_loc = (y_loc, self.info_offset) self.update_day_range(self.saved_days_in_month) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.hour_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.hour_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.HOUR_TEXT) self.hour_edit = EditField(self.edit_area, window=self.hour_list, validate=hour_valid, error_win=self.hour_err, on_exit=hour_on_exit, text=self.saved_hour, numeric_pad="0") self.hour_edit.clear_on_enter = True self.hour_edit.right_justify = True self.center_win.add_text("(0-23)", y_loc, self.info_offset) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.minute_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.minute_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.MINUTE_TEXT) self.minute_edit = EditField(self.edit_area, window=self.minute_list, validate=minute_valid, error_win=self.minute_err, on_exit=minute_on_exit, text=self.saved_minute, numeric_pad="0") self.minute_edit.clear_on_enter = True self.minute_edit.right_justify = True self.center_win.add_text("(0-59)", y_loc, self.info_offset) self.main_win.do_update() self.center_win.activate_object(self.year_list)
def _show(self): '''Display partition data for selected disk, and present the two choices ''' if self.install_profile.install_to_pool: raise SkipException if self.x86_slice_mode: if len(self.install_profile.disks) > 1: # When installing on multiple disks use only whole disk EFI type logging.error("Not looking at partitions on multi-dev install") raise SkipException disk = self.install_profile.disks[0] self.disk_info = disk.get_solaris_data() if self.disk_info is None: # No partitions selected - it's whole disk EFI install logging.error("No partitions were selected. Continuing.") raise SkipException logging.debug("bool(self.disk_info.slices)=%s", bool(self.disk_info.slices)) logging.debug("self.disk_info.modified()=%s", self.disk_info.modified()) if not self.disk_info.slices or self.disk_info.modified(): logging.debug("Setting partition.use_whole_segment," "creating default layout, and skipping") self.disk_info.use_whole_segment = True # We only do slice level editing on x86 if there are # existing slices on an existing (unmodified)Solaris # partition self.disk_info.create_default_layout() raise SkipException disp_disk = self.install_profile.original_disks[ 0].get_solaris_data() logging.debug("Preserved partition with existing slices:" " presenting option to install into a slice") else: if len(self.install_profile.disks) > 1: suggested_pool_types = ['mirror'] if len(self.install_profile.disks) > 2: suggested_pool_types.append('raidz') if len(self.install_profile.disks) > 3: suggested_pool_types.append('raidz2') if len(self.install_profile.disks) > 4: suggested_pool_types.append('raidz3') # Show selected disks header_text = self.HEADER_ZPOOL % (SliceInfo.DEFAULT_POOL.data) self.main_win.set_header_text(header_text) y_loc = 1 y_loc += self.center_win.add_paragraph(self.SELECTED_DISKS, start_y=y_loc) for disk in self.install_profile.disks: y_loc += self.center_win.add_paragraph(self.DISK_INFO % { "name": disk.name, "size": disk.size }, start_y=y_loc) y_loc += 2 y_loc += self.center_win.add_paragraph(self.SELECT_POOL_TYPE, start_y=y_loc) pool_type_win_area = WindowArea(1, 1, y_loc, 0) selected_pool_type = 0 for pool_type in suggested_pool_types: pool_type_win_area.y_loc = y_loc pool_type_win_area.columns = len(pool_type) + 1 list_item = ListItem(pool_type_win_area, window=self.center_win, text=pool_type, data_obj=pool_type) if pool_type == self.selected_pool_type_name: selected_pool_type = list_item y_loc += 1 self.main_win.do_update() self.center_win.activate_object(selected_pool_type) else: self.disk_info = self.install_profile.disks[0] disp_disk = self.install_profile.original_disks[0] if self.disk_info.boot: bootable = FDiskPart.BOOT_TEXT else: bootable = "" header_text = self.header_text % \ {"size" : self.disk_info.size.size_as("gb"), "type" : self.disk_info.type, "bootable" : bootable} self.main_win.set_header_text(header_text) if len(self.install_profile.disks) == 1: y_loc = 1 y_loc += self.center_win.add_paragraph(self.paragraph, start_y=y_loc) y_loc += 1 if self.is_x86 and not self.x86_slice_mode: found_parts = bool(self.disk_info.partitions) else: found_parts = bool(self.disk_info.slices) if found_parts: next_line = self.found else: next_line = self.proposed y_loc += self.center_win.add_paragraph(next_line, start_y=y_loc) y_loc += 1 disk_win_area = WindowArea(6, 70, y_loc, 0) self.disk_win = DiskWindow(disk_win_area, disp_disk, window=self.center_win) y_loc += disk_win_area.lines y_loc += 3 whole_disk_width = textwidth(self.use_whole) + 3 cols = int((self.win_size_x - whole_disk_width) / 2) whole_disk_item_area = WindowArea(1, whole_disk_width, y_loc, cols) self.whole_disk_item = ListItem(whole_disk_item_area, window=self.center_win, text=self.use_whole, centered=True) y_loc += 1 partial_width = textwidth(self.use_part) + 3 cols = int((self.win_size_x - partial_width) / 2) partial_item_area = WindowArea(1, partial_width, y_loc, cols) self.partial_disk_item = ListItem(partial_item_area, window=self.center_win, text=self.use_part, centered=True) self.main_win.do_update() if self.disk_info.use_whole_segment: self.center_win.activate_object(self.whole_disk_item) else: self.center_win.activate_object(self.partial_disk_item)
def _show(self): '''Create a list of disks to choose from and create the window for displaying the partition/slice information from the selected disk ''' self.wait_for_disks() self.num_targets = 0 if not self.disks: self.center_win.add_paragraph(DiskScreen.NO_DISKS, 1, 1, max_x=(self.win_size_x - 1)) return if isinstance(self.disks[0], BaseException): if len(self.disks) == 1: raise tgt.TgtError( ("Unexpected error (%s) during target " "discovery. See log for details.") % self.disks[0]) else: self.disks = self.disks[1:] logging.warn("Failure in target discovery, but one or more" " disks found. Continuing.") boot_disk = self.disks[0] for disk in self.disks: if (disk.size.size_as("gb") > self.minimum_size): self.num_targets += 1 if disk.boot: boot_disk = disk self.disks.remove(boot_disk) self.disks.insert(0, boot_disk) if self.num_targets == 0: self.center_win.add_paragraph(DiskScreen.NO_TARGETS, 1, 1, max_x=(self.win_size_x - 1)) return self.main_win.reset_actions() self.main_win.show_actions() y_loc = 1 self.center_win.add_text(DiskScreen.PARAGRAPH, y_loc, 1) y_loc += 1 self.center_win.add_text(self.size_line, y_loc, 1) y_loc += 2 self.center_win.add_text(self.disk_header_text, y_loc, 1) y_loc += 1 self.center_win.window.hline(y_loc, self.center_win.border_size[1] + 1, curses.ACS_HLINE, textwidth(self.disk_header_text)) y_loc += 1 disk_win_area = WindowArea(4, textwidth(self.disk_header_text) + 2, y_loc, 0) disk_win_area.scrollable_lines = len(self.disks) + 1 self.disk_win = ScrollWindow(disk_win_area, window=self.center_win) disk_item_area = WindowArea(1, disk_win_area.columns - 2, 0, 1) disk_index = 0 len_type = DiskScreen.DISK_HEADERS[0][0] - 1 len_size = DiskScreen.DISK_HEADERS[1][0] - 1 len_boot = DiskScreen.DISK_HEADERS[2][0] - 1 len_dev = DiskScreen.DISK_HEADERS[3][0] - 1 len_mftr = DiskScreen.DISK_HEADERS[4][0] - 1 for disk in self.disks: disk_text_fields = [] type_field = disk.type[:len_type] type_field = ljust_columns(type_field, len_type) disk_text_fields.append(type_field) disk_size = disk.size.size_as("gb") size_field = "%*.1f" % (len_size, disk_size) disk_text_fields.append(size_field) if disk.boot: bootable_field = "+".center(len_boot) else: bootable_field = " " * (len_boot) disk_text_fields.append(bootable_field) device_field = disk.name[:len_dev] device_field = ljust_columns(device_field, len_dev) disk_text_fields.append(device_field) if disk.vendor is not None: mftr_field = disk.vendor[:len_mftr] mftr_field = ljust_columns(mftr_field, len_mftr) else: mftr_field = " " * len_mftr disk_text_fields.append(mftr_field) selectable = True if disk_size < self.minimum_size: note_field = self.too_small_text selectable = False elif DiskInfo.GPT in disk.label: note_field = DiskScreen.GPT_LABELED elif disk_size > SliceInfo.MAX_VTOC.size_as("gb"): note_field = self.too_big_warn else: note_field = "" disk_text_fields.append(note_field) disk_text = " ".join(disk_text_fields) disk_item_area.y_loc = disk_index disk_list_item = ListItem(disk_item_area, window=self.disk_win, text=disk_text, add_obj=selectable) disk_list_item.on_make_active = on_activate disk_list_item.on_make_active_kwargs["disk_info"] = disk disk_list_item.on_make_active_kwargs["disk_select"] = self disk_index += 1 self.disk_win.no_ut_refresh() y_loc += 7 disk_detail_area = WindowArea(6, 70, y_loc, 1) self.disk_detail = DiskWindow(disk_detail_area, self.disks[0], window=self.center_win) self.main_win.do_update() self.center_win.activate_object(self.disk_win) self.disk_win.activate_object(self.selected_disk) # Set the flag so that the disk is not copied by on_change_screen, # unless on_activate gets called as a result of the user changing # the selected disk. self.do_copy = False
def _show(self): '''Create the list of time zones''' logging.debug("self.screen %s", self.screen) if self.install_profile.system is None: self.install_profile.system = SystemInfo() self.sys_info = self.install_profile.system self.cur_country = self.sys_info.tz_country self.cur_continent = self.sys_info.tz_region if self.cur_continent == SystemInfo.UTC and self.screen != "regions": raise SkipException self.center_win.border_size = TimeZone.BORDER_WIDTH if self.screen == TimeZone.LOCATIONS: self.cur_timezone_parent = self.cur_continent elif self.screen == TimeZone.TIMEZONE: self.cur_timezone_parent = self.cur_country logging.debug("cur_continent %s, cur_country %s", self.cur_continent, self.cur_country) y_loc = 1 y_loc += self.center_win.add_paragraph(self.intro, y_loc) y_loc += 1 menu_item_max_width = self.win_size_x - TimeZone.SCROLL_SIZE self.center_win.add_text(self.title, y_loc, TimeZone.SCROLL_SIZE) y_loc += 1 self.center_win.window.hline(y_loc, 3, curses.ACS_HLINE, 40) y_loc += 1 tz_list = self.get_timezones(self.cur_continent, self.cur_country) area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(tz_list) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x logging.debug("area.lines=%d, area.columns=%d", area.lines, area.columns) self.scroll_region = ScrollWindow(area, window=self.center_win) utc = 0 if self.screen == TimeZone.REGIONS: utc_area = WindowArea(1, len(TimeZone.UTC_TEXT) + 1, 0, TimeZone.SCROLL_SIZE) utc_item = ListItem(utc_area, window=self.scroll_region, text=TimeZone.UTC_TEXT, data_obj=SystemInfo.UTC) utc = 1 # add the entries to the screen for idx, timezone in enumerate(tz_list): logging.log(LOG_LEVEL_INPUT, "tz idx = %i name= %s", idx, tz_list[idx]) hilite = min(menu_item_max_width, len(timezone) + 1) win_area = WindowArea(1, hilite, idx + utc, TimeZone.SCROLL_SIZE) list_item = ListItem(win_area, window=self.scroll_region, text=timezone, data_obj=timezone) y_loc += 1 self.main_win.do_update() self.center_win.activate_object(self.scroll_region) logging.debug("self.cur_timezone_idx=%s", self.cur_timezone_idx) self.scroll_region.activate_object_force(self.cur_timezone_idx, force_to_top=True)
def _show(self): '''Create a list of disks to choose from and create the window for displaying the partition/slice information from the selected disk ''' self.wait_for_disks() self.num_targets = 0 if not self.disks: self.center_win.add_paragraph(DiskScreen.NO_DISKS, 1, 1, max_x=(self.win_size_x - 1)) return if isinstance(self.disks[0], BaseException): if len(self.disks) == 1: raise tgt.TgtError(("Unexpected error (%s) during target " "discovery. See log for details.") % self.disks[0]) else: self.disks = self.disks[1:] logging.warn("Failure in target discovery, but one or more" " disks found. Continuing.") boot_disk = self.disks[0] for disk in self.disks: if (disk.size.size_as("gb") > self.minimum_size): self.num_targets += 1 if disk.boot: boot_disk = disk self.disks.remove(boot_disk) self.disks.insert(0, boot_disk) if self.num_targets == 0: self.center_win.add_paragraph(DiskScreen.NO_TARGETS, 1, 1, max_x=(self.win_size_x - 1)) return self.main_win.reset_actions() self.main_win.show_actions() y_loc = 1 self.center_win.add_text(DiskScreen.PARAGRAPH, y_loc, 1) y_loc += 1 self.center_win.add_text(self.size_line, y_loc, 1) y_loc += 2 self.center_win.add_text(self.disk_header_text, y_loc, 1) y_loc += 1 self.center_win.window.hline(y_loc, self.center_win.border_size[1] + 1, curses.ACS_HLINE, textwidth(self.disk_header_text)) y_loc += 1 disk_win_area = WindowArea(4, textwidth(self.disk_header_text) + 2, y_loc, 0) disk_win_area.scrollable_lines = len(self.disks) + 1 self.disk_win = ScrollWindow(disk_win_area, window=self.center_win) disk_item_area = WindowArea(1, disk_win_area.columns - 2, 0, 1) disk_index = 0 len_type = DiskScreen.DISK_HEADERS[0][0] - 1 len_size = DiskScreen.DISK_HEADERS[1][0] - 1 len_boot = DiskScreen.DISK_HEADERS[2][0] - 1 len_dev = DiskScreen.DISK_HEADERS[3][0] - 1 len_mftr = DiskScreen.DISK_HEADERS[4][0] - 1 for disk in self.disks: disk_text_fields = [] type_field = disk.type[:len_type] type_field = ljust_columns(type_field, len_type) disk_text_fields.append(type_field) disk_size = disk.size.size_as("gb") size_field = "%*.1f" % (len_size, disk_size) disk_text_fields.append(size_field) if disk.boot: bootable_field = "+".center(len_boot) else: bootable_field = " " * (len_boot) disk_text_fields.append(bootable_field) device_field = disk.name[:len_dev] device_field = ljust_columns(device_field, len_dev) disk_text_fields.append(device_field) if disk.vendor is not None: mftr_field = disk.vendor[:len_mftr] mftr_field = ljust_columns(mftr_field, len_mftr) else: mftr_field = " " * len_mftr disk_text_fields.append(mftr_field) selectable = True if disk_size < self.minimum_size: note_field = self.too_small_text selectable = False elif DiskInfo.GPT in disk.label: note_field = DiskScreen.GPT_LABELED elif disk_size > SliceInfo.MAX_VTOC.size_as("gb"): note_field = self.too_big_warn else: note_field = "" disk_text_fields.append(note_field) disk_text = " ".join(disk_text_fields) disk_item_area.y_loc = disk_index disk_list_item = ListItem(disk_item_area, window=self.disk_win, text=disk_text, add_obj=selectable) disk_list_item.on_make_active = on_activate disk_list_item.on_make_active_kwargs["disk_info"] = disk disk_list_item.on_make_active_kwargs["disk_select"] = self disk_index += 1 self.disk_win.no_ut_refresh() y_loc += 7 disk_detail_area = WindowArea(6, 70, y_loc, 1) self.disk_detail = DiskWindow(disk_detail_area, self.disks[0], window=self.center_win) self.main_win.do_update() self.center_win.activate_object(self.disk_win) self.disk_win.activate_object(self.selected_disk) # Set the flag so that the disk is not copied by on_change_screen, # unless on_activate gets called as a result of the user changing # the selected disk. self.do_copy = False
def _show(self): '''Display the user name, real name, and password fields''' if len(self.install_profile.users) != 2: root = UserInfo() root.login_name = "root" root.is_role = True user = UserInfo() self.install_profile.users = [root, user] self.root = self.install_profile.users[0] self.user = self.install_profile.users[1] logging.debug("Root: %s", self.root) logging.debug("User: %s", self.user) y_loc = 1 self.center_win.add_paragraph(UserScreen.INTRO, y_loc, 1, y_loc + 2, self.win_size_x - 1) y_loc += 3 self.center_win.add_text(UserScreen.ROOT_TEXT, y_loc, 1, self.win_size_x - 1) y_loc += 2 self.error_area.y_loc = y_loc self.list_area.y_loc = y_loc self.root_pass_err = ErrorWindow(self.error_area, window=self.center_win) self.root_pass_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.ROOT_LABEL) self.root_pass_edit = EditField(self.edit_area, window=self.root_pass_list, error_win=self.root_pass_err, masked=True, text=("*" * self.root.passlen)) self.root_pass_edit.clear_on_enter = True y_loc += 1 self.error_area.y_loc = y_loc self.list_area.y_loc = y_loc self.root_confirm_err = ErrorWindow(self.error_area, window=self.center_win) self.root_confirm_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.CONFIRM_LABEL) self.root_confirm_edit = EditField(self.edit_area, window=self.root_confirm_list, masked=True, text=("*" * self.root.passlen), on_exit=pass_match, error_win=self.root_confirm_err) self.root_confirm_edit.clear_on_enter = True rc_edit_kwargs = {"linked_win": self.root_pass_edit} self.root_confirm_edit.on_exit_kwargs = rc_edit_kwargs if not self.install_profile.install_to_pool: y_loc += 2 self.center_win.add_text(UserScreen.USER_TEXT, y_loc, 1, self.win_size_x - 1) y_loc += 2 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.real_name_err = ErrorWindow(self.error_area, window=self.center_win) self.real_name_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.NAME_LABEL) self.real_name_edit = EditField(self.edit_area, window=self.real_name_list, error_win=self.real_name_err, text=self.user.real_name) y_loc += 1 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.username_err = ErrorWindow(self.error_area, window=self.center_win) self.username_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.USERNAME_LABEL) self.username_edit = EditField(self.username_edit_area, window=self.username_list, validate=username_valid_alphanum, error_win=self.username_err, on_exit=username_valid, text=self.user.login_name) y_loc += 1 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.user_pass_err = ErrorWindow(self.error_area, window=self.center_win) self.user_pass_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.USER_PASS_LABEL) self.user_pass_edit = EditField(self.edit_area, window=self.user_pass_list, error_win=self.user_pass_err, masked=True, text=("*" * self.user.passlen)) self.user_pass_edit.clear_on_enter = True y_loc += 1 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.user_confirm_err = ErrorWindow(self.error_area, window=self.center_win) self.user_confirm_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.CONFIRM_LABEL) self.user_confirm_edit = EditField(self.edit_area, window=self.user_confirm_list, masked=True, on_exit=pass_match, error_win=self.user_confirm_err, text=("*" * self.user.passlen)) self.user_confirm_edit.clear_on_enter = True uc_edit_kwargs = {"linked_win": self.user_pass_edit} self.user_confirm_edit.on_exit_kwargs = uc_edit_kwargs self.main_win.do_update() self.center_win.activate_object(self.root_pass_list)
def _show(self): '''Create an EditField for entering hostname, and list items for each of the network types ''' if self.install_profile.system is None: self.install_profile.system = SystemInfo() self.sys_info = self.install_profile.system if self.install_profile.nic is None: self.install_profile.nic = self.nic_info y_loc = 1 y_loc += self.center_win.add_paragraph(NetworkTypeScreen.PARAGRAPH, y_loc) y_loc += 1 self.center_win.add_text(NetworkTypeScreen.HOSTNAME_TEXT, y_loc) max_cols = self.win_size_x - self.hostfield_offset cols = min(max_cols, NetworkTypeScreen.HOSTNAME_SCREEN_LEN) scrollable_columns = SystemInfo.MAX_HOSTNAME_LEN + 1 hostname_area = WindowArea(1, cols, y_loc, self.hostfield_offset, scrollable_columns=scrollable_columns) self.hostname = EditField(hostname_area, window=self.center_win, text=self.sys_info.hostname, validate=hostname_is_valid, error_win=self.main_win.error_line) self.hostname.item_key = None y_loc += 3 if not self.have_nic: self.center_win.add_paragraph(NetworkTypeScreen.NO_NICS_FOUND, y_loc, 1) self.main_win.do_update() activate = self.net_type_dict.get(self.nic_info.type, self.hostname) self.center_win.activate_object(activate) return y_loc += self.center_win.add_paragraph(NetworkTypeScreen.NET_TYPE_TEXT, y_loc) y_loc += 1 item_area = WindowArea(1, NetworkTypeScreen.ITEM_MAX_WIDTH, y_loc, NetworkTypeScreen.ITEM_OFFSET) self.automatic = ListItem(item_area, window=self.center_win, text=NetworkTypeScreen.AUTO_TEXT) self.automatic.item_key = NetworkInfo.AUTOMATIC self.net_type_dict[self.automatic.item_key] = self.automatic self.center_win.add_text(NetworkTypeScreen.AUTO_DETAIL, y_loc, NetworkTypeScreen.ITEM_DESC_OFFSET, self.menu_item_desc_max) y_loc += 2 item_area.y_loc = y_loc self.manual = ListItem(item_area, window=self.center_win, text=NetworkTypeScreen.MANUAL_TEXT) self.manual.item_key = NetworkInfo.MANUAL self.net_type_dict[self.manual.item_key] = self.manual self.center_win.add_text(NetworkTypeScreen.MANUAL_DETAIL, y_loc, NetworkTypeScreen.ITEM_DESC_OFFSET, self.menu_item_desc_max) y_loc += 2 item_area.y_loc = y_loc self.none_option = ListItem(item_area, window=self.center_win, text=NetworkTypeScreen.NONE_TEXT) self.none_option.item_key = NetworkInfo.NONE self.net_type_dict[self.none_option.item_key] = self.none_option self.center_win.add_text(NetworkTypeScreen.NONE_DETAIL, y_loc, NetworkTypeScreen.ITEM_DESC_OFFSET, self.menu_item_desc_max) self.main_win.do_update() activate = self.net_type_dict.get(self.nic_info.type, self.hostname) self.center_win.activate_object(activate)
def _show(self): '''Create a list of pools to choose from, ask user to select BE name and if we should overwrite pool's boot configuration ''' if not self.install_profile.install_to_pool: raise SkipException if len(self.existing_pools) == 0: self.existing_pools.extend(get_zpool_list()) self.num_targets = 0 if len(self.existing_pools) == 0: self.center_win.add_paragraph(ZpoolScreen.NO_POOLS, 1, 1, max_x=(self.win_size_x - 1)) return for pool in self.existing_pools: free_gb = get_zpool_free_size(pool) / 1024 / 1024 / 1024 if (get_zpool_free_size(pool) / 1024 / 1024 / 1024 > self.minimum_size): self.num_targets += 1 else: logging.info("Skipping pool %s: need %d GB, free %d GB" % (pool, self.minimum_size, free_gb)) if self.num_targets == 0: self.center_win.add_paragraph(ZpoolScreen.NO_TARGETS, 1, 1, max_x=(self.win_size_x - 1)) return self.main_win.reset_actions() self.main_win.show_actions() y_loc = 1 self.center_win.add_text(ZpoolScreen.PARAGRAPH, y_loc, 1) y_loc += 1 self.center_win.add_text(self.size_line, y_loc, 1) y_loc += 2 self.center_win.add_text(self.pool_header_text, y_loc, 1) y_loc += 1 self.center_win.window.hline(y_loc, self.center_win.border_size[1] + 1, curses.ACS_HLINE, textwidth(self.pool_header_text)) y_loc += 1 pool_win_area = WindowArea(4, textwidth(self.pool_header_text) + 2, y_loc, 0) pool_win_area.scrollable_lines = len(self.existing_pools) + 1 self.pool_win = ScrollWindow(pool_win_area, window=self.center_win) pool_item_area = WindowArea(1, pool_win_area.columns - 2, 0, 1) pool_index = 0 len_name = ZpoolScreen.POOL_HEADERS[0][0] - 1 len_size = ZpoolScreen.POOL_HEADERS[2][0] - 1 for pool in self.existing_pools: pool_text_fields = [] name_field = pool[:len_name] name_field = ljust_columns(name_field, len_name) pool_text_fields.append(name_field) pool_size = get_zpool_free_size(pool) / 1024 / 1024 / 1024 size_field = "%*.1f" % (len_size, pool_size) pool_text_fields.append(size_field) selectable = True if pool_size < self.minimum_size: note_field = self.too_small_text selectable = False else: note_field = "" pool_text_fields.append(note_field) pool_text = " ".join(pool_text_fields) pool_item_area.y_loc = pool_index pool_list_item = ListItem(pool_item_area, window=self.pool_win, text=pool_text, add_obj=selectable) pool_list_item.on_make_active = on_activate pool_list_item.on_make_active_kwargs["pool_select"] = self pool_index += 1 self.pool_win.no_ut_refresh() y_loc += 7 self.list_area.y_loc = y_loc y_loc += 2 self.error_area.y_loc = y_loc self.be_name_err = ErrorWindow(self.error_area, window=self.center_win) self.be_name_list = ListItem(self.list_area, window=self.center_win, text=ZpoolScreen.BE_LABEL) self.be_name_edit = EditField(self.edit_area, window=self.be_name_list, validate=be_name_valid, error_win=self.be_name_err, text=self.install_profile.be_name) y_loc += 2 boot_configuration_width = textwidth( ZpoolScreen.OVERWRITE_BOOT_CONFIGURATION_LABEL) + 5 cols = int((self.win_size_x - boot_configuration_width) / 2) boot_configuration_area = WindowArea(1, boot_configuration_width, y_loc, cols) self.boot_configuration_item = MultiListItem( boot_configuration_area, window=self.center_win, text=ZpoolScreen.OVERWRITE_BOOT_CONFIGURATION_LABEL, used=self.install_profile.overwrite_boot_configuration) self.boot_configuration_item.on_select = on_select_obc self.boot_configuration_item.on_select_kwargs["pool_select"] = self self.main_win.do_update() self.center_win.activate_object(self.pool_win) self.pool_win.activate_object(self.selected_pool) # Set the flag so that the pool is not copied by on_change_screen, # unless on_activate gets called as a result of the user changing # the selected pool. self.do_copy = False
def _show(self): '''Display partition data for selected disk, and present the two choices ''' if self.x86_slice_mode: disk = self.install_profile.disk self.disk_info = disk.get_solaris_data() if self.disk_info is None: err_msg = "Critical error - no Solaris partition found" logging.error(err_msg) raise ValueError(err_msg) logging.debug("bool(self.disk_info.slices)=%s", bool(self.disk_info.slices)) logging.debug("self.disk_info.modified()=%s", self.disk_info.modified()) if not self.disk_info.slices or self.disk_info.modified(): logging.debug("Setting partition.use_whole_segment," "creating default layout, and skipping") self.disk_info.use_whole_segment = True # We only do slice level editing on x86 if there are # existing slices on an existing (unmodified)Solaris # partition self.disk_info.create_default_layout() raise SkipException disp_disk = self.install_profile.original_disk.get_solaris_data() logging.debug("Preserved partition with existing slices:" " presenting option to install into a slice") else: self.disk_info = self.install_profile.disk disp_disk = self.install_profile.original_disk if self.disk_info.boot: bootable = FDiskPart.BOOT_TEXT else: bootable = u"" header_text = self.header_text % \ {"size" : self.disk_info.size.size_as("gb"), "type" : self.disk_info.type, "bootable" : bootable} self.main_win.set_header_text(header_text) y_loc = 1 y_loc += self.center_win.add_paragraph(self.paragraph, start_y=y_loc) y_loc += 1 if self.is_x86 and not self.x86_slice_mode: found_parts = bool(self.disk_info.partitions) else: found_parts = bool(self.disk_info.slices) if found_parts: next_line = self.found else: next_line = self.proposed y_loc += self.center_win.add_paragraph(next_line, start_y=y_loc) y_loc += 1 disk_win_area = WindowArea(6, 70, y_loc, 0) self.disk_win = DiskWindow(disk_win_area, disp_disk, window=self.center_win) y_loc += disk_win_area.lines y_loc += 3 whole_disk_width = textwidth(self.use_whole) + 3 cols = (self.win_size_x - whole_disk_width) / 2 whole_disk_item_area = WindowArea(1, whole_disk_width, y_loc, cols) self.whole_disk_item = ListItem(whole_disk_item_area, window=self.center_win, text=self.use_whole, centered=True) y_loc += 1 partial_width = textwidth(self.use_part) + 3 cols = (self.win_size_x - partial_width) / 2 partial_item_area = WindowArea(1, partial_width, y_loc, cols) self.partial_disk_item = ListItem(partial_item_area, window=self.center_win, text=self.use_part, centered=True) self.main_win.do_update() if self.disk_info.use_whole_segment: self.center_win.activate_object(self.whole_disk_item) else: self.center_win.activate_object(self.partial_disk_item)