How to use the platformio.fs.cd 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 / platformio-core / platformio / commands / check / command.py View on Github external
environment,
    project_dir,
    project_conf,
    filter,
    flags,
    severity,
    silent,
    verbose,
    json_output,
):
    # find project directory on upper level
    if isfile(project_dir):
        project_dir = find_project_dir_above(project_dir)

    results = []
    with fs.cd(project_dir):
        config = ProjectConfig.get_instance(
            project_conf or join(project_dir, "platformio.ini")
        )
        config.validate(environment)

        default_envs = config.default_envs()
        for envname in config.envs():
            skipenv = any(
                [
                    environment and envname not in environment,
                    not environment and default_envs and envname not in default_envs,
                ]
            )

            env_options = config.items(env=envname, as_dict=True)
            env_dump = []
github platformio / platformio-core / platformio / commands / home / rpc / handlers / piocore.py View on Github external
def _thread_task():
            with fs.cd(cwd):
                exit_code = __main__.main(["-c"] + args)
            return (PIOCoreRPC.thread_stdout.get_value_and_reset(),
                    PIOCoreRPC.thread_stderr.get_value_and_reset(), exit_code)
github platformio / platformio-core / platformio / commands / remote.py View on Github external
def device_monitor(ctx, **kwargs):
    project_options = {}
    try:
        with fs.cd(kwargs["project_dir"]):
            project_options = device.get_project_options(kwargs["environment"])
        kwargs = device.apply_project_monitor_options(kwargs, project_options)
    except NotPlatformIOProjectError:
        pass

    kwargs["baud"] = kwargs["baud"] or 9600

    def _tx_target(sock_dir):
        pioplus_argv = ["remote", "device", "monitor"]
        pioplus_argv.extend(device.options_to_argv(kwargs, project_options))
        pioplus_argv.extend(["--sock", sock_dir])
        try:
            pioplus_call(pioplus_argv)
        except exception.ReturnErrorCode:
            pass
github platformio / platformio-core / platformio / commands / run / command.py View on Github external
def cli(ctx, environment, target, upload_port, project_dir, project_conf, jobs,
        silent, verbose, disable_auto_clean):
    # find project directory on upper level
    if isfile(project_dir):
        project_dir = find_project_dir_above(project_dir)

    is_test_running = CTX_META_TEST_IS_RUNNING in ctx.meta

    with fs.cd(project_dir):
        config = ProjectConfig.get_instance(
            project_conf or join(project_dir, "platformio.ini"))
        config.validate(environment)

        # clean obsolete build dir
        if not disable_auto_clean:
            try:
                clean_build_dir(get_project_build_dir(), config)
            except:  # pylint: disable=bare-except
                click.secho(
                    "Can not remove temporary directory `%s`. Please remove "
                    "it manually to avoid build issues" %
                    get_project_build_dir(force=True),
                    fg="yellow")

        handle_legacy_libdeps(project_dir, config)
github platformio / platformio-core / platformio / ide / projectgenerator.py View on Github external
def get_src_files(self):
        result = []
        with fs.cd(self.project_dir):
            for root, _, files in os.walk(self.config.get_optional_dir("src")):
                for f in files:
                    result.append(relpath(join(root, f)))
        return result
github platformio / platformio-core / platformio / commands / check / tools / base.py View on Github external
def get_source_language(self):
        with fs.cd(get_project_dir()):
            for _, __, files in os.walk(self.config.get_optional_dir("src")):
                for name in files:
                    if "." not in name:
                        continue
                    if os.path.splitext(name)[1].lower() in (".cpp", ".cxx", ".ino"):
                        return "c++"
            return "c"
github platformio / platformio-core / platformio / commands / device.py View on Github external
def device_monitor(**kwargs):  # pylint: disable=too-many-branches
    click.echo(
        "Looking for advanced Serial Monitor with UI? "
        "Check http://bit.ly/pio-advanced-monitor"
    )
    project_options = {}
    try:
        with fs.cd(kwargs["project_dir"]):
            project_options = get_project_options(kwargs["environment"])
        kwargs = apply_project_monitor_options(kwargs, project_options)
    except NotPlatformIOProjectError:
        pass

    if not kwargs["port"]:
        ports = util.get_serial_ports(filter_hwid=True)
        if len(ports) == 1:
            kwargs["port"] = ports[0]["port"]
    elif kwargs["port"] and (set(["*", "?", "[", "]"]) & set(kwargs["port"])):
        for item in util.get_serial_ports():
            if fnmatch(item["port"], kwargs["port"]):
                kwargs["port"] = item["port"]
                break

    # override system argv with patched options
github platformio / platformio-core / platformio / builder / tools / piolib.py View on Github external
def include_dir(self):
        if "includeDir" in self._manifest.get("build", {}):
            with fs.cd(self.path):
                return realpath(self._manifest.get("build").get("includeDir"))
        return LibBuilderBase.include_dir.fget(self)
github platformio / platformio-core / platformio / commands / home / rpc / handlers / project.py View on Github external
def _finalize_arduino_import(_, project_dir, arduino_project_dir):
        with fs.cd(project_dir):
            config = ProjectConfig()
            src_dir = config.get_optional_dir("src")
            if os.path.isdir(src_dir):
                fs.rmtree(src_dir)
            shutil.copytree(arduino_project_dir, src_dir)
        return project_dir
github platformio / platformio-core / platformio / home / rpc / handlers / piocore.py View on Github external
def _thread_task():
            with fs.cd(cwd):
                exit_code = __main__.main(["-c"] + args)
            return (
                PIOCoreRPC.thread_stdout.get_value_and_reset(),
                PIOCoreRPC.thread_stderr.get_value_and_reset(),
                exit_code,
            )