예제 #1
0
def woezel_callback(text, error):
    global category_stats
    rgb.clear()
    rgb.framerate(20)
    rgb.setfont(rgb.FONT_7x5)
    print(text)

    if 'Connecting to WiFi' in text:
        data, size, frames = animation_connecting_wifi
        rgb.framerate(3)
        rgb.gif(data, (12, 0), size, frames)
    elif 'Failed to connect to WiFi' in text:
        data, frames = icon_no_wifi
        rgb.gif(data, (12, 0), (8, 8), frames)
        time.sleep(3)
        system.reboot()
    elif 'Downloading categories...' in text:
        data, size, frames = animation_loading
        rgb.gif(data, (1, 1), size, frames)
        rgb.scrolltext('Loading', pos=(8, 0), width=(rgb.PANEL_WIDTH - 8))
    elif 'Installing' in text:
        data, size, frames = animation_loading
        rgb.gif(data, (1, 1), size, frames)
        rgb.scrolltext(text, pos=(8, 0), width=(rgb.PANEL_WIDTH - 8))
    elif "Downloading '" in text:
        cur, total = text.split('(')[1].split(')')[0].split(
            '/')  # Definitely not proud of this
        progress = '(%s/%s)' % (cur, total)
        data, size, frames = animation_loading
        rgb.gif(data, (1, 1), size, frames)
        rgb.setfont(rgb.FONT_6x3)
        rgb.text(progress, pos=(8, 1))
    elif 'Done!' in text or 'Failed!' in text:
        pass
예제 #2
0
 def test_reboot_while_flashing_refused(
     self, mocked_call, mocked_other_flasher_running
 ):
     with self.assertRaises(SystemExit) as context_manager:
         system.reboot(False, "testing", self.logger)
         mocked_call.assert_not_called()
         self.assertEqual(context_manager.exception.code, 1)
예제 #3
0
def passInputDone(passIn):
    badge.nvs_set_str("system", "wifi.password", passIn)
    ugfx.clear(ugfx.WHITE)
    ugfx.string(100, 50, 'Restarting!', 'Roboto_Regular18', ugfx.BLACK)
    ugfx.flush()
    badge.eink_busy_wait()
    system.reboot()
예제 #4
0
def connectClick(pushed):
    if pushed:
        selected = options.selected_text().encode()
        print('selected')
        options.destroy()

        ssidType = scanResults[ssidList.index(selected)][4]
        print(ssidType)
        print(ssidList.index(selected))
        ugfx.clear(ugfx.WHITE)
        ugfx.string(100, 50, selected, 'Roboto_Regular18', ugfx.BLACK)
        ugfx.flush()
        if ssidType == 5:
            clearGhosting()
            ugfx.clear(ugfx.WHITE)
            ugfx.string(20, 50, 'WPA Enterprise unsupported...',
                        'Roboto_Regular18', ugfx.BLACK)
            ugfx.set_lut(ugfx.LUT_FULL)
            ugfx.flush()
            badge.eink_busy_wait()
            system.reboot()

        badge.nvs_set_str("system", "wifi.ssid", selected)

        if ssidType == 0:
            badge.nvs_set_str("system", "wifi.password", '')
            system.reboot()
        else:
            clearGhosting()
            dialogs.prompt_text("WiFi password", cb=passInputDone)
예제 #5
0
def action(action):
    if action is "shutdown":
        system.shutdown()
    elif action is "reboot":
        system.reboot()

    response = app.response_class(
        response = action + " initiated.",
        status=200,
        mimetype='text/plain'
    )

    return response
예제 #6
0
 def test_reboot(self, mocked_shutdown, mocked_call, mocked_other_flasher_running):
     inputs_outputs = [
         (
             True,
             ["wall", "pypartition would be testing if this were not a dry run."],
         ),
         (False, ["shutdown", "-r", "now", "pypartition is testing."]),
     ]
     for (dry_run, expected_arguments) in inputs_outputs:
         with self.assertRaises(SystemExit):
             system.reboot(dry_run, "testing", self.logger)
             mocked_call.assert_called_once_with(expected_arguments)
             mocked_shutdown.assert_called()
