Esempio n. 1
0
def check_prune_system():
    last_check = app.get_state_item("last_check", {})
    interval = 30 * 3600 * 24  # 1 time per month
    if (time() - interval) < last_check.get("prune_system", 0):
        return

    last_check["prune_system"] = int(time())
    app.set_state_item("last_check", last_check)
    threshold_mb = int(app.get_setting("check_prune_system_threshold") or 0)
    if threshold_mb <= 0:
        return

    unnecessary_size = calculate_unnecessary_system_data()
    if (unnecessary_size / 1024) < threshold_mb:
        return

    terminal_width, _ = click.get_terminal_size()
    click.echo()
    click.echo("*" * terminal_width)
    click.secho(
        "We found %s of unnecessary PlatformIO system data (temporary files, "
        "unnecessary packages, etc.).\nUse `pio system prune --dry-run` to list "
        "them or `pio system prune` to save disk space."
        % fs.humanize_file_size(unnecessary_size),
        fg="yellow",
    )
def test_check_and_update_libraries(clirunner, 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)

    # check updated version
    result = clirunner.invoke(cli_pio, ["lib", "-g", "list", "--json-output"])
    validate_cliresult(result)
    assert prev_data[0]['version'] != json.loads(result.output)[0]['version']
Esempio n. 3
0
 def get_account_info(self, offline=False):
     account = app.get_state_item("account") or {}
     if (account.get("summary")
             and account["summary"].get("expire_at", 0) > time.time()):
         return account["summary"]
     if offline and account.get("email"):
         return {
             "profile": {
                 "email": account.get("email"),
                 "username": account.get("username"),
             }
         }
     result = self.send_auth_request(
         "get",
         "/v1/summary",
     )
     account["summary"] = dict(
         profile=result.get("profile"),
         packages=result.get("packages"),
         subscriptions=result.get("subscriptions"),
         user_id=result.get("user_id"),
         expire_at=int(time.time()) + self.SUMMARY_CACHE_TTL,
     )
     app.set_state_item("account", account)
     return result
