예제 #1
0
    def test_run_rgb_sequence(self):
        header = '\n\n--------------------------------------------------------------------------------------------\
               -[ CK2 Lite ]- TEST: LED Ring \
               --------------------------------------------------------------------------------------------'

        header = colours.decorate_with_preset(header, "code")
        print header

        animation = InitFlow()
        animation.connect()

        response = ''

        while response not in ('yes', 'no', 'y', 'n'):
            animation.start(2.5, 5.0)
            animation.iface.unlock()
            text = 'Did you see the LEDs light up? Please type "y" or "n". Type "r" to replay. '
            text = colours.decorate_with_preset(text, "warning")
            response = raw_input(text).lower().strip()

        saw_animation = (response == 'yes' or response == 'y')

        self.bootAssertTrue(saw_animation,
                            'Animation could not be observed on Pi Hat!')
        self._test_done()
예제 #2
0
    def test_power_button_press_detected(self):
        header = '\n\n--------------------------------------------------------------------------------------------\
               -[ CK2 Lite ]- TEST: Power Button \
               --------------------------------------------------------------------------------------------'

        header = colours.decorate_with_preset(header, "code")
        print header

        loop = GLib.MainLoop()
        timeout = 30
        self.power_button_failure = False

        def button_pressed():
            loop.quit()

        def abort():
            loop.quit()

            text = colours.decorate_with_preset(
                'Button press not detected within {} seconds.\n'
                'Do you wish to try again? Type "y" or "n".\n'.format(timeout),
                'warning')
            response = raw_input(text).lower().strip()

            if response not in ('n', 'no'):
                start_loop()
            else:
                self.power_button_failure = True

        def start_loop():
            GLib.timeout_add_seconds(priority=GLib.PRIORITY_DEFAULT,
                                     interval=timeout,
                                     function=abort)

            print '\nPress the power button\n'
            loop.run()

        dbus.SystemBus().add_signal_receiver(button_pressed,
                                             'power_button_pressed',
                                             SERVICE_API_IFACE,
                                             PI_HAT_BUS_NAME,
                                             PI_HAT_OBJECT_PATH)

        start_loop()

        if self.power_button_failure:
            fail_msg = 'Power button press not detected'
            print colours.decorate_with_preset(fail_msg, 'fail')
            self.bootAssertTrue(False, fail_msg)

        self._test_done()
예제 #3
0
    def write(self, msg, force_flush=False, **kwargs):
        lname = "info"
        if "level" in kwargs:
            lname = normalise_level(kwargs["level"])

        level = LEVELS[lname]
        sys_log_level = LEVELS[self.get_log_level()]
        sys_output_level = LEVELS[self.get_output_level()]

        if level > 0 and (level <= sys_log_level or level <= sys_output_level):
            if self._app_name is None:
                try:
                    self.set_app_name(sys.argv[0])
                except (AttributeError, IndexError):
                    # argv is likely not accessible, use default value
                    self.set_app_name('unknown-app')

            lines = msg.encode('utf8') if type(msg) == unicode else msg
            lines = lines.strip().split("\n")

            log = {}
            log["pid"] = self._pid
            log.update(kwargs)
            log["level"] = lname

            # if an exception object was passed in, add it to the log fields
            tbk = None
            if 'exception' in kwargs:
                import traceback
                tbk = traceback.format_exc()
                log['exception'] = unicode(kwargs['exception']).encode('utf8')
                log['traceback'] = tbk

            for line in lines:
                log["time"] = time.time()
                log["message"] = line

                if level <= sys_log_level:
                    if self._log_file is None:
                        self._init_log_file()
                    self._log_file.write("{}\n".format(json.dumps(log)))

                    if self._force_flush or force_flush:
                        self.sync()

                if level <= sys_output_level:
                    output_line = "{}[{}] {} {}\n".format(
                        self._app_name,
                        decorate_string_only_terminal(self._pid, "yellow"),
                        decorate_with_preset(log["level"], log["level"], True),
                        log["message"])
                    sys.stderr.write(output_line)