예제 #7
0
 def test_reboot(self, mocked_shutdown, mocked_call,
                 mocked_other_flasher_running):
     inputs_outputs = [
         (True, [
             'wall',
             'pypartition would be testing if this were not a dry run.'
         ]),
         (False, ['shutdown', '-r', 'now', 'pypartition is testing.']),
     ]
     for (dry_run, expected_arguments) in inputs_outputs:
         with self.assertRaises(SystemExit):
             system.reboot(dry_run, 'testing', self.logger)
             mocked_call.assert_called_once_with(expected_arguments)
             mocked_shutdown.assert_called()
예제 #8
0
def connectClick(pushed):
	global chosenSsid
	if pushed:
		selected = options.selected_text().encode()
		
		ssidType = scanResults[ssidList.index(selected)][4]
		if ssidType == 5:
			easydraw.messageCentered("WPA Enterprise is not supported yet.", True, "/media/alert.png")
			system.reboot()
		
		chosenSsid = selected
		if ssidType == 0:
			passInputDone(None)
		else:
			keyboard.show("Password","",passInputDone)
def woezel_callback(text, error):
    global category_stats
    rgb.clear()
    rgb.framerate(20)
    rgb.setfont(rgb.FONT_7x5)
    print(text)

    if 'Connecting to WiFi' in text:
        data, size, frames = animation_connecting_wifi
        rgb.framerate(3)
        rgb.gif(data, (12, 0), size, frames)
    elif 'Failed to connect to WiFi' in text:
        data, frames = icon_no_wifi
        rgb.gif(data, (12, 0), (8, 8), frames)
        time.sleep(3)
        system.reboot()
    elif 'Done!' in text or 'Failed!' in text:
        return
    else:
        data, size, frames = animation_loading
        rgb.gif(data, (1, 1), size, frames)
        rgb.scrolltext(text, pos=(8, 0), width=(rgb.PANEL_WIDTH - 8))
        rgb.setfont(rgb.FONT_7x5)
        uinterface.skippabletext(message)

def ap_requires_password(ap_type):
        return "OPEN" != ap_type

ap_list = scan_access_point_list()
ssids = [ap[0] for ap in ap_list]
prompt_message("Select network")

choice = uinterface.menu(ssids)
if not (choice is None):
        chosen_ssid, chosen_ap_type = ap_list[choice]

        pw_required = ap_requires_password(chosen_ap_type)
        if pw_required:
                prompt_message("Enter password")

        chosen_pass = uinterface.text_input() if pw_required else ''
        if not pw_required or chosen_pass:
                # For OTA
                nvs = esp32.NVS("system")
                nvs.set_blob("wifi.ssid", chosen_ssid)
                nvs.set_blob("wifi.password", chosen_pass)
                nvs.commit()
                # For apps
                valuestore.save("system", "wifi.ssid", chosen_ssid)
                valuestore.save("system", "wifi.password", chosen_pass)

system.reboot()
예제 #11
0
def __cbReboot(pressed):
    if pressed:
        system.reboot()