def test_check_and_update_platforms(clirunner, validate_cliresult,
                                    isolated_pio_home):
    # enable library auto-updates
    result = clirunner.invoke(
        cli_pio, ["settings", "set", "auto_update_platforms", "Yes"])

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

    # fetch installed version
    result = clirunner.invoke(cli_pio, ["platform", "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, ["platform", "show", "native"])
    validate_cliresult(result)
    assert "There are the new updates for platforms (native)" in result.output
    assert "Please wait while updating platforms" in result.output
    assert re.search(r"Updating native\s+@ 0.0.0\s+\[[\d\.]+\]",
                     result.output)

    # check updated version
    result = clirunner.invoke(cli_pio, ["platform", "list", "--json-output"])
    validate_cliresult(result)
    assert prev_data[0]['version'] != json.loads(result.output)[0]['version']
Esempio n. 5
0
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)

    try:
        latest_version = get_latest_version()
    except GetLatestVersionError:
        click.secho("Failed to check for PlatformIO upgrades", fg="red")
        return

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

    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(" command.\nChanges: ", fg="yellow", nl=False)
    click.secho("http://docs.platformio.org/en/latest/history.html\n",
                fg="cyan")
Esempio n. 6
0
def test_check_pio_upgrade(clirunner, validate_cliresult, isolated_pio_home):

    def _patch_pio_version(version):
        maintenance.__version__ = version
        cmd_upgrade.VERSION = version.split(".", 3)

    interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24
    last_check = {"platformio_upgrade": time() - interval - 1}
    origin_version = maintenance.__version__

    # check development version
    _patch_pio_version("3.0.0-a1")
    app.set_state_item("last_check", last_check)
    result = clirunner.invoke(cli_pio, ["platform", "list"])
    validate_cliresult(result)
    assert "There is a new version" in result.output
    assert "Please upgrade" in result.output

    # check stable version
    _patch_pio_version("2.11.0")
    app.set_state_item("last_check", last_check)
    result = clirunner.invoke(cli_pio, ["platform", "list"])
    validate_cliresult(result)
    assert "There is a new version" in result.output
    assert "Please upgrade" in result.output

    # restore original version
    _patch_pio_version(origin_version)
Esempio n. 7
0
def test_after_upgrade_2_to_3(clirunner, validate_cliresult,
                              isolated_pio_home):
    app.set_state_item("last_version", "2.11.2")
    app.set_state_item("installed_platforms", ["native"])

    # generate PlatformIO 2.0 boards
    boards = isolated_pio_home.mkdir("boards")
    board_ids = set()
    for prefix in ("foo", "bar"):
        data = {}
        for i in range(3):
            board_id = "board_%s_%d" % (prefix, i)
            board_ids.add(board_id)
            data[board_id] = {
                "name": "Board %s #%d" % (prefix, i),
                "url": "",
                "vendor": ""
            }
        boards.join(prefix + ".json").write(json.dumps(data))

    result = clirunner.invoke(cli_pio, ["settings", "get"])
    validate_cliresult(result)
    assert "upgraded to 3"
    assert isolated_pio_home.join("platforms", "native",
                                  "platform.json").check()

    # check PlatformIO 3.0 boards
    assert board_ids == set([p.basename[:-5] for p in boards.listdir()])

    result = clirunner.invoke(cli_pio,
                              ["boards", "--installed", "--json-output"])
    validate_cliresult(result)
    assert board_ids == set([b['id'] for b in json.loads(result.output)])
Esempio n. 8
0
def test_after_upgrade_silence(clirunner, validate_cliresult,
                               isolated_pio_home):
    app.set_state_item("last_version", "2.11.2")
    result = clirunner.invoke(cli_pio, ["boards", "--json-output"])
    validate_cliresult(result)
    boards = json.loads(result.output)
    assert any([b['id'] == "uno" for b in boards])
Esempio n. 9
0
 def get_account_info(self, offline):
     account = app.get_state_item("account")
     if not account:
         raise exception.AccountNotAuthorized()
     if (account.get("summary")
             and account["summary"].get("expire_at", 0) > time.time()):
         return account["summary"]
     if offline:
         return {
             "profile": {
                 "email": account.get("email"),
                 "username": account.get("username"),
             }
         }
     token = self.fetch_authentication_token()
     result = self.send_request(
         "get",
         self.api_base_url + "/v1/summary",
         headers={"Authorization": "Bearer %s" % token},
     )
     account["summary"] = dict(
         profile=result.get("profile"),
         packages=result.get("packages"),
         subscriptions=result.get("subscriptions"),
         user_id=result.get("user_id"),
         expire_at=int(time.time()) + self.SUMMARY_CACHE_TTL,
     )
     app.set_state_item("account", account)
     return result
Esempio n. 10
0
def test_check_and_update_libraries(clirunner, isolated_pio_core,
                                    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 bblanchon/ArduinoJson\s+6\.12\.0\s+\[Updating to [\d\.]+\]",
        result.output,
    )

    # check updated version
    result = clirunner.invoke(cli_pio, ["lib", "-g", "list", "--json-output"])
    validate_cliresult(result)
    assert prev_data[0]["version"] != json.loads(result.output)[0]["version"]
Esempio n. 11
0
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(" command.\nChanges: ", fg="yellow", nl=False)
    click.secho("http://docs.platformio.org/en/latest/history.html",
                fg="cyan")
    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 12
0
def test_check_pio_upgrade(clirunner, isolated_pio_core, validate_cliresult):
    def _patch_pio_version(version):
        maintenance.__version__ = version
        cmd_upgrade.VERSION = version.split(".", 3)

    interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24
    last_check = {"platformio_upgrade": time() - interval - 1}
    origin_version = maintenance.__version__

    # check development version
    _patch_pio_version("3.0.0-a1")
    app.set_state_item("last_check", last_check)
    result = clirunner.invoke(cli_pio, ["platform", "list"])
    validate_cliresult(result)
    assert "There is a new version" in result.output
    assert "Please upgrade" in result.output

    # check stable version
    _patch_pio_version("2.11.0")
    app.set_state_item("last_check", last_check)
    result = clirunner.invoke(cli_pio, ["platform", "list"])
    validate_cliresult(result)
    assert "There is a new version" in result.output
    assert "Please upgrade" in result.output

    # restore original version
    _patch_pio_version(origin_version)
Esempio n. 13
0
    def install(self, with_packages=None, without_packages=None,
                skip_default_packages=False):
        with_packages = set(
            self.pkg_aliases_to_names(with_packages or []))
        without_packages = set(
            self.pkg_aliases_to_names(without_packages or []))

        upkgs = with_packages | without_packages
        ppkgs = set(self.get_packages().keys())
        if not upkgs.issubset(ppkgs):
            raise exception.UnknownPackage(", ".join(upkgs - ppkgs))

        requirements = []
        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)
Esempio n. 14
0
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)
    click.secho("pip install -U platformio", fg="cyan", nl=False)
    click.secho("` command.\nChanges: ", fg="yellow", nl=False)
    click.secho("http://docs.platformio.org/en/latest/history.html",
                fg="cyan")
    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 15
0
    def uninstall(self):
        platform = self.get_type()
        installed_platforms = PlatformFactory.get_platforms(
            installed=True).keys()

        if platform not in installed_platforms:
            raise exception.PlatformNotInstalledYet(platform)

        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