예제 #4
0
        def abort():
            loop.quit()

            text = colours.decorate_with_preset(
                'Button press not detected within {} seconds.\n'
                'Do you wish to try again? Type "y" or "n".\n'.format(timeout),
                'warning')
            response = raw_input(text).lower().strip()

            if response not in ('n', 'no'):
                start_loop()
            else:
                self.power_button_failure = True
예제 #5
0
    def write(self, msg, force_flush=False, **kwargs):
        lname = "info"
        if "level" in kwargs:
            lname = normalise_level(kwargs["level"])

        level = LEVELS[lname]
        sys_log_level = LEVELS[self.get_log_level()]
        sys_output_level = LEVELS[self.get_output_level()]

        if level > 0 and (level <= sys_log_level or level <= sys_output_level):
            if self._app_name is None:
                self.set_app_name(sys.argv[0])

            lines = msg.encode('utf8') if type(msg) == unicode else msg
            lines = lines.strip().split("\n")

            log = {}
            log["pid"] = self._pid
            log.update(kwargs)
            log["level"] = lname

            # if an exception object was passed in, add it to the log fields
            tbk = None
            if 'exception' in kwargs:
                import traceback
                tbk = traceback.format_exc()
                log['exception'] = unicode(kwargs['exception']).encode('utf8')
                log['traceback'] = tbk

            for line in lines:
                log["time"] = time.time()
                log["message"] = line

                if level <= sys_log_level:
                    if self._log_file is None:
                        self._init_log_file()
                    self._log_file.write("{}\n".format(json.dumps(log)))

                    if self._force_flush or force_flush:
                        self.sync()

                if level <= sys_output_level:
                    output_line = "{}[{}] {} {}\n".format(
                        self._app_name,
                        decorate_string_only_terminal(self._pid, "yellow"),
                        decorate_with_preset(log["level"], log["level"], True),
                        log["message"]
                    )
                    sys.stderr.write(output_line)
예제 #6
0
    def write(self, msg, force_flush=False, **kwargs):
        lname = "info"
        if "level" in kwargs:
            lname = normalise_level(kwargs["level"])

        level = LEVELS[lname]
        sys_log_level = LEVELS[self.get_log_level()]
        sys_output_level = LEVELS[self.get_output_level()]

        if level > 0 and (level <= sys_log_level or level <= sys_output_level):
            if self._app_name is None:
                self.set_app_name(sys.argv[0])

            lines = str(msg).strip().split("\n")

            log = {}
            log["pid"] = self._pid
            log.update(kwargs)
            log["level"] = lname

            for line in lines:
                log["time"] = time.time()
                log["message"] = line

                if level <= sys_log_level:
                    if self._log_file is None:
                        self._init_log_file()
                    self._log_file.write("{}\n".format(json.dumps(log)))

                    if self._force_flush or force_flush:
                        self.sync()

                if level <= sys_output_level:
                    output_line = "{}[{}] {} {}\n".format(
                        self._app_name,
                        decorate_string_only_terminal(self._pid, "yellow"),
                        decorate_with_preset(log["level"], log["level"], True),
                        log["message"]
                    )
                    sys.stderr.write(output_line)
예제 #7
0
def do_white_rabbit_stage(flow_params):
    init_status = Status.get_instance()

    if not flow_params.get('skip', False):
        clear_screen()
        try:
            rabbit(1, 'left-to-right')
        except:
            pass
        clear_screen()

        msg = _("{string_username}, follow the white rabbit").format(
            string_username=init_status.username)
        typewriter_echo(msg, trailing_linebreaks=2)

        command = decorate_with_preset('cd rabbithole', 'code')
        typewriter_echo(_("Type {string_code_to_type}, then [ENTER]").format(
            string_code_to_type=command),
                        trailing_linebreaks=2)

        # TODO: open shell
        rabbithole = "/home/{}/rabbithole".format(init_status.username)
        ensure_dir(rabbithole)
        cmd = "sudo -u {} -H bash --init-file {}".format(
            init_status.username, SUBSHELLRC_PATH)
        os.system(cmd)
        delete_dir(rabbithole)

        reset_overscan()
        matrix_binary(1, False)
        set_overscan()

        clear_screen()

    init_status.stage = Status.LOVE_STAGE
    init_status.save()