Exemple #1
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("")
Exemple #2
0
def platform_list(json_output):
    platforms = []
    pm = PlatformManager()
    for manifest in pm.get_installed():
        p = PlatformFactory.newPlatform(
            pm.get_manifest_path(manifest['__pkg_dir']))
        platforms.append({
            "name":
            p.name,
            "title":
            p.title,
            "description":
            p.description,
            "version":
            p.version,
            "url":
            p.vendor_url,
            "packages":
            p.get_installed_packages().keys(),
            'forDesktop':
            any([p.name.startswith(n) for n in ("native", "linux", "windows")])
        })

    if json_output:
        click.echo(json.dumps(platforms))
    else:
        _print_platforms(platforms)
Exemple #3
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("")
Exemple #4
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("")
Exemple #5
0
def platform_update(platforms, only_packages, only_check):
    pm = PlatformManager()
    if not platforms:
        platforms = set([m['name'] for m in pm.get_installed()])
    for platform in platforms:
        click.echo("Platform %s" % click.style(platform, fg="cyan"))
        click.echo("--------")
        pm.update(platform, only_packages=only_packages, only_check=only_check)
        click.echo()
Exemple #6
0
def platform_update(platforms, only_packages, only_check):
    pm = PlatformManager()
    if not platforms:
        platforms = set([m['name'] for m in pm.get_installed()])
    for platform in platforms:
        click.echo("Platform %s" % click.style(platform, fg="cyan"))
        click.echo("--------")
        pm.update(platform, only_packages=only_packages, only_check=only_check)
        click.echo()
def platform_list(json_output):
    platforms = []
    pm = PlatformManager()
    for manifest in pm.get_installed():
        platforms.append(
            _get_installed_platform_data(manifest['__pkg_dir'],
                                         with_boards=False,
                                         expose_packages=False))
    if json_output:
        click.echo(json.dumps(platforms))
    else:
        _print_platforms(platforms)
Exemple #8
0
def platform_list(json_output):
    platforms = []
    pm = PlatformManager()
    for manifest in pm.get_installed():
        platforms.append(
            _get_installed_platform_data(manifest["__pkg_dir"],
                                         with_boards=False,
                                         expose_packages=False))

    platforms = sorted(platforms, key=lambda manifest: manifest["name"])
    if json_output:
        click.echo(dump_json_to_unicode(platforms))
    else:
        _print_platforms(platforms)
Exemple #9
0
def platform_list(json_output):
    platforms = []
    pm = PlatformManager()
    for manifest in pm.get_installed():
        platforms.append(
            _get_installed_platform_data(
                manifest['__pkg_dir'],
                with_boards=False,
                expose_packages=False))

    platforms = sorted(platforms, key=lambda manifest: manifest['name'])
    if json_output:
        click.echo(json.dumps(platforms))
    else:
        _print_platforms(platforms)
Exemple #10
0
def get_builtin_libs(storage_names=None):
    items = []
    storage_names = storage_names or []
    pm = PlatformManager()
    for manifest in pm.get_installed():
        p = PlatformFactory.newPlatform(manifest['__pkg_dir'])
        for storage in p.get_lib_storages():
            if storage_names and storage['name'] not in storage_names:
                continue
            lm = LibraryManager(storage['path'])
            items.append({
                "name": storage['name'],
                "path": storage['path'],
                "items": lm.get_installed()
            })
    return items
Exemple #11
0
def get_builtin_libs(storage_names=None):
    items = []
    storage_names = storage_names or []
    pm = PlatformManager()
    for manifest in pm.get_installed():
        p = PlatformFactory.newPlatform(manifest['__pkg_dir'])
        for storage in p.get_lib_storages():
            if storage_names and storage['name'] not in storage_names:
                continue
            lm = LibraryManager(storage['path'])
            items.append({
                "name": storage['name'],
                "path": storage['path'],
                "items": lm.get_installed()
            })
    return items
Exemple #12
0
def platform_update(  # pylint: disable=too-many-locals
        platforms, only_packages, only_check, dry_run, json_output):
    pm = PlatformManager()
    pkg_dir_to_name = {}
    if not platforms:
        platforms = []
        for manifest in pm.get_installed():
            platforms.append(manifest["__pkg_dir"])
            pkg_dir_to_name[manifest["__pkg_dir"]] = manifest.get(
                "title", manifest["name"])

    only_check = dry_run or only_check

    if only_check and json_output:
        result = []
        for platform in platforms:
            pkg_dir = platform if isdir(platform) else None
            requirements = None
            url = None
            if not pkg_dir:
                name, requirements, url = pm.parse_pkg_uri(platform)
                pkg_dir = pm.get_package_dir(name, requirements, url)
            if not pkg_dir:
                continue
            latest = pm.outdated(pkg_dir, requirements)
            if (not latest and not PlatformFactory.newPlatform(
                    pkg_dir).are_outdated_packages()):
                continue
            data = _get_installed_platform_data(pkg_dir,
                                                with_boards=False,
                                                expose_packages=False)
            if latest:
                data["versionLatest"] = latest
            result.append(data)
        return click.echo(dump_json_to_unicode(result))

    # cleanup cached board and platform lists
    app.clean_cache()
    for platform in platforms:
        click.echo(
            "Platform %s" %
            click.style(pkg_dir_to_name.get(platform, platform), fg="cyan"))
        click.echo("--------")
        pm.update(platform, only_packages=only_packages, only_check=only_check)
        click.echo()

    return True