def improve_system(logger):
    # type: (object) -> None
    if not system.is_openbmc():
        logger.error("{} must be run from an OpenBMC system.".format(sys.argv[0]))
        sys.exit(1)

    description = textwrap.dedent(
        """\
        Leave the OpenBMC system better than we found it, by performing one or
        more of the following actions: fetching an image file, validating the
        checksums of the partitions inside an image file, copying the image
        file to flash, validating the checksums of the partitions on flash,
        changing kernel parameters, rebooting.

        The current logic is reboot-happy. If you want to validate the
        checksums of the partitions on flash without rebooting, use
        --dry-run."""
    )
    (checksums, args) = system.get_checksums_args(description)

    # Don't let things like dropped SSH connections interrupt.
    [
        signal.signal(s, signal.SIG_IGN)
        for s in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]
    ]

    (full_flash_mtds, all_mtds) = system.get_mtds()

    [total_memory_kb, free_memory_kb] = system.get_mem_info()
    logger.info(
        "{} KiB total memory, {} KiB free memory.".format(
            total_memory_kb, free_memory_kb
        )
    )

    reboot_threshold_pct = system.get_healthd_reboot_threshold()
    reboot_threshold_kb = ((100 - reboot_threshold_pct) / 100) * total_memory_kb

    # As of May 2019, sample image files are 17 to 23 MiB. Make sure there
    # is space for them and a few flashing related processes.
    max_openbmc_img_size = 23
    openbmc_img_size_kb = max_openbmc_img_size * 1024
    # in the case of no reboot treshold, use a default limit
    default_threshold = 60 * 1024

    # for low memory remediation - ensure downloading BMC image will NOT trigger
    # healthd reboot
    min_memory_needed = max(
        default_threshold, openbmc_img_size_kb + reboot_threshold_kb
    )
    logger.info(
        "Healthd reboot threshold at {}%  ({} KiB)".format(
            reboot_threshold_pct, reboot_threshold_kb
        )
    )
    logger.info("Minimum memory needed for update is {} KiB".format(min_memory_needed))
    if free_memory_kb < min_memory_needed:
        logger.info(
            "Free memory ({} KiB) < minimum required memory ({} KiB), reboot needed".format(
                free_memory_kb, min_memory_needed
            )
        )
        if full_flash_mtds != []:
            [
                system.get_valid_partitions([full_flash], checksums, logger)
                for full_flash in full_flash_mtds
            ]
        else:
            system.get_valid_partitions(all_mtds, checksums, logger)
        system.reboot(args.dry_run, "remediating low free memory", logger)

    if full_flash_mtds == []:
        partitions = system.get_valid_partitions(all_mtds, checksums, logger)
        mtdparts = "mtdparts={}:{},-@0(flash0)".format(
            "spi0.0", ",".join(map(str, partitions))
        )
        system.append_to_kernel_parameters(args.dry_run, mtdparts, logger)
        system.reboot(args.dry_run, "changing kernel parameters", logger)

    reason = "potentially applying a latent update"
    if args.image:
        image_file_name = args.image
        if args.image.startswith("https"):
            try:
                cmd = ["curl", "-k", "-s", "-o", "/tmp/flash", args.image]
                system.run_verbosely(cmd, logger)
                image_file_name = "/tmp/flash"
            except Exception:
                # Python2 may throw OSError here, whereas Python3 may
                # throw FileNotFoundError - common case is Exception.
                args.image = args.image.replace("https", "http")

        if args.image.startswith("http:"):
            cmd = ["wget", "-q", "-O", "/tmp/flash", args.image]
            system.run_verbosely(cmd, logger)
            # --continue might be cool but it doesn't seem to work.
            image_file_name = "/tmp/flash"

        image_file = virtualcat.ImageFile(image_file_name)
        system.get_valid_partitions([image_file], checksums, logger)

        # If /mnt/data is smaller in the new image, it must be made read-only
        # to prevent the tail of the FIT image from being corrupted.
        # Determining shrinkage isn't trivial (data0 is omitted from image
        # image files for one thing) and details may change over time, so just
        # remount every MTD read-only. Reboot is expected to restart the
        # killed processes.
        system.fuser_k_mount_ro(system.get_writeable_mounted_mtds(), logger)

        # Don't let healthd reboot mid-flash (S166329).
        system.remove_healthd_reboot(logger)

        attempts = 0 if args.dry_run else 3
        for mtd in full_flash_mtds:
            system.flash(attempts, image_file, mtd, logger)
        # One could in theory pre-emptively set mtdparts for images that
        # will need it, but the mtdparts generator hasn't been tested on dual
        # flash and potentially other systems. To avoid over-optimizing for
        # what should be a temporary condition, just reboot and reuse the
        # existing no full flash logic.
        reason = "applying an update"

    [
        system.get_valid_partitions([full_flash], checksums, logger)
        for full_flash in full_flash_mtds
    ]
    system.reboot(args.dry_run, reason, logger)