Esempio n. 16
0
def test_check_and_update_libraries(clirunner, validate_cliresult,
                                    isolated_pio_home):
    # 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", "PubSubClient"])
    validate_cliresult(result)
    assert ("There are the new updates for libraries (PubSubClient)"
            in result.output)
    assert "Please wait while updating libraries" in result.output
    assert "[Out-of-date]" in result.output

    # check updated version
    result = clirunner.invoke(cli_pio, ["lib", "-g", "list", "--json-output"])
    validate_cliresult(result)
    assert prev_data[0]['version'] != json.loads(result.output)[0]['version']
Esempio n. 17
0
 def _register(self, name, version):
     data = self.get_installed()
     data[name] = {
         "version": version,
         "time": int(time())
     }
     set_state_item("installed_packages", data)
Esempio n. 18
0
 def _register(self, name, version):
     data = self.get_installed()
     data[name] = {
         "version": version,
         "time": int(time())
     }
     set_state_item("installed_packages", data)
Esempio n. 19
0
def test_check_and_update_platforms(clirunner, validate_cliresult,
                                    isolated_pio_home):
    # enable library auto-updates
    result = clirunner.invoke(
        cli_pio, ["settings", "set", "auto_update_platforms", "Yes"])

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

    # fetch installed version
    result = clirunner.invoke(cli_pio, ["platform", "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, ["platform", "show", "native"])
    validate_cliresult(result)
    assert "There are the new updates for platforms (native)" in result.output
    assert "Please wait while updating platforms" in result.output
    assert "[Out-of-date]" in result.output

    # check updated version
    result = clirunner.invoke(cli_pio, ["platform", "list", "--json-output"])
    validate_cliresult(result)
    assert prev_data[0]['version'] != json.loads(result.output)[0]['version']
Esempio n. 20
0
def after_upgrade(ctx):
    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__)
    else:
        click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")
        clean_cache()
        u = Upgrader(last_version, __version__)
        if u.run(ctx):
            app.set_state_item("last_version", __version__)

            # update development platforms
            pm = PlatformManager()
            for manifest in pm.get_installed():
                # pm.update(manifest['name'], "^" + manifest['version'])
                pm.update(manifest['name'])

            # update PlatformIO Plus tool if installed
            pioplus_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("")

    # PlatformIO banner
    terminal_width, _ = click.get_terminal_size()
    click.echo("*" * terminal_width)
    click.echo("If you like %s, please:" % (click.style(
        "PlatformIO", fg="cyan")))
    click.echo("- %s us on Twitter to stay up-to-date "
               "on the latest project news > %s" % (click.style(
                   "follow", fg="cyan"), click.style(
                       "https://twitter.com/PlatformIO_Org", fg="cyan")))
    click.echo("- %s it on GitHub > %s" % (click.style(
        "star", fg="cyan"), click.style(
            "https://github.com/platformio/platformio", fg="cyan")))
    if not getenv("PLATFORMIO_IDE"):
        click.echo("- %s PlatformIO IDE for IoT development > %s" %
                   (click.style(
                       "try", fg="cyan"), click.style(
                           "http://platformio.org/platformio-ide", fg="cyan")))
    if not util.is_ci():
        click.echo("- %s us with PlatformIO Plus > %s" % (click.style(
            "support", fg="cyan"), click.style(
                "https://pioplus.com", fg="cyan")))

    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 21
0
def test_after_upgrade_silence(clirunner, validate_cliresult,
                               isolated_pio_home):
    app.set_state_item("last_version", "2.11.2")
    result = clirunner.invoke(cli_pio, ["boards", "--json-output"])
    validate_cliresult(result)
    boards = json.loads(result.output)
    assert any([b['id'] == "uno" for b in boards])
Esempio n. 22
0
def test_after_upgrade_2_to_3(clirunner, validate_cliresult,
                              isolated_pio_home):
    app.set_state_item("last_version", "2.11.2")
    app.set_state_item("installed_platforms", ["native"])

    # generate PlatformIO 2.0 boards
    boards = isolated_pio_home.mkdir("boards")
    board_ids = set()
    for prefix in ("foo", "bar"):
        data = {}
        for i in range(3):
            board_id = "board_%s_%d" % (prefix, i)
            board_ids.add(board_id)
            data[board_id] = {
                "name": "Board %s #%d" % (prefix, i),
                "url": "",
                "vendor": ""
            }
        boards.join(prefix + ".json").write(json.dumps(data))

    result = clirunner.invoke(cli_pio, ["settings", "get"])
    validate_cliresult(result)
    assert "upgraded to 3"
    assert isolated_pio_home.join("platforms", "native",
                                  "platform.json").check()

    # check PlatformIO 3.0 boards
    assert board_ids == set([p.basename[:-5] for p in boards.listdir()])

    result = clirunner.invoke(cli_pio,
                              ["boards", "--installed", "--json-output"])
    validate_cliresult(result)
    assert board_ids == set([b['id'] for b in json.loads(result.output)])
Esempio n. 23
0
def backup_reports(items):
    if not items:
        return

    KEEP_MAX_REPORTS = 100
    tm = app.get_state_item("telemetry", {})
    if "backup" not in tm:
        tm['backup'] = []

    for params in items:
        # skip static options
        for key in 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)
