Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
class DateTimeScreen(BaseScreen):
    '''
    Allow user to select year, month, day, hour, and minute to be
    used to set system clock.
    '''

    HEADER_TEXT = _("Date and Time")

    YEAR_TEXT = _("Year:")
    MONTH_TEXT = _("Month:")
    DAY_TEXT = _("Day:")
    HOUR_TEXT = _("Hour:")
    MINUTE_TEXT = _("Minute:")
    YEAR_FORMAT = _("(YYYY)")

    PARAGRAPH = _("Edit the date and time as necessary.\n"
                  "The time is in 24 hour format.")

    YEAR_DIGITS = 4
    TWO_DIGITS = 2
    YEAR_LEN = len(YEAR_TEXT)
    MONTH_LEN = len(MONTH_TEXT)
    DAY_LEN = len(DAY_TEXT)
    HOUR_LEN = len(HOUR_TEXT)
    MINUTE_LEN = len(MINUTE_TEXT)
    MAX_LEN = max(YEAR_LEN, MONTH_LEN, DAY_LEN, HOUR_LEN, MINUTE_LEN) + 1

    ITEM_OFFSET = 2

    def __init__(self, main_win):
        super(DateTimeScreen, self).__init__(main_win)

        year_edit_width = DateTimeScreen.YEAR_DIGITS + 1
        list_width = DateTimeScreen.MAX_LEN + year_edit_width
        self.list_area = WindowArea(1, list_width, 0,
                                    DateTimeScreen.ITEM_OFFSET)
        self.year_edit_area = WindowArea(1, year_edit_width, 0,
                                         DateTimeScreen.MAX_LEN + 1)
        other_edit_width = DateTimeScreen.TWO_DIGITS + 1
        other_edit_offset = (
            DateTimeScreen.MAX_LEN +
            (DateTimeScreen.YEAR_DIGITS - DateTimeScreen.TWO_DIGITS) + 1)
        self.edit_area = WindowArea(1, other_edit_width, 0, other_edit_offset)
        self.info_offset = (DateTimeScreen.ITEM_OFFSET +
                            self.list_area.columns + 1)
        self.info_width = len(DateTimeScreen.YEAR_FORMAT)
        err_offset = self.info_offset + self.info_width + 2
        err_width = self.win_size_x - err_offset
        self.err_area = WindowArea(1, err_width, 0, err_offset)

        self.year_edit = None
        self.year_err = None
        self.year_list = None
        self.month_edit = None
        self.month_err = None
        self.month_list = None
        self.day_edit = None
        self.day_err = None
        self.day_list = None
        self.hour_edit = None
        self.hour_err = None
        self.hour_list = None
        self.minute_edit = None
        self.minute_err = None
        self.minute_list = None
        self.year_is_valid = True
        self.month_is_valid = True
        self.date_range_loc = None
        self.saved_year = None
        self.saved_month = None
        self.saved_day = None
        self.saved_hour = None
        self.saved_minute = None
        self.saved_days_in_month = None

    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 validate(self):
        '''Verify each of the edit fields'''
        year_value = self.year_edit.get_text()
        month_value = self.month_edit.get_text()
        day_value = self.day_edit.get_text()
        hour_value = self.hour_edit.get_text()
        minute_value = self.minute_edit.get_text()
        logging.debug("year_value=%s", year_value)
        logging.debug("month_value=%s", month_value)
        logging.debug("day_value=%s", day_value)
        logging.debug("hour_value=%s", hour_value)
        logging.debug("minute_value=%s", minute_value)
        had_err = False
        if not self.year_edit.run_on_exit():
            had_err = True
        if not self.month_edit.run_on_exit():
            had_err = True
        if not self.day_edit.run_on_exit():
            had_err = True
        if not self.hour_edit.run_on_exit():
            had_err = True
        if not self.minute_edit.run_on_exit():
            had_err = True
        if had_err:
            raise UIMessage, _("Invalid date/time. See errors above.")

    def update_day_range(self, maxday=31):
        '''
        Update the day range displayed. The max number of days can vary
        depending on the month, so calling functions can update appropriately.
        
        '''
        self.center_win.add_text("(1-%d)" % maxday, self.date_range_loc[0],
                                 self.date_range_loc[1], self.win_size_x - 3)
        self.saved_days_in_month = maxday

    def on_change_screen(self):
        '''Save current user input for return to screen'''
        self.saved_year = self.year_edit.get_text()
        self.saved_month = self.month_edit.get_text()
        self.saved_day = self.day_edit.get_text()
        self.saved_hour = self.hour_edit.get_text()
        self.saved_minute = self.minute_edit.get_text()

    def on_continue(self):
        '''Save time offset to profile'''
        saved_time = datetime.datetime(int(self.year_edit.get_text()),
                                       int(self.month_edit.get_text()),
                                       int(self.day_edit.get_text()),
                                       int(self.hour_edit.get_text()),
                                       int(self.minute_edit.get_text()))
        userdelta = saved_time - datetime.datetime.now()
        logging.debug("delta time=%s", userdelta)
        self.install_profile.system.time_offset = userdelta
        install_datetime = datetime.datetime.now() + userdelta
        logging.debug("date command would be: /usr/bin/date %s",
                      install_datetime.strftime("%m%d%H%M%y"))
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
class UserScreen(BaseScreen):
    '''Allow user to set:
    - root password
    - user real name
    - user login
    - user password
    
    '''

    HEADER_TEXT = _("Users")
    INTRO = _("Define a root password for the system and user account for"
              " yourself.")
    ROOT_TEXT = _("System Root Password")
    ROOT_LABEL = _("Root password:"******"Confirm password:"******"Create a user account")
    NAME_LABEL = _("Your real name:")
    USERNAME_LABEL = _("Username:"******"User password:"******"No Root Password")
    NO_ROOT_TEXT = _("A root password has not been defined. The system is "
                     "completely unsecured.\n\nChoose Cancel to set a "
                     "root password.")
    NO_USER_HEADER = _("No User Password")
    NO_USER_TEXT = _("A user password has not been defined. The user account "
                     "has administrative privileges so the system is "
                     "unsecured.\n\nChoose Cancel to set a user password.")
    CONTINUE_BTN = _("Continue")
    CANCEL_BTN = _("Cancel")

    PASS_SCREEN_LEN = 16
    ITEM_OFFSET = 2

    def __init__(self, main_win):
        super(UserScreen, self).__init__(main_win)
        self.max_text_len = (self.win_size_x - UserScreen.PASS_SCREEN_LEN -
                             UserScreen.ITEM_OFFSET) / 2
        max_field = max(textwidth(UserScreen.ROOT_LABEL),
                        textwidth(UserScreen.CONFIRM_LABEL),
                        textwidth(UserScreen.NAME_LABEL),
                        textwidth(UserScreen.USERNAME_LABEL),
                        textwidth(UserScreen.USER_PASS_LABEL))
        self.text_len = min(max_field + 1, self.max_text_len)
        self.list_area = WindowArea(1, self.text_len, 0,
                                    UserScreen.ITEM_OFFSET)
        scrollable_columns = UserInfo.MAX_PASS_LEN + 1
        self.edit_area = WindowArea(1,
                                    UserScreen.PASS_SCREEN_LEN + 1,
                                    0,
                                    self.text_len,
                                    scrollable_columns=scrollable_columns)
        self.username_edit_area = WindowArea(1, UserInfo.MAX_USERNAME_LEN + 1,
                                             0, self.text_len)
        err_x_loc = 2 * self.max_text_len - self.text_len
        err_width = (self.text_len + UserScreen.PASS_SCREEN_LEN)
        self.error_area = WindowArea(1, err_width, 0, err_x_loc)
        self.root = None
        self.user = None
        self.root_pass_list = None
        self.root_pass_edit = None
        self.root_pass_err = None
        self.root_confirm_err = None
        self.root_confirm_list = None
        self.root_confirm_edit = None
        self.real_name_err = None
        self.real_name_list = None
        self.real_name_edit = None
        self.username_err = None
        self.username_list = None
        self.username_edit = None
        self.user_pass_err = None
        self.user_pass_list = None
        self.user_pass_edit = None
        self.user_confirm_err = None
        self.user_confirm_list = None
        self.user_confirm_edit = None

    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 on_change_screen(self):
        '''Save real name and login name always'''
        if not self.install_profile.install_to_pool:
            self.user.real_name = self.real_name_edit.get_text()
            self.user.login_name = self.username_edit.get_text()
        else:
            self.user.real_name = self.user.login_name = ""
        self.root.is_role = bool(self.user.login_name)

        if self.root_pass_edit.get_text() != self.root_confirm_edit.get_text():
            self.root.password = ""
        else:
            self.root.password = self.root_pass_edit.get_text()
        self.root_pass_edit.clear_text()
        self.root_confirm_edit.clear_text()

        if not self.install_profile.install_to_pool:
            if self.user_pass_edit.get_text(
            ) != self.user_confirm_edit.get_text():
                self.user.password = ""
            else:
                self.user.password = self.user_pass_edit.get_text()
            self.user_pass_edit.clear_text()
            self.user_confirm_edit.clear_text()
        else:
            self.user.password = ""

    def validate(self):
        '''Check for mismatched passwords, bad login names, etc.'''

        color = self.main_win.theme.header

        if self.root_pass_edit.get_text() != self.root_confirm_edit.get_text():
            raise UIMessage, _("Root passwords don't match")
        if not self.install_profile.install_to_pool:
            user_pass = self.user_pass_edit.get_text()
            if user_pass != self.user_confirm_edit.get_text():
                raise UIMessage, _("User passwords don't match")
            login_name = self.username_edit.get_text()
            logging.debug("login_name=%s", login_name)
            username_valid(self.username_edit)
            real_name = self.real_name_edit.get_text()

            logging.debug("real_name=%s", real_name)
            # If password or real_name has been entered, require a login name

            if not login_name:
                if real_name or user_pass:
                    raise UIMessage, _("Enter username or clear all user "
                                       "account fields")

            if login_name and not user_pass:
                continue_anyway = self.main_win.pop_up(
                    UserScreen.NO_USER_HEADER,
                    UserScreen.NO_USER_TEXT,
                    BaseScreen.CANCEL_BUTTON,
                    UserScreen.CONTINUE_BTN,
                    color=color)
                if not continue_anyway:
                    raise UIMessage()

        if not self.root_pass_edit.get_text():
            continue_anyway = self.main_win.pop_up(UserScreen.NO_ROOT_HEADER,
                                                   UserScreen.NO_ROOT_TEXT,
                                                   BaseScreen.CANCEL_BUTTON,
                                                   UserScreen.CONTINUE_BTN,
                                                   color=color)
            if not continue_anyway:
                raise UIMessage()
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
class NetworkTypeScreen(BaseScreen):
    '''
    Let the user:
    - Choose the hostname
    - Select network type (Automatic, Manual, or None)
    '''

    HEADER_TEXT = _("Network")
    PARAGRAPH = _("Enter a name for this computer that identifies it on "
                  "the network. It must be at least two characters. It "
                  "can contain letters, numbers, and minus signs (-).")
    HOSTNAME_TEXT = _("Computer Name: ")
    NET_TYPE_TEXT = _("Select how the wired ethernet network "
                      "connection is configured.")
    AUTO_TEXT = _("Automatically")
    AUTO_DETAIL = _("Automatically configure the connection")
    MANUAL_TEXT = _("Manually")
    MANUAL_DETAIL = _("Enter the information on the following screen")
    NONE_TEXT = _("None")
    NONE_DETAIL = _("Do not configure the network at this time")
    NO_NICS_FOUND = _("No wired network interfaces found. Additional "
                      "device drivers may be needed.")

    ITEM_OFFSET = 2
    ITEM_MAX_WIDTH = 17
    ITEM_DESC_OFFSET = ITEM_MAX_WIDTH + ITEM_OFFSET + 1
    HOSTNAME_SCREEN_LEN = 25

    def __init__(self, main_win):
        super(NetworkTypeScreen, self).__init__(main_win)
        self.hostfield_offset = textwidth(NetworkTypeScreen.HOSTNAME_TEXT)
        self.menu_item_desc_max = (self.win_size_x -
                                   NetworkTypeScreen.ITEM_DESC_OFFSET)

        self.net_type_dict = {}
        self.sys_info = None
        self.automatic = None
        self.manual = None
        self.none_option = None
        self.hostname = None
        self.nic_info = NetworkInfo()
        self.ether_nics = NetworkInfo.find_links()
        self.have_nic = True
        if len(self.ether_nics) == 0:
            self.have_nic = False

    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 on_change_screen(self):
        '''Save hostname and selected network type on change screen'''
        if self.have_nic:
            self.nic_info.type = self.center_win.get_active_object().item_key
        else:
            self.nic_info.type = NetworkInfo.NONE
        logging.info("Configuring NIC as: %s", self.nic_info.type)
        self.sys_info.hostname = self.hostname.get_text()

    def validate(self):
        '''Ensure hostname is set and a network type is chosen (unless no
        NICs are present)
        
        '''
        hostname_text = self.hostname.get_text()
        if not hostname_text:
            raise UIMessage(_("A Hostname is required."))
        if len(hostname_text) < 2:
            raise UIMessage(_("A Hostname must be at least two characters."))
        if self.have_nic:
            item_key = self.center_win.get_active_object().item_key
            if item_key not in self.net_type_dict:
                raise UIMessage(
                    _("Select the wired network configuration: "
                      "Automatically or None."))
