How to use the platformio.app.set_state_item 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 / tests / test_maintenance.py View on Github external
def test_check_and_update_libraries(clirunner, isolated_pio_home,
                                    validate_cliresult):
    # enable library auto-updates
    result = clirunner.invoke(
        cli_pio, ["settings", "set", "auto_update_libraries", "Yes"])

    # reset check time
    interval = int(app.get_setting("check_libraries_interval")) * 3600 * 24
    last_check = {"libraries_update": time() - interval - 1}
    app.set_state_item("last_check", last_check)

    # fetch installed version
    result = clirunner.invoke(cli_pio, ["lib", "-g", "list", "--json-output"])
    validate_cliresult(result)
    prev_data = json.loads(result.output)
    assert len(prev_data) == 1

    # initiate auto-updating
    result = clirunner.invoke(cli_pio, ["lib", "-g", "show", "ArduinoJson"])
    validate_cliresult(result)
    assert ("There are the new updates for libraries (ArduinoJson)" in
            result.output)
    assert "Please wait while updating libraries" in result.output
    assert re.search(r"Updating ArduinoJson\s+@ 5.6.7\s+\[[\d\.]+\]",
                     result.output)
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / platforms / base.py View on Github external
deppkgs = set()
        for item in installed_platforms:
            if item == platform:
                continue
            p = PlatformFactory.newPlatform(item)
            deppkgs = deppkgs.union(set(p.get_packages().keys()))

        pm = PackageManager()
        for name in self.get_packages().keys():
            if not pm.is_installed(name) or name in deppkgs:
                continue
            pm.uninstall(name)

        # unregister installed platform
        installed_platforms.remove(platform)
        set_state_item("installed_platforms", installed_platforms)

        return True
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / pkgmanager.py View on Github external
def _unregister(self, name):
        data = self.get_installed()
        del data[name]
        set_state_item("installed_packages", data)
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / platforms / base.py View on Github external
for name, opts in self.get_packages().items():
            if name in without_packages:
                continue
            elif (name in with_packages or (not skip_default_packages and
                                                opts.get("default"))):
                requirements.append(name)

        pm = PackageManager()
        for name in requirements:
            pm.install(name)

        # register installed platform
        data = get_state_item("installed_platforms", [])
        if self.get_type() not in data:
            data.append(self.get_type())
            set_state_item("installed_platforms", data)

        return len(requirements)
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / maintenance.py View on Github external
def check_platformio_upgrade():
    last_check = app.get_state_item("last_check", {})
    interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24
    if (time() - interval) < last_check.get("platformio_upgrade", 0):
        return

    last_check['platformio_upgrade'] = int(time())
    app.set_state_item("last_check", last_check)

    latest_version = get_latest_version()
    if (latest_version == __version__ or
            Upgrader.version_to_int(latest_version) <
            Upgrader.version_to_int(__version__)):
        return

    terminal_width, _ = click.get_terminal_size()

    click.echo("")
    click.echo("*" * terminal_width)
    click.secho("There is a new version %s of PlatformIO available.\n"
                "Please upgrade it via `" % latest_version,
                fg="yellow", nl=False)
    click.secho("platformio upgrade", fg="cyan", nl=False)
    click.secho("` or `", fg="yellow", nl=False)
github platformio / platformio-core / platformio / telemetry.py View on Github external
for params in items:
        # skip static options
        for key in list(params.keys()):
            if key in ("v", "tid", "cid", "cd1", "cd2", "sr", "an"):
                del params[key]

        # store time in UNIX format
        if "qt" not in params:
            params["qt"] = time()
        elif not isinstance(params["qt"], float):
            params["qt"] = time() - (params["qt"] / 1000)

        tm["backup"].append(params)

    tm["backup"] = tm["backup"][KEEP_MAX_REPORTS * -1 :]
    app.set_state_item("telemetry", tm)
github platformio / platformio-core / platformio / maintenance.py View on Github external
def after_upgrade(ctx):
    terminal_width, _ = click.get_terminal_size()
    last_version = app.get_state_item("last_version", "0.0.0")
    if last_version == __version__:
        return

    if last_version == "0.0.0":
        app.set_state_item("last_version", __version__)
    elif semantic_version.Version.coerce(
        util.pepver_to_semver(last_version)
    ) > semantic_version.Version.coerce(util.pepver_to_semver(__version__)):
        click.secho("*" * terminal_width, fg="yellow")
        click.secho(
            "Obsolete PIO Core v%s is used (previous was %s)"
            % (__version__, last_version),
            fg="yellow",
        )
        click.secho("Please remove multiple PIO Cores from a system:", fg="yellow")
        click.secho(
            "https://docs.platformio.org/page/faq.html"
            "#multiple-pio-cores-in-a-system",
            fg="cyan",
        )
        click.secho("*" * terminal_width, fg="yellow")
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / maintenance.py View on Github external
click.style("star", fg="cyan"),
        click.style("https://github.com/platformio/platformio", fg="cyan")
    ))
    click.echo("*" * terminal_width)
    click.echo("")

    if last_version == "0.0.0":
        app.set_state_item("last_version", __version__)
        return

    click.secho("Please wait while upgrading PlatformIO ...",
                fg="yellow")

    u = Upgrader(last_version, __version__)
    if u.run(ctx):
        app.set_state_item("last_version", __version__)
        ctx.invoke(cmd_platforms_update)

        click.secho("PlatformIO has been successfully upgraded to %s!\n" %
                    __version__, fg="green")

        telemetry.on_event(category="Auto", action="Upgrade",
                           label="%s > %s" % (last_version, __version__))
    else:
        raise exception.UpgradeError("Auto upgrading...")
    click.echo("")
github bq / bitbloq-offline / app / res / web2board / darwin / Web2Board.app / Contents / Resources / platformio / pkgmanager.py View on Github external
def _register(self, name, version):
        data = self.get_installed()
        data[name] = {
            "version": version,
            "time": int(time())
        }
        set_state_item("installed_packages", data)