Esempio n. 24
0
def check_internal_updates(ctx, what):
    last_check = app.get_state_item("last_check", {})
    interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24
    if (time() - interval) < last_check.get(what + "_update", 0):
        return

    last_check[what + '_update'] = int(time())
    app.set_state_item("last_check", last_check)

    pm = PlatformManager() if what == "platforms" else LibraryManager()
    outdated_items = []
    for manifest in pm.get_installed():
        if manifest['name'] not in outdated_items and \
                pm.is_outdated(manifest['name']):
            outdated_items.append(manifest['name'])

    if not outdated_items:
        return

    terminal_width, _ = click.get_terminal_size()

    click.echo("")
    click.echo("*" * terminal_width)
    click.secho("There are the new updates for %s (%s)" %
                (what, ", ".join(outdated_items)),
                fg="yellow")

    if not app.get_setting("auto_update_" + what):
        click.secho("Please update them via ", fg="yellow", nl=False)
        click.secho("`platformio %s update`" %
                    ("lib --global" if what == "libraries" else "platform"),
                    fg="cyan",
                    nl=False)
        click.secho(" command.\n", fg="yellow")
        click.secho(
            "If you want to manually check for the new versions "
            "without updating, please use ",
            fg="yellow",
            nl=False)
        click.secho("`platformio %s update --only-check`" %
                    ("lib --global" if what == "libraries" else "platform"),
                    fg="cyan",
                    nl=False)
        click.secho(" command.", fg="yellow")
    else:
        click.secho("Please wait while updating %s ..." % what, fg="yellow")
        if what == "platforms":
            ctx.invoke(cmd_platform_update, platforms=outdated_items)
        elif what == "libraries":
            ctx.obj = pm
            ctx.invoke(cmd_lib_update, libraries=outdated_items)
        click.echo()

        telemetry.on_event(category="Auto",
                           action="Update",
                           label=what.title())

    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 25
0
def after_upgrade(ctx):
    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__)
    else:
        click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")
        clean_cache()
        u = Upgrader(last_version, __version__)
        if u.run(ctx):
            app.set_state_item("last_version", __version__)

            # update development platforms
            pm = PlatformManager()
            for manifest in pm.get_installed():
                # pm.update(manifest['name'], "^" + manifest['version'])
                pm.update(manifest['name'])

            # update PlatformIO Plus tool if installed
            pioplus_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("")

    # PlatformIO banner
    terminal_width, _ = click.get_terminal_size()
    click.echo("*" * terminal_width)
    click.echo("If you like %s, please:" %
               (click.style("PlatformIO", fg="cyan")))
    click.echo("- %s us on Twitter to stay up-to-date "
               "on the latest project news > %s" %
               (click.style("follow", fg="cyan"),
                click.style("https://twitter.com/PlatformIO_Org", fg="cyan")))
    click.echo(
        "- %s it on GitHub > %s" %
        (click.style("star", fg="cyan"),
         click.style("https://github.com/platformio/platformio", fg="cyan")))
    if not getenv("PLATFORMIO_IDE"):
        click.echo(
            "- %s PlatformIO IDE for IoT development > %s" %
            (click.style("try", fg="cyan"),
             click.style("http://platformio.org/platformio-ide", fg="cyan")))
    if not util.is_ci():
        click.echo("- %s us with PlatformIO Plus > %s" %
                   (click.style("support", fg="cyan"),
                    click.style("https://pioplus.com", fg="cyan")))

    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 26