Ejemplo n.º 9
0
class ZpoolScreen(BaseScreen):
    '''
    Allow the user to select a (valid) zpool target for installation
    '''

    HEADER_TEXT = _("Pools")
    PARAGRAPH = _("Where should %(release)s be installed?") % RELEASE
    SIZE_TEXT = _("Recommended size:  %(recommend).1fGB      "
                  "Minimum size: %(min).1fGB")
    POOL_SEEK_TEXT = _("Seeking pools on system")
    TOO_SMALL = _("Too small")
    NO_POOLS = _("No pools found. ")
    NO_TARGETS = _("%(release)s cannot be installed on any pool") % RELEASE
    TGT_ERROR = _("An error occurred while searching for installation"
                  " targets. Please check the install log and file a bug"
                  " at bugs.openindiana.org.")
    OVERWRITE_BOOT_CONFIGURATION_LABEL = _(
        "Overwrite pool's boot configuration")
    BE_LABEL = _("Select BE name:")
    FILESYSTEM_EXISTS_ERROR = _(
        "ZFS file system"
        " %(pool_name)s/ROOT/%(be_name)s already exists")
    BE_NAME_EMPTY_ERROR = _("Boot environment name is empty")
    BE_NAME_UNALLOWED_ERROR = _(
        "Boot environment name contains unallowed symbols")

    POOL_HEADERS = [(25, _("Name")), (10, _("Size(GB)")), (16, _("Notes"))]

    BE_SCREEN_LEN = 32
    ITEM_OFFSET = 2

    def __init__(self, main_win):
        super(ZpoolScreen, self).__init__(main_win)

        pool_header_text = []
        for header in ZpoolScreen.POOL_HEADERS:
            header_str = fit_text_truncate(header[1],
                                           header[0] - 1,
                                           just="left")
            pool_header_text.append(header_str)
        self.pool_header_text = " ".join(pool_header_text)

        self.existing_pools = []
        self.num_targets = 0
        max_note_size = ZpoolScreen.POOL_HEADERS[2][0]
        self.too_small_text = ZpoolScreen.TOO_SMALL[:max_note_size]
        self._size_line = None
        self.selected_pool = 0
        self._minimum_size = None
        self._recommended_size = None
        self.pool_win = None

        max_field = max(textwidth(ZpoolScreen.BE_LABEL),
                        textwidth(ZpoolScreen.BE_NAME_EMPTY_ERROR),
                        textwidth(ZpoolScreen.BE_NAME_UNALLOWED_ERROR),
                        textwidth(ZpoolScreen.NO_POOLS))

        self.max_text_len = int((self.win_size_x - ZpoolScreen.BE_SCREEN_LEN -
                                 ZpoolScreen.ITEM_OFFSET) / 2)
        self.text_len = min(max_field + 1, self.max_text_len)
        self.list_area = WindowArea(1, self.text_len, 0,
                                    ZpoolScreen.ITEM_OFFSET)

        self.edit_area = WindowArea(1, ZpoolScreen.BE_SCREEN_LEN + 1, 0,
                                    self.text_len)
        err_x_loc = 2
        err_width = (self.text_len + ZpoolScreen.BE_SCREEN_LEN)
        self.error_area = WindowArea(1, err_width + 1, 0, err_x_loc)
        self.be_name_list = None
        self.be_name_edit = None
        self.be_name_err = None

        self.boot_configuration_item = None
        self.do_copy = False  # Flag indicating if install_profile.pool_name
        # should be copied

    def determine_minimum(self):
        '''Returns minimum install size, fetching first if needed'''
        self.determine_size_data()
        return self._minimum_size

    minimum_size = property(determine_minimum)

    def determine_recommended(self):
        '''Returns recommended install size, fetching first if needed'''
        self.determine_size_data()
        return self._recommended_size

    recommended_size = property(determine_recommended)

    def determine_size_data(self):
        '''Retrieve the minimum and recommended sizes and generate the string
        to present that information.
        
        '''
        if self._minimum_size is None or self._recommended_size is None:
            self._recommended_size = get_recommended_size().size_as("gb")
            self._minimum_size = get_minimum_size().size_as("gb")

    def get_size_line(self):
        '''Returns the line of text displaying the min/recommended sizes'''
        if self._size_line is None:
            size_dict = {
                "recommend": self.recommended_size,
                "min": self.minimum_size
            }
            self._size_line = ZpoolScreen.SIZE_TEXT % size_dict
        return self._size_line

    size_line = property(get_size_line)

    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 on_change_screen(self):
        ''' Assign the selected pool to the InstallProfile, and make note of
        its index (in case the user returns to this screen later)
        
        '''
        if self.pool_win:
            if self.do_copy or self.install_profile.pool_name is None:
                self.install_profile.pool_name = self.existing_pools[
                    self.pool_win.active_object]
            self.selected_pool = self.pool_win.active_object
            self.install_profile.be_name = self.be_name_edit.get_text()

    def validate(self):
        if not self.pool_win:
            raise UIMessage(ZpoolScreen.NO_POOLS)
        pool_name = self.existing_pools[self.pool_win.active_object]
        be_name = self.be_name_edit.get_text()
        if not be_name:
            raise UIMessage(ZpoolScreen.BE_NAME_EMPTY_ERROR)

        be_names = get_zpool_be_names(pool_name)
        if be_name in be_names:
            filesystem_dict = {"pool_name": pool_name, "be_name": be_name}
            raise UIMessage(ZpoolScreen.FILESYSTEM_EXISTS_ERROR %
                            filesystem_dict)
Ejemplo n.º 10
0
    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