Example #1
0
    def _wait_for_entropy(self, data):
        """Wait for entropy.

        :param data: Blivet's callback data
        :return: True if we are out of time, otherwise False
        """
        log.debug(data.msg)
        required_entropy = data.min_entropy
        total_time = self._entropy_timeout
        current_time = 0

        while True:
            # Report the current status.
            current_entropy = get_current_entropy()
            current_percents = min(
                int(current_entropy / required_entropy * 100), 100)
            remaining_time = max(total_time - current_time, 0)
            self._report_entropy_message(current_percents, remaining_time)

            sleep(5)
            current_time += 5

            # Enough entropy gathered.
            if current_percents == 100:
                return False

            # Out of time.
            if remaining_time == 0:
                return True
Example #2
0
    def _update_progress(self):
        if self._terminate:
            # give users time to realize they should stop typing
            time.sleep(3)
            Gtk.main_quit()
            # remove the method from idle queue
            return False
        else:
            self._num_loops += 1
            current_entropy = get_current_entropy()
            current_fraction = min(float(current_entropy) / self._desired_entropy, 1.0)
            remaining = (MAX_ENTROPY_WAIT * 1000 - self._num_loops * LOOP_TIMEOUT) / 1000 / 60.0

            self._progress_bar.set_fraction(current_fraction)
            self._progress_bar.set_text("%(pct)d %% (%(rem)d %(min)s remaining)" % {"pct": (int(current_fraction * 100)),
                                                                                    "rem": math.ceil(remaining),
                                                                                    "min": P_("minute", "minutes", int(remaining))})

            # if we have enough our time ran out, terminate the dialog, but let
            # the progress_bar refresh in the main loop
            self._terminate = (current_entropy >= self._desired_entropy) or (remaining <= 0)

            self.force_cont = (remaining <= 0)

            # keep updating
            return True
Example #3
0
    def _update_progress(self):
        if self._terminate:
            # give users time to realize they should stop typing
            time.sleep(3)
            Gtk.main_quit()
            # remove the method from idle queue
            return False
        else:
            self._num_loops += 1
            current_entropy = get_current_entropy()
            current_fraction = min(float(current_entropy) / self._desired_entropy, 1.0)
            remaining = (MAX_ENTROPY_WAIT * 1000 - self._num_loops * LOOP_TIMEOUT) / 1000 / 60.0

            self._progress_bar.set_fraction(current_fraction)
            self._progress_bar.set_text("%(pct)d %% (%(rem)d %(min)s remaining)" % {"pct": (int(current_fraction * 100)),
                                                                                    "rem": math.ceil(remaining),
                                                                                    "min": P_("minute", "minutes", int(remaining))})

            # if we have enough our time ran out, terminate the dialog, but let
            # the progress_bar refresh in the main loop
            self._terminate = (current_entropy >= self._desired_entropy) or (remaining <= 0)

            self.force_cont = (remaining <= 0)

            # keep updating
            return True
Example #4
0
def _tui_wait(msg, desired_entropy):
    """Tell user we are waiting for entropy"""

    print(msg)
    print(_("Entropy can be increased by typing randomly on keyboard"))
    print(_("After %d minutes, the installation will continue regardless of the "
            "amount of available entropy") % (MAX_ENTROPY_WAIT / 60))
    fd = sys.stdin.fileno()
    termios_attrs_changed = False

    try:
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        termios.tcsetattr(fd, termios.TCSANOW, new)
        termios_attrs_changed = True
    except termios.error as term_err:
        if term_err.args[0] == errno.ENOTTY:
            # "Inappropriate ioctl for device" --> terminal attributes not supported
            pass
        else:
            raise

    # wait for the entropy to become high enough or time has run out
    cur_entr = get_current_entropy()
    secs = 0
    while cur_entr < desired_entropy and secs <= MAX_ENTROPY_WAIT:
        remaining = (MAX_ENTROPY_WAIT - secs) / 60.0
        print(_("Available entropy: %(av_entr)s, Required entropy: %(req_entr)s [%(pct)d %%] (%(rem)d %(min)s remaining)")
                % {"av_entr": cur_entr, "req_entr": desired_entropy,
                   "pct": int((float(cur_entr) / desired_entropy) * 100),
                   "min": P_("minute", "minutes", remaining),
                   "rem": math.ceil(remaining)})
        time.sleep(1)
        cur_entr = get_current_entropy()
        secs += 1

    # print the final state as well
    print(_("Available entropy: %(av_entr)s, Required entropy: %(req_entr)s [%(pct)d %%]")
            % {"av_entr": cur_entr, "req_entr": desired_entropy,
               "pct": int((float(cur_entr) / desired_entropy) * 100)})

    if secs <= MAX_ENTROPY_WAIT:
        print(_("Enough entropy gathered, please stop typing."))
        force_cont = False
    else:
        print(_("Giving up, time (%d minutes) ran out.") % (MAX_ENTROPY_WAIT / 60))
        force_cont = True

    # we are done
    # first let the user notice we are done and stop typing
    time.sleep(5)

    # and then just read everything from the input buffer and revert the
    # termios state
    data = "have something"
    while sys.stdin in select.select([sys.stdin], [], [], 0)[0] and data:
        # just read from stdin and scratch the read data
        data = sys.stdin.read(1)

    if termios_attrs_changed:
        termios.tcsetattr(fd, termios.TCSAFLUSH, old)

    return force_cont