0
def after_upgrade(ctx):
    last_version = app.get_state_item("last_version", "0.0.0")
    if last_version == __version__:
        return

    terminal_width, _ = click.get_terminal_size()

    # promotion
    click.echo("")
    click.echo("*" * terminal_width)
    click.echo("If you like %s, please:" % (
        click.style("PlatformIO", fg="cyan")
    ))
    click.echo(
        "- %s us on Twitter to stay up-to-date "
        "on the latest project news > %s" %
        (click.style("follow", fg="cyan"),
         click.style("https://twitter.com/PlatformIO_Org", fg="cyan"))
    )
    click.echo("- %s it on GitHub > %s" % (
        click.style("star", fg="cyan"),
        click.style("https://github.com/platformio/platformio", fg="cyan")
    ))
    if not getenv("PLATFORMIO_IDE"):
        click.echo("- %s PlatformIO IDE for IoT development > %s" % (
            click.style("try", fg="cyan"),
            click.style("http://platformio.org/#!/platformio-ide", fg="cyan")
        ))
    if not util.is_ci():
        click.echo("- %s to keep PlatformIO alive! > %s" % (
            click.style("donate", fg="cyan"),
            click.style("http://platformio.org/#!/donate", 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("")
Esempio n. 27
0
def after_upgrade(ctx):
    last_version = app.get_state_item("last_version", "0.0.0")
    if last_version == __version__:
        return

    terminal_width, _ = click.get_terminal_size()

    # promotion
    click.echo("")
    click.echo("*" * terminal_width)
    click.echo("If you like %s, please:" %
               (click.style("PlatformIO", fg="cyan")))
    click.echo("- %s us on Twitter to stay up-to-date "
               "on the latest project news > %s" %
               (click.style("follow", fg="cyan"),
                click.style("https://twitter.com/PlatformIO_Org", fg="cyan")))
    click.echo(
        "- %s it on GitHub > %s" %
        (click.style("star", fg="cyan"),
         click.style("https://github.com/platformio/platformio", fg="cyan")))
    if not getenv("PLATFORMIO_IDE"):
        click.echo("- %s PlatformIO IDE for IoT development > %s" %
                   (click.style("try", fg="cyan"),
                    click.style("http://platformio.org/#!/platformio-ide",
                                fg="cyan")))
    if not util.is_ci():
        click.echo("- %s to keep PlatformIO alive! > %s" %
                   (click.style("donate", fg="cyan"),
                    click.style("http://platformio.org/#!/donate", 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("")
Esempio n. 28
0
def check_internal_updates(ctx, what):
    last_check = app.get_state_item("last_check", {})
    interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24
    if (time() - interval) < last_check.get(what + "_update", 0):
        return

    last_check[what + '_update'] = int(time())
    app.set_state_item("last_check", last_check)

    outdated_items = []
    if what == "platforms":
        for platform in PlatformFactory.get_platforms(installed=True).keys():
            p = PlatformFactory.newPlatform(platform)
            if p.is_outdated():
                outdated_items.append(platform)
    elif what == "libraries":
        lm = LibraryManager()
        outdated_items = lm.get_outdated()

    if not outdated_items:
        return

    terminal_width, _ = click.get_terminal_size()

    click.echo("")
    click.echo("*" * terminal_width)
    click.secho("There are the new updates for %s (%s)" %
                (what, ", ".join(outdated_items)),
                fg="yellow")

    if not app.get_setting("auto_update_" + what):
        click.secho("Please update them via ", fg="yellow", nl=False)
        click.secho("`platformio %s update`" %
                    ("lib" if what == "libraries" else "platforms"),
                    fg="cyan",
                    nl=False)
        click.secho(" command.", fg="yellow")
    else:
        click.secho("Please wait while updating %s ..." % what, fg="yellow")
        if what == "platforms":
            ctx.invoke(cmd_platforms_update)
        elif what == "libraries":
            ctx.invoke(cmd_libraries_update)
        click.echo()

        telemetry.on_event(category="Auto",
                           action="Update",
                           label=what.title())

    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 29
0
def after_upgrade(ctx):
    last_version = app.get_state_item("last_version", "0.0.0")
    if last_version == __version__:
        return

    terminal_width, _ = click.get_terminal_size()

    # promotion
    click.echo("")
    click.echo("*" * terminal_width)
    click.echo("If you like %s, please:" % (
        click.style("PlatformIO", fg="cyan")
    ))
    click.echo(
        "- %s us on Twitter to stay up-to-date "
        "on the latest project news > %s" %
        (click.style("follow", fg="cyan"),
         click.style("https://twitter.com/PlatformIO_Org", fg="cyan"))
    )
    click.echo("- %s us a star on GitHub > %s" % (
        click.style("give", fg="cyan"),
        click.style("https://github.com/platformio/platformio", fg="cyan")
    ))
    click.echo("- %s for the new features/issues on Bountysource > %s" % (
        click.style("vote", fg="cyan"),
        click.style("https://www.bountysource.com/teams/platformio/issues",
                    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.UpgraderFailed()
    click.echo("")
Esempio n. 30
0
def after_upgrade(ctx):
    last_version = app.get_state_item("last_version", "0.0.0")
    if last_version == __version__:
        return

    terminal_width, _ = click.get_terminal_size()

    # promotion
    click.echo("")
    click.echo("*" * terminal_width)
    click.echo("If you like %s, please:" % (
        click.style("PlatformIO", fg="cyan")
    ))
    click.echo(
        "- %s us on Twitter to stay up-to-date "
        "on the latest project news > %s" %
        (click.style("follow", fg="cyan"),
         click.style("https://twitter.com/PlatformIO_Org", fg="cyan"))
    )
    click.echo("- %s us a star on GitHub > %s" % (
        click.style("give", fg="cyan"),
        click.style("https://github.com/platformio/platformio", fg="cyan")
    ))
    click.echo("- %s for the new features/issues on Bountysource > %s" % (
        click.style("vote", fg="cyan"),
        click.style("https://www.bountysource.com/teams/platformio/issues",
                    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.UpgraderFailed()
    click.echo("")
Esempio n. 31
0
def resend_backuped_reports():
    tm = app.get_state_item("telemetry", {})
    if "backup" not in tm or not tm['backup']:
        return False

    for report in tm['backup']:
        mp = MeasurementProtocol()
        for key, value in report.items():
            mp[key] = value
        mp.send(report['t'])

    # clean
    tm['backup'] = []
    app.set_state_item("telemetry", tm)
Esempio n. 32
0
def resend_backuped_report():
    tm = app.get_state_item("telemetry", {})
    if "backup" not in tm or not tm['backup']:
        return False

    report = tm['backup'].pop()
    app.set_state_item("telemetry", tm)

    mp = MeasurementProtocol()
    for key, value in report.items():
        mp[key] = value
    mp.send(report['t'])

    return True
Esempio n. 33
0
def resend_backuped_report():
    tm = app.get_state_item("telemetry", {})
    if "backup" not in tm or not tm['backup']:
        return False

    report = tm['backup'].pop()
    app.set_state_item("telemetry", tm)

    mp = MeasurementProtocol()
    for key, value in report.items():
        mp[key] = value
    mp.send(report['t'])

    return True
Esempio n. 34
0
def test_check_lib_updates(clirunner, isolated_pio_core, validate_cliresult):
    # install obsolete library
    result = clirunner.invoke(cli_pio,
                              ["lib", "-g", "install", "ArduinoJson@<6.13"])
    validate_cliresult(result)

    # 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)

    result = clirunner.invoke(cli_pio, ["lib", "-g", "list"])
    validate_cliresult(result)
    assert "There are the new updates for libraries (ArduinoJson)" in result.output
Esempio n. 35
0
def test_check_lib_updates(clirunner, validate_cliresult, isolated_pio_home):
    # install obsolete library
    result = clirunner.invoke(cli_pio,
                              ["lib", "-g", "install", "PubSubClient@<2.6"])
    validate_cliresult(result)

    # 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)

    result = clirunner.invoke(cli_pio, ["lib", "-g", "list"])
    validate_cliresult(result)
    assert ("There are the new updates for libraries (PubSubClient)"
            in result.output)
Esempio n. 36
0
def test_check_lib_updates(clirunner, validate_cliresult, isolated_pio_home):
    # install obsolete library
    result = clirunner.invoke(cli_pio,
                              ["lib", "-g", "install", "ArduinoJson@<5.7"])
    validate_cliresult(result)

    # 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)

    result = clirunner.invoke(cli_pio, ["lib", "-g", "list"])
    validate_cliresult(result)
    assert ("There are the new updates for libraries (ArduinoJson)" in
            result.output)
Esempio n. 37
0
def check_internal_updates(ctx, what):
    last_check = app.get_state_item("last_check", {})
    interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24
    if (time() - interval) < last_check.get(what + "_update", 0):
        return

    last_check[what + '_update'] = int(time())
    app.set_state_item("last_check", last_check)

    outdated_items = []
    if what == "platforms":
        for platform in PlatformFactory.get_platforms(installed=True).keys():
            p = PlatformFactory.newPlatform(platform)
            if p.is_outdated():
                outdated_items.append(platform)
    elif what == "libraries":
        lm = LibraryManager()
        outdated_items = lm.get_outdated()

    if not outdated_items:
        return

    terminal_width, _ = click.get_terminal_size()

    click.echo("")
    click.echo("*" * terminal_width)
    click.secho("There are the new updates for %s (%s)" %
                (what, ", ".join(outdated_items)), fg="yellow")

    if not app.get_setting("auto_update_" + what):
        click.secho("Please update them via ", fg="yellow", nl=False)
        click.secho("`platformio %s update`" %
                    ("lib" if what == "libraries" else "platforms"),
                    fg="cyan", nl=False)
        click.secho(" command.", fg="yellow")
    else:
        click.secho("Please wait while updating %s ..." % what, fg="yellow")
        if what == "platforms":
            ctx.invoke(cmd_platforms_update)
        elif what == "libraries":
            ctx.invoke(cmd_libraries_update)
        click.echo()

        telemetry.on_event(category="Auto", action="Update",
                           label=what.title())

    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 38
0
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)

    util.internet_on(raise_exception=True)

    # Update PlatformIO's Core packages
    update_core_packages(silent=True)

    latest_version = get_latest_version()
    if semantic_version.Version.coerce(util.pepver_to_semver(
            latest_version)) <= semantic_version.Version.coerce(
                util.pepver_to_semver(__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,
    )
    if getenv("PLATFORMIO_IDE"):
        click.secho("PlatformIO IDE Menu: Upgrade PlatformIO",
                    fg="cyan",
                    nl=False)
        click.secho("`.", fg="yellow")
    elif join("Cellar", "platformio") in fs.get_source_dir():
        click.secho("brew update && brew upgrade", fg="cyan", nl=False)
        click.secho("` command.", fg="yellow")
    else:
        click.secho("platformio upgrade", fg="cyan", nl=False)
        click.secho("` or `", fg="yellow", nl=False)
        click.secho("pip install -U platformio", fg="cyan", nl=False)
        click.secho("` command.", fg="yellow")
    click.secho("Changes: ", fg="yellow", nl=False)
    click.secho("https://docs.platformio.org/en/latest/history.html",
                fg="cyan")
    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 39
0
 def fetch_authentication_token(self):
     if "PLATFORMIO_AUTH_TOKEN" in os.environ:
         return os.environ["PLATFORMIO_AUTH_TOKEN"]
     auth = app.get_state_item("account", {}).get("auth", {})
     if auth.get("access_token") and auth.get("access_token_expire"):
         if auth.get("access_token_expire") > time.time():
             return auth.get("access_token")
         if auth.get("refresh_token"):
             response = self._session.post(
                 self.api_base_url + "/v1/login",
                 headers={"Authorization": "Bearer %s" % auth.get("refresh_token")},
             )
             result = self.raise_error_from_response(response)
             app.set_state_item("account", result)
             return result.get("auth").get("access_token")
     raise exception.AccountNotAuthenticated()
Esempio n. 40
0
    def login_with_code(self, client_id, code, redirect_uri):
        try:
            self.fetch_authentication_token()
        except:  # pylint:disable=bare-except
            pass
        else:
            raise exception.AccountAlreadyAuthenticated(
                app.get_state_item("account", {}).get("email", "")
            )

        response = self._session.post(
            self.api_base_url + "/v1/login/code",
            data={"client_id": client_id, "code": code, "redirect_uri": redirect_uri},
        )
        result = self.raise_error_from_response(response)
        app.set_state_item("account", result)
        return result
Esempio n. 41
0
    def login(self, username, password):
        try:
            self.fetch_authentication_token()
        except:  # pylint:disable=bare-except
            pass
        else:
            raise AccountAlreadyAuthorized(
                app.get_state_item("account", {}).get("email", "")
            )

        data = self.fetch_json_data(
            "post",
            "/v1/login",
            data={"username": username, "password": password},
        )
        app.set_state_item("account", data)
        return data
Esempio n. 42
0
    def login(self, username, password):
        try:
            self.fetch_authentication_token()
        except:  # pylint:disable=bare-except
            pass
        else:
            raise exception.AccountAlreadyAuthenticated(
                app.get_state_item("account", {}).get("email", "")
            )

        response = self._session.post(
            self.api_base_url + "/v1/login",
            data={"username": username, "password": password},
        )
        result = self.raise_error_from_response(response)
        app.set_state_item("account", result)
        return result
Esempio n. 43
0
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)

    util.internet_on(raise_exception=True)

    # Update PlatformIO's Core packages
    update_core_packages(silent=True)

    latest_version = get_latest_version()
    if semantic_version.Version.coerce(util.pepver_to_semver(
            latest_version)) <= semantic_version.Version.coerce(
                util.pepver_to_semver(__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)
    if getenv("PLATFORMIO_IDE"):
        click.secho(
            "PlatformIO IDE Menu: Upgrade PlatformIO", fg="cyan", nl=False)
        click.secho("`.", fg="yellow")
    elif join("Cellar", "platformio") in util.get_source_dir():
        click.secho("brew update && brew upgrade", fg="cyan", nl=False)
        click.secho("` command.", fg="yellow")
    else:
        click.secho("platformio upgrade", fg="cyan", nl=False)
        click.secho("` or `", fg="yellow", nl=False)
        click.secho("pip install -U platformio", fg="cyan", nl=False)
        click.secho("` command.", fg="yellow")
    click.secho("Changes: ", fg="yellow", nl=False)
    click.secho(
        "https://docs.platformio.org/en/latest/history.html", fg="cyan")
    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 44
0
    def login_with_code(self, client_id, code, redirect_uri):
        try:
            self.fetch_authentication_token()
        except:  # pylint:disable=bare-except
            pass
        else:
            raise AccountAlreadyAuthorized(
                app.get_state_item("account", {}).get("email", "")
            )

        result = self.fetch_json_data(
            "post",
            "/v1/login/code",
            data={"client_id": client_id, "code": code, "redirect_uri": redirect_uri},
        )
        app.set_state_item("account", result)
        return result
Esempio n. 45
0
def test_check_platform_updates(clirunner, validate_cliresult,
                                isolated_pio_home):
    # install obsolete platform
    result = clirunner.invoke(cli_pio, ["platform", "install", "native"])
    validate_cliresult(result)
    manifest_path = isolated_pio_home.join("platforms", "native",
                                           "platform.json")
    manifest = json.loads(manifest_path.read())
    manifest['version'] = "0.0.0"
    manifest_path.write(json.dumps(manifest))
    # reset cached manifests
    PlatformManager().reset_cache()

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

    result = clirunner.invoke(cli_pio, ["platform", "list"])
    validate_cliresult(result)
    assert "There are the new updates for platforms (native)" in result.output
Esempio n. 46
0
def after_upgrade(ctx):
    last_version = app.get_state_item("last_version", "0.0.0")
    if last_version == __version__:
        return

    # promotion
    click.echo("\nIf you like %s, please:" % (
        click.style("PlatformIO", fg="cyan")
    ))
    click.echo(
        "- %s us on Twitter to stay up-to-date "
        "on the latest project news > %s" %
        (click.style("follow", fg="cyan"),
         click.style("https://twitter.com/PlatformIO_Org", fg="cyan"))
    )
    click.echo("- %s us a star on GitHub > %s" % (
        click.style("give", fg="cyan"),
        click.style("https://github.com/ivankravets/platformio", fg="cyan")
    ))
    click.secho("Thanks a lot!\n", fg="green")

    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__)
        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 UpgraderFailed()
    click.echo("")
Esempio n. 47
0
 def get_cid(self):
     cid = app.get_state_item("cid")
     if not cid:
         cid = self.MACHINE_ID
         app.set_state_item("cid", cid)
     return cid
Esempio n. 48
0
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")
        return
    else:
        click.secho("Please wait while upgrading PlatformIO...", fg="yellow")
        app.clean_cache()

        # Update PlatformIO's Core packages
        update_core_packages(silent=True)

        u = Upgrader(last_version, __version__)
        if u.run(ctx):
            app.set_state_item("last_version", __version__)
            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("")

    # PlatformIO banner
    click.echo("*" * terminal_width)
    click.echo(
        "If you like %s, please:" % (click.style("PlatformIO", fg="cyan")))
    click.echo("- %s us on Twitter to stay up-to-date "
               "on the latest project news > %s" %
               (click.style("follow", fg="cyan"),
                click.style("https://twitter.com/PlatformIO_Org", fg="cyan")))
    click.echo(
        "- %s it on GitHub > %s" %
        (click.style("star", fg="cyan"),
         click.style("https://github.com/platformio/platformio", fg="cyan")))
    if not getenv("PLATFORMIO_IDE"):
        click.echo(
            "- %s PlatformIO IDE for IoT development > %s" %
            (click.style("try", fg="cyan"),
             click.style("https://platformio.org/platformio-ide", fg="cyan")))
    if not util.is_ci():
        click.echo("- %s us with PlatformIO Plus > %s" % (click.style(
            "support", fg="cyan"), click.style(
                "https://pioplus.com", fg="cyan")))

    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 49
0
def check_internal_updates(ctx, what):
    last_check = app.get_state_item("last_check", {})
    interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24
    if (time() - interval) < last_check.get(what + "_update", 0):
        return

    last_check[what + '_update'] = int(time())
    app.set_state_item("last_check", last_check)

    pm = PlatformManager() if what == "platforms" else LibraryManager()
    outdated_items = []
    for manifest in pm.get_installed():
        if manifest['name'] not in outdated_items and \
                pm.is_outdated(manifest['name']):
            outdated_items.append(manifest['name'])

    if not outdated_items:
        return

    terminal_width, _ = click.get_terminal_size()

    click.echo("")
    click.echo("*" * terminal_width)
    click.secho(
        "There are the new updates for %s (%s)" %
        (what, ", ".join(outdated_items)),
        fg="yellow")

    if not app.get_setting("auto_update_" + what):
        click.secho("Please update them via ", fg="yellow", nl=False)
        click.secho(
            "`platformio %s update`" %
            ("lib --global" if what == "libraries" else "platform"),
            fg="cyan",
            nl=False)
        click.secho(" command.\n", fg="yellow")
        click.secho(
            "If you want to manually check for the new versions "
            "without updating, please use ",
            fg="yellow",
            nl=False)
        click.secho(
            "`platformio %s update --only-check`" %
            ("lib --global" if what == "libraries" else "platform"),
            fg="cyan",
            nl=False)
        click.secho(" command.", fg="yellow")
    else:
        click.secho("Please wait while updating %s ..." % what, fg="yellow")
        if what == "platforms":
            ctx.invoke(cmd_platform_update, platforms=outdated_items)
        elif what == "libraries":
            ctx.obj = pm
            ctx.invoke(cmd_lib_update, libraries=outdated_items)
        click.echo()

        telemetry.on_event(
            category="Auto", action="Update", label=what.title())

    click.echo("*" * terminal_width)
    click.echo("")
Esempio n. 50
0
 def _unregister(self, name):
     data = self.get_installed()
     del data[name]
     set_state_item("installed_packages", data)