コード例 #1
0
    def test_refresh_target_returns_target(self, mock_mbed_lstools_create):
        class MockLS(object):
            def __init__(self):
                pass

            def list_mbeds(self, filter_function=None):
                return [{"target_id": "test_id"}]

        mock_mbed_lstools_create.return_value = MockLS()

        target = {"target_id": "test_id"}
        self.assertEqual(target,
                         FlasherMbed.refresh_target(target["target_id"]))
コード例 #2
0
    def test_refresh_target_returns_empty_list_when_no_devices(
            self, mock_mbed_lstools_create):
        class MockLS(object):
            def __init__(self):
                pass

            def list_mbeds(self, filter_function=None):
                return []

        mock_mbed_lstools_create.return_value = MockLS()

        FlasherMbed.REFRESH_TARGET_SLEEP = 0.01
        target = {"target_id": "test_id"}
        self.assertEqual(None, FlasherMbed.refresh_target(target["target_id"]))
コード例 #3
0
ファイル: erase.py プロジェクト: pingdan32/mbed-flasher
    def _erase_board_simple(self, target, no_reset):
        """
        :param target: target to which perform the erase
        :param no_reset: erase with/without reset
        :return: exit code
        """
        if 'mount_point' not in target:
            raise EraseError(message="mount point missing from target",
                             return_code=EXIT_CODE_MOUNT_POINT_MISSING)
        if 'serial_port' not in target:
            raise EraseError(message="serial port missing from target",
                             return_code=EXIT_CODE_SERIAL_PORT_MISSING)

        automation_activated = False
        daplink_version = 0
        if not isfile(join(target["mount_point"], 'DETAILS.TXT')):
            raise EraseError(message="No DETAILS.TXT found",
                             return_code=EXIT_CODE_IMPLEMENTATION_MISSING)

        self.logger.debug(join(target["mount_point"], 'DETAILS.TXT'))
        with open(join(target["mount_point"], 'DETAILS.TXT'),
                  'rb') as new_file:
            for line in new_file:
                if line.find(b"Automation allowed: 1") != -1:
                    automation_activated = True
                if line.find(b"Interface Version") != -1:
                    try:
                        if six.PY2:
                            daplink_version = int(line.split(' ')[-1])
                        else:
                            daplink_version = int(
                                line.decode('utf-8').split(' ')[-1])
                    except (IndexError, ValueError):
                        raise EraseError(
                            message=
                            "Failed to parse DAPLINK version from DETAILS.TXT",
                            return_code=EXIT_CODE_IMPLEMENTATION_MISSING)

        if not automation_activated:
            msg = "Selected device does not have automation activated in DAPLINK"
            raise EraseError(message=msg,
                             return_code=EXIT_CODE_IMPLEMENTATION_MISSING)

        if daplink_version < ERASE_DAPLINK_SUPPORT_VERSION:
            msg = "Selected device has Daplink version {}," \
                  "erasing supported from version {} onwards".\
                format(daplink_version, ERASE_DAPLINK_SUPPORT_VERSION)
            raise EraseError(message=msg,
                             return_code=EXIT_CODE_IMPLEMENTATION_MISSING)

        with open(join(target["mount_point"], 'ERASE.ACT'), 'wb'):
            pass

        auto_thread = Thread(target=self.wait_to_disappear,
                             args=(target["mount_point"], ))
        auto_thread.start()
        while auto_thread.is_alive():
            auto_thread.join(0.5)

        target = FlasherMbed.refresh_target(target["target_id"])
        if not target:
            raise EraseError(message="target id is missing",
                             return_code=EXIT_CODE_TARGET_ID_MISSING)

        auto_thread = Thread(target=self.runner,
                             args=(target["mount_point"], 'ERASE.ACT'))
        auto_thread.start()
        while auto_thread.is_alive():
            auto_thread.join(0.5)

        if not no_reset:
            success = self.reset_board(target["serial_port"])
            if success != 0:
                raise EraseError(message="erase failed", return_code=success)

        self.logger.info("erase %s completed", target['target_id'])
        return EXIT_CODE_SUCCESS