How to use the platformio.util.exec_command function in platformio

To help you get started, we’ve selected a few platformio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github platformio / platform-ststm8 / builder / frameworks / spl.py View on Github external
def get_core_files():
    if not isfile(join(env.subst("$PROJECTSRC_DIR"), "stm8s_conf.h")):
        print("Warning! Couldn't find stm8s_conf.h file!")
        return []

    command = [
        env.subst("$CC"), "-m%s" % board_config.get("build.cpu"),
        "-D%s" % board_config.get("build.mcu")[0:8].upper(),
        "-I.", "-I", "%s" % env.subst("$PROJECTSRC_DIR"),
        "-Wp-MM", "-E", "stm8s.h"
    ]

    result = exec_command(
        command,
        cwd=join(FRAMEWORK_DIR, "Libraries", "STM8S_StdPeriph_Driver", "inc"),
        env=env['ENV']
    )

    if result['returncode'] != 0:
        sys.stderr.write(
            "Error: Could not parse library files for the target.\n")
        sys.stderr.write(result['err'])
        env.Exit(1)

    src_files = []
    includes = result['out']
    for inc in includes.split(" "):
        if "_" not in inc or ".h" not in inc or "conf" in inc:
            continue
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / ide / projectgenerator.py View on Github external
    @util.memoized
    def get_project_build_data(self):
        data = {
            "defines": [],
            "includes": [],
            "cxx_path": None
        }
        envdata = self.get_project_env()
        if "env_name" not in envdata:
            return data
        result = util.exec_command(
            ["platformio", "-f", "run", "-t", "idedata",
             "-e", envdata['env_name'], "-d", self.project_dir]
        )

        if result['returncode'] != 0 or '"includes":' not in result['out']:
            raise exception.PlatformioException(
                "\n".join([result['out'], result['err']]))

        output = result['out']
        start_index = output.index('\n{"')
        stop_index = output.rindex('}')
        data = json.loads(output[start_index + 1:stop_index + 1])

        return data
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / commands / upgrade.py View on Github external
cmds = (
            ["pip", "install", "--upgrade", "platformio"],
            ["platformio", "--version"]
        )

        cmd = None
        r = None
        try:
            for cmd in cmds:
                r = None
                r = util.exec_command(cmd)

                # try pip with disabled cache
                if r['returncode'] != 0 and cmd[0] == "pip":
                    r = util.exec_command(["pip", "--no-cache-dir"] + cmd[1:])

                assert r['returncode'] == 0
            assert last in r['out'].strip()
            click.secho(
                "PlatformIO has been successfully upgraded to %s" % last,
                fg="green")
            click.echo("Release notes: ", nl=False)
            click.secho("http://docs.platformio.org/en/latest/history.html",
                        fg="cyan")
        except Exception as e:  # pylint: disable=W0703
            if not r:
                raise exception.UpgradeError(
                    "\n".join([str(cmd), str(e)]))
            permission_errors = (
                "permission denied",
                "not permitted"
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / telemetry.py View on Github external
def _prefill_appinfo(self):
        self['av'] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("Click/%s" % click.__version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        try:
            result = util.exec_command(["scons", "--version"])
            match = re.search(r"engine: v([\d\.]+)", result['out'])
            if match:
                dpdata.append("SCons/%s" % match.group(1))
        except:  # pylint: disable=W0702
            pass
        self['an'] = " ".join(dpdata)
github platformio / platformio-core / scripts / mbed_to_package.py View on Github external
def buildlib(mbed_dir, mcu, lib="mbed"):
    build_command = [
        "python",
        join(mbed_dir, "workspace_tools", "build.py"),
        "--mcu", mcu,
        "-t", "GCC_ARM"
    ]
    if lib is not "mbed":
        build_command.append(lib)
    build_result = exec_command(build_command, cwd=getcwd())
    if build_result['returncode'] != 0:
        print "*     %s doesn't support %s library!" % (mcu, lib)
github platformio / platformio-core / scripts / mbed_to_package.py View on Github external
settings_file = join(mbed_dir, "workspace_tools", "private_settings.py")
    if not isfile(settings_file):
        with open(settings_file, "w") as f:
            f.write("GCC_ARM_PATH = '%s'" %
                    join(get_home_dir(), "packages", "toolchain-gccarmnoneeabi",
                         "bin"))

    makedirs(join(output_dir, "variant"))
    mbed_libs = ["--rtos", "--dsp", "--fat", "--eth", "--usb", "--usb_host"]

    for mcu in set(gccarm.GccArm.TARGETS):
        print "Processing board: %s" % mcu
        buildlib(mbed_dir, mcu)
        for lib in mbed_libs:
            buildlib(mbed_dir, mcu, lib)
        result = exec_command(
            ["python", join(mbed_dir, "workspace_tools", "project.py"),
             "--mcu", mcu, "-i", "emblocks", "-p", "0", "-b"], cwd=getcwd()
        )
        if result['returncode'] != 0:
            print "Unable to build the project for %s" % mcu
            continue
        _unzip_generated_file(mbed_dir, output_dir, mcu)
    copylibs(mbed_dir, output_dir)

    with open(join(output_dir, "boards.txt"), "w") as fp:
        fp.write("\n".join(sorted(listdir(join(output_dir, "variant")))))

    print "Complete!"
github bq / web2board / src / platformio / platforms / base.py View on Github external
self._found_error = False
        args = []
        try:
            args = [os.path.relpath(PathsManager.EXECUTABLE_FILE),  # [JORGE_GARCIA] modified for scons compatibility
                    "-Q",
                    "-j %d" % self.get_job_nums(),
                    "--warn=no-no-parallel-support",
                    "-f", join(util.get_source_dir(), "builder", "main.py")
                    ] + variables + targets + [os.getcwd()]
            if PathsManager.EXECUTABLE_FILE.endswith(".py"):
                args = ["python"] + args
            # test that SCons is installed correctly
            # assert util.test_scons()
            log.debug("Executing: {}".format("\n".join(args)))
            result = util.exec_command(args,
                                       stdout=util.AsyncPipe(self.on_run_out),
                                       stderr=util.AsyncPipe(self.on_run_err))

        except (OSError, AssertionError) as e:
            log.exception("error running scons with \n{}".format(args))
            raise exception.SConsNotInstalledError()

        assert "returncode" in result
        # if self._found_error:
        #     result['returncode'] = 1

        if self._last_echo_line == ".":
            click.echo("")

        return result
github bq / bitbloq-offline / app / res / web2board / win32 / platformio / platforms / base.py View on Github external
self._found_error = False
        args = []
        try:
            args = [os.path.relpath(PathsManager.EXECUTABLE_FILE),  # [JORGE_GARCIA] modified for scons compatibility
                    "-Q",
                    "-j %d" % self.get_job_nums(),
                    "--warn=no-no-parallel-support",
                    "-f", join(util.get_source_dir(), "builder", "main.py")
                    ] + variables + targets + [PathsManager.PLATFORMIO_WORKSPACE_PATH]
            if PathsManager.EXECUTABLE_FILE.endswith(".py"):
                args = ["python"] + args
            # test that SCons is installed correctly
            # assert util.test_scons()
            log.debug("Executing: {}".format("\n".join(args)))
            result = util.exec_command(args,
                                       stdout=util.AsyncPipe(self.on_run_out),
                                       stderr=util.AsyncPipe(self.on_run_err))

        except (OSError, AssertionError) as e:
            log.exception("error running scons with \n{}".format(args))
            raise exception.SConsNotInstalledError()

        assert "returncode" in result
        # if self._found_error:
        #     result['returncode'] = 1

        if self._last_echo_line == ".":
            click.echo("")

        return result