Пример #1
0
    def _spawn_qemu(self):
        qemu_bin = os.environ.get('PEBBLE_QEMU_PATH', 'qemu-pebble')
        qemu_micro_flash = os.path.join(sdk_manager.path_for_sdk(self.version), 'pebble', self.platform, 'qemu',
                                        "qemu_micro_flash.bin")
        qemu_spi_flash = self._get_spi_path()

        for path in (qemu_micro_flash, qemu_spi_flash):
            if not os.path.exists(path):
                raise MissingEmulatorError("Can't launch emulator: missing required file at {}".format(path))

        command = [
            qemu_bin,
            "-rtc", "base=localtime",
            "-serial", "null",
            "-serial", "tcp::{},server,nowait".format(self.qemu_port),
            "-serial", "tcp::{},server".format(self.qemu_serial_port),
            "-pflash", qemu_micro_flash,
            "-gdb", "tcp::{},server,nowait".format(self.qemu_gdb_port),
        ]

        platform_args = {
            'diorite': [
                '-machine', 'pebble-silk-bb',
                '-cpu', 'cortex-m4',
                '-mtdblock', qemu_spi_flash,
            ],
            'chalk': [
                '-machine', 'pebble-s4-bb',
                '-cpu', 'cortex-m4',
                '-pflash', qemu_spi_flash,
            ],
            'basalt': [
                '-machine', 'pebble-snowy-bb',
                '-cpu', 'cortex-m4',
                '-pflash', qemu_spi_flash,
            ],
            'aplite': [
                '-machine', 'pebble-bb2',
                '-cpu', 'cortex-m3',
                '-mtdblock', qemu_spi_flash,
            ]
        }

        command.extend(platform_args[self.platform])
        logger.info("Qemu command: %s", subprocess.list2cmdline(command))
        process = subprocess.Popen(command, stdout=self._get_output(), stderr=self._get_output())
        time.sleep(0.2)
        if process.poll() is not None:
            try:
                subprocess.check_output(command, stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                raise MissingEmulatorError("Couldn't launch emulator:\n{}".format(e.output.strip()))
        self.qemu_pid = process.pid
        self._wait_for_qemu()
Пример #2
0
    def _spawn_pypkjs(self):
        phonesim_bin = os.environ.get('PHONESIM_PATH', 'phonesim.py')
        layout_file = os.path.join(sdk_manager.path_for_sdk(self.version), 'pebble', self.platform, 'qemu',
                                   "layouts.json")

        command = [
            sys.executable,
            phonesim_bin,
            "--qemu", "localhost:{}".format(self.qemu_port),
            "--port", str(self.pypkjs_port),
            "--persist", get_sdk_persist_dir(self.platform, self.version),
            "--layout", layout_file,
            '--debug',
        ]

        account = get_default_account()
        if account.is_logged_in:
            command.extend(['--oauth', account.bearer_token])
        if logger.getEffectiveLevel() <= logging.DEBUG:
            command.append('--debug')
        logger.info("pypkjs command: %s", subprocess.list2cmdline(command))
        process = subprocess.Popen(command, stdout=self._get_output(), stderr=self._get_output())
        time.sleep(0.5)
        if process.poll() is not None:
            try:
                subprocess.check_output(command, stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                raise MissingEmulatorError("Couldn't launch pypkjs:\n{}".format(e.output.strip()))
        self.pypkjs_pid = process.pid
Пример #3
0
    def _copy_spi_image(self, path):
        sdk_qemu_spi_flash = os.path.join(sdk_path(), 'pebble', self.platform, 'qemu', 'qemu_spi_flash.bin.bz2')
        if not os.path.exists(sdk_qemu_spi_flash):
            raise MissingEmulatorError("Your SDK does not support the Pebble Emulator.")
        else:
            try:
                os.makedirs(os.path.dirname(path))
            except OSError as e:
                if e.errno != errno.EEXIST:
                    raise

            # Copy the compressed file.
            with bz2.BZ2File(sdk_qemu_spi_flash) as from_file:
                with open(path, 'wb') as to_file:
                    while True:
                        data = from_file.read(512)
                        if not data:
                            break
                        to_file.write(data)