How to use the platformio.fs 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 / ide / projectgenerator.py View on Github external
"src_files": self.get_src_files(),
                    "project_src_dir": self.config.get_optional_dir("src"),
                    "project_lib_dir": self.config.get_optional_dir("lib"),
                    "project_libdeps_dir": join(
                        self.config.get_optional_dir("libdeps"), self.env_name
                    ),
                }
            )

        for key, value in tpl_vars.items():
            if key.endswith(("_path", "_dir")):
                tpl_vars[key] = fs.to_unix_path(value)
        for key in ("includes", "src_files", "libsource_dirs"):
            if key not in tpl_vars:
                continue
            tpl_vars[key] = [fs.to_unix_path(inc) for inc in tpl_vars[key]]

        tpl_vars["to_unix_path"] = fs.to_unix_path
        return tpl_vars
github platformio / platformio-core / platformio / commands / debug / helpers.py View on Github external
def configure_esp32_load_cmds(debug_options, configuration):
    ignore_conds = [
        debug_options["load_cmds"] != ["load"],
        "xtensa-esp32" not in configuration.get("cc_path", ""),
        not configuration.get("flash_extra_images"),
        not all(
            [isfile(item["path"]) for item in configuration.get("flash_extra_images")]
        ),
    ]
    if any(ignore_conds):
        return debug_options["load_cmds"]

    mon_cmds = [
        'monitor program_esp32 "{{{path}}}" {offset} verify'.format(
            path=fs.to_unix_path(item["path"]), offset=item["offset"]
        )
        for item in configuration.get("flash_extra_images")
    ]
    mon_cmds.append(
        'monitor program_esp32 "{%s.bin}" 0x10000 verify'
        % fs.to_unix_path(configuration["prog_path"][:-4])
    )
    return mon_cmds
github platformio / platformio-core / platformio / commands / debug / helpers.py View on Github external
if not isfile(prog_path):
        return True
    shasum = sha1()
    with open(prog_path, "rb") as fp:
        while True:
            data = fp.read(1024)
            if not data:
                break
            shasum.update(data)
    new_digest = shasum.hexdigest()
    old_digest = (
        fs.get_file_contents(prog_hash_path) if isfile(prog_hash_path) else None
    )
    if new_digest == old_digest:
        return False
    fs.write_file_contents(prog_hash_path, new_digest)
    return True
github platformio / platformio-core / platformio / commands / ci.py View on Github external
def validate_path(ctx, param, value):  # pylint: disable=unused-argument
    invalid_path = None
    value = list(value)
    for i, p in enumerate(value):
        if p.startswith("~"):
            value[i] = fs.expanduser(p)
        value[i] = realpath(value[i])
        if not glob(value[i]):
            invalid_path = p
            break
    try:
        assert invalid_path is None
        return value
    except AssertionError:
        raise click.BadParameter("Found invalid path: %s" % invalid_path)
github platformio / platformio-core / platformio / commands / debug / client.py View on Github external
def processEnded(self, reason):  # pylint: disable=unused-argument
        self._unlock_session()
        if self._gdbsrc_dir and isdir(self._gdbsrc_dir):
            fs.rmtree(self._gdbsrc_dir)
        if self._debug_server:
            self._debug_server.terminate()

        reactor.stop()
github platformio / platformio-core / platformio / managers / package.py View on Github external
def load_manifest(self, pkg_dir):  # pylint: disable=too-many-branches
        cache_key = "load_manifest-%s" % pkg_dir
        result = self.cache_get(cache_key)
        if result:
            return result

        manifest = {}
        src_manifest = None
        manifest_path = self.get_manifest_path(pkg_dir)
        src_manifest_path = self.get_src_manifest_path(pkg_dir)
        if src_manifest_path:
            src_manifest = fs.load_json(src_manifest_path)

        if not manifest_path and not src_manifest_path:
            return None

        try:
            manifest = ManifestParserFactory.new_from_file(manifest_path).as_dict()
        except ManifestParserError:
            pass

        if src_manifest:
            if "version" in src_manifest:
                manifest["version"] = src_manifest["version"]
            manifest["__src_url"] = src_manifest["url"]
            # handle a custom package name
            autogen_name = self.parse_pkg_uri(manifest["__src_url"])[0]
            if "name" not in manifest or autogen_name != src_manifest["name"]:
github platformio / platformio-core / scripts / docspregen.py View on Github external
assert board_manifest_url
    if board_manifest_url.endswith(".git"):
        board_manifest_url = board_manifest_url[:-4]
    board_manifest_url += "/blob/master/boards/%s.json" % board['id']

    variables = dict(id=board['id'],
                     name=board['name'],
                     platform=board['platform'],
                     platform_description=platform.description,
                     url=campaign_url(board['url']),
                     mcu=board_config.get("build", {}).get("mcu", ""),
                     mcu_upper=board['mcu'].upper(),
                     f_cpu=board['fcpu'],
                     f_cpu_mhz=int(int(board['fcpu']) / 1000000),
                     ram=fs.format_filesize(board['ram']),
                     rom=fs.format_filesize(board['rom']),
                     vendor=board['vendor'],
                     board_manifest_url=board_manifest_url,
                     upload_protocol=board_config.get("upload.protocol", ""))

    lines = [RST_COPYRIGHT]
    lines.append(".. _board_{platform}_{id}:".format(**variables))
    lines.append("")
    lines.append(board['name'])
    lines.append("=" * len(board['name']))
    lines.append("""
.. contents::

Hardware
--------

Platform :ref:`platform_{platform}`: {platform_description}
github platformio / platformio-core / platformio / commands / check / tools / base.py View on Github external
def get_project_src_files(self):
        file_extensions = ["h", "hpp", "c", "cc", "cpp", "ino"]
        return fs.match_src_files(
            get_project_dir(), self.options.get("filter"), file_extensions
        )
github platformio / platformio-core / platformio / commands / boards.py View on Github external
def print_boards(boards):
    click.echo(
        tabulate(
            [
                (
                    click.style(b["id"], fg="cyan"),
                    b["mcu"],
                    "%dMHz" % (b["fcpu"] / 1000000),
                    fs.format_filesize(b["rom"]),
                    fs.format_filesize(b["ram"]),
                    b["name"],
                )
                for b in boards
            ],
            headers=["ID", "MCU", "Frequency", "Flash", "RAM", "Name"],
        )