예제 #13
0
def improve_system(logger):
    # type: (object) -> None
    if not system.is_openbmc():
        logger.error('{} must be run from an OpenBMC system.'.format(
            sys.argv[0]))
        sys.exit(1)

    description = textwrap.dedent('''\
        Leave the OpenBMC system better than we found it, by performing one or
        more of the following actions: fetching an image file, validating the
        checksums of the partitions inside an image file, copying the image
        file to flash, validating the checksums of the partitions on flash,
        changing kernel parameters, rebooting.

        The current logic is reboot-happy. If you want to validate the
        checksums of the partitions on flash without rebooting, use
        --dry-run.''')
    (checksums, args) = system.get_checksums_args(description)

    # Don't let things like dropped SSH connections interrupt.
    [
        signal.signal(s, signal.SIG_IGN)
        for s in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]
    ]

    (full_flash_mtds, all_mtds) = system.get_mtds()

    free_memory = system.free_kibibytes()
    logger.info('{} KiB free memory.'.format(free_memory))
    # As of August 2017, sample image files are 15 to 22 MiB. Make sure there
    # is space for them and a few flashing related processes.
    if system.free_kibibytes() < 60 * 1024:
        if full_flash_mtds != []:
            [
                system.get_valid_partitions([full_flash], checksums, logger)
                for full_flash in full_flash_mtds
            ]
        else:
            system.get_valid_partitions(all_mtds, checksums, logger)
        system.reboot(args.dry_run, 'remediating low free memory', logger)

    if full_flash_mtds == []:
        partitions = system.get_valid_partitions(all_mtds, checksums, logger)
        mtdparts = 'mtdparts={}:{},-@0(flash0)'.format(
            'spi0.0', ','.join(map(str, partitions)))
        system.append_to_kernel_parameters(args.dry_run, mtdparts, logger)
        system.reboot(args.dry_run, 'changing kernel parameters', logger)

    reason = 'potentially applying a latent update'
    if args.image:
        image_file_name = args.image
        if args.image.startswith('http'):
            # --continue might be cool but it doesn't seem to work.
            system.run_verbosely(
                ['wget', '-q', '-O', '/tmp/flash', args.image], logger)
            image_file_name = '/tmp/flash'

        image_file = virtualcat.ImageFile(image_file_name)
        system.get_valid_partitions([image_file], checksums, logger)

        # If /mnt/data is smaller in the new image, it must be made read-only
        # to prevent the tail of the FIT image from being corrupted.
        # Determining shrinkage isn't trivial (data0 is omitted from image
        # image files for one thing) and details may change over time, so just
        # remount every MTD read-only. Reboot is expected to restart the
        # killed processes.
        system.fuser_k_mount_ro(system.get_writeable_mounted_mtds(), logger)

        # Don't let healthd reboot mid-flash (S166329).
        system.remove_healthd_reboot(logger)

        attempts = 0 if args.dry_run else 3
        for mtd in full_flash_mtds:
            system.flash(attempts, image_file, mtd, logger)
        # One could in theory pre-emptively set mtdparts for images that
        # will need it, but the mtdparts generator hasn't been tested on dual
        # flash and potentially other systems. To avoid over-optimizing for
        # what should be a temporary condition, just reboot and reuse the
        # existing no full flash logic.
        reason = 'applying an update'

    [
        system.get_valid_partitions([full_flash], checksums, logger)
        for full_flash in full_flash_mtds
    ]
    system.reboot(args.dry_run, reason, logger)
예제 #14
0
def reboot():
    import system
    system.reboot()
예제 #15
0
def input_B(pressed):
    if pressed:
        rgb.clear()
        rgb.text("Bye!")
        sleep(0.5)
        system.reboot()