Exemple #13
0
def platform_update(platforms, only_packages, only_check, json_output):
    pm = PlatformManager()
    pkg_dir_to_name = {}
    if not platforms:
        platforms = []
        for manifest in pm.get_installed():
            platforms.append(manifest['__pkg_dir'])
            pkg_dir_to_name[manifest['__pkg_dir']] = manifest.get(
                "title", manifest['name'])

    if only_check and json_output:
        result = []
        for platform in platforms:
            pkg_dir = platform if isdir(platform) else None
            requirements = None
            url = None
            if not pkg_dir:
                name, requirements, url = pm.parse_pkg_input(platform)
                pkg_dir = pm.get_package_dir(name, requirements, url)
            if not pkg_dir:
                continue
            latest = pm.outdated(pkg_dir, requirements)
            if (not latest and not PlatformFactory.newPlatform(
                    pkg_dir).are_outdated_packages()):
                continue
            data = _get_installed_platform_data(pkg_dir,
                                                with_boards=False,
                                                expose_packages=False)
            if latest:
                data['versionLatest'] = latest
            result.append(data)
        return click.echo(json.dumps(result))
    else:
        # cleanup cached board and platform lists
        app.clean_cache()
        for platform in platforms:
            click.echo("Platform %s" % click.style(
                pkg_dir_to_name.get(platform, platform), fg="cyan"))
            click.echo("--------")
            pm.update(platform,
                      only_packages=only_packages,
                      only_check=only_check)
            click.echo()
Exemple #14
0
def platform_update(platforms, only_packages, only_check, json_output):
    pm = PlatformManager()
    pkg_dir_to_name = {}
    if not platforms:
        platforms = []
        for manifest in pm.get_installed():
            platforms.append(manifest['__pkg_dir'])
            pkg_dir_to_name[manifest['__pkg_dir']] = manifest.get(
                "title", manifest['name'])

    if only_check and json_output:
        result = []
        for platform in platforms:
            pkg_dir = platform if isdir(platform) else None
            requirements = None
            url = None
            if not pkg_dir:
                name, requirements, url = pm.parse_pkg_uri(platform)
                pkg_dir = pm.get_package_dir(name, requirements, url)
            if not pkg_dir:
                continue
            latest = pm.outdated(pkg_dir, requirements)
            if (not latest and not PlatformFactory.newPlatform(
                    pkg_dir).are_outdated_packages()):
                continue
            data = _get_installed_platform_data(
                pkg_dir, with_boards=False, expose_packages=False)
            if latest:
                data['versionLatest'] = latest
            result.append(data)
        return click.echo(json.dumps(result))
    else:
        # cleanup cached board and platform lists
        app.clean_cache()
        for platform in platforms:
            click.echo("Platform %s" % click.style(
                pkg_dir_to_name.get(platform, platform), fg="cyan"))
            click.echo("--------")
            pm.update(
                platform, only_packages=only_packages, only_check=only_check)
            click.echo()

    return True
Exemple #15
0
def platform_list(json_output):
    platforms = []
    pm = PlatformManager()
    for manifest in pm.get_installed():
        p = PlatformFactory.newPlatform(
            pm.get_manifest_path(manifest['__pkg_dir']))
        platforms.append({
            "name": p.name,
            "title": p.title,
            "description": p.description,
            "version": p.version,
            "url": p.vendor_url,
            "packages": p.get_installed_packages().keys(),
            'forDesktop': any([
                p.name.startswith(n) for n in ("native", "linux", "windows")
            ])
        })

    if json_output:
        click.echo(json.dumps(platforms))
    else:
        _print_platforms(platforms)
Exemple #16
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("")
Exemple #17
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)

    util.internet_on(raise_exception=True)

    pm = PlatformManager() if what == "platforms" else LibraryManager()
    outdated_items = []
    for manifest in pm.get_installed():
        if manifest["name"] in outdated_items:
            continue
        conds = [
            pm.outdated(manifest["__pkg_dir"]),
            what == "platforms" and PlatformFactory.newPlatform(
                manifest["__pkg_dir"]).are_outdated_packages(),
        ]
        if any(conds):
            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 --dry-run`" %
            ("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.meta[CTX_META_STORAGE_DIRS_KEY] = [pm.package_dir]
            ctx.invoke(cmd_lib_update, libraries=outdated_items)
        click.echo()

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

    click.echo("*" * terminal_width)
    click.echo("")