Exemplo n.º 1
0
    def _install_from_piorepo(self, name, requirements):
        pkg_dir = None
        pkgdata = None
        versions = None
        last_exc = None
        for versions in PackageRepoIterator(name, self.repositories):
            pkgdata = self.max_satisfying_repo_version(versions, requirements)
            if not pkgdata:
                continue
            try:
                pkg_dir = self._install_from_url(name, pkgdata["url"],
                                                 requirements,
                                                 pkgdata.get("sha1"))
                break
            except Exception as e:  # pylint: disable=broad-except
                last_exc = e
                click.secho("Warning! Package Mirror: %s" % e, fg="yellow")
                click.secho("Looking for another mirror...", fg="yellow")

        if versions is None:
            util.internet_on(raise_exception=True)
            raise exception.UnknownPackage(name +
                                           (". Error -> %s" %
                                            last_exc if last_exc else ""))
        if not pkgdata:
            raise exception.UndefinedPackageVersion(requirements or "latest",
                                                    util.get_systype())
        return pkg_dir
Exemplo n.º 2
0
    def fetch_content(uri, data=None, headers=None, cache_valid=None):
        if not headers:
            headers = {
                "User-Agent":
                ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) "
                 "AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 "
                 "Safari/603.3.8")
            }
        cache_key = app.ContentCache.key_from_args(
            uri, data) if cache_valid else None
        with app.ContentCache() as cc:
            if cache_key:
                result = cc.get(cache_key)
                if result is not None:
                    defer.returnValue(result)

        # check internet before and resolve issue with 60 seconds timeout
        util.internet_on(raise_exception=True)

        session = helpers.requests_session()
        if data:
            r = yield session.post(uri, data=data, headers=headers)
        else:
            r = yield session.get(uri, headers=headers)

        r.raise_for_status()
        result = r.text
        if cache_valid:
            with app.ContentCache() as cc:
                cc.set(cache_key, result, cache_valid)
        defer.returnValue(result)
Exemplo n.º 3
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("")
Exemplo n.º 4
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("")
Exemplo n.º 5
0
    def update(  # pylint: disable=too-many-return-statements
            self,
            package,
            requirements=None,
            only_check=False):
        if isdir(package):
            pkg_dir = package
        else:
            pkg_dir = self.get_package_dir(*self.parse_pkg_input(package))

        if not pkg_dir:
            raise exception.UnknownPackage("%s @ %s" % (package,
                                                        requirements or "*"))

        manifest = self.load_manifest(pkg_dir)
        name = manifest['name']

        click.echo(
            "{} {:<40} @ {:<15}".format(
                "Checking" if only_check else "Updating",
                click.style(manifest['name'], fg="cyan"), manifest['version']),
            nl=False)
        if not util.internet_on():
            click.echo("[%s]" % (click.style("Off-line", fg="yellow")))
            return

        latest = self.outdated(pkg_dir, requirements)
        if latest:
            click.echo("[%s]" % (click.style(latest, fg="red")))
        elif latest is False:
            click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
        else:
            click.echo("[%s]" % (click.style("Skip", fg="yellow")))

        if only_check or not latest:
            return

        if "__src_url" in manifest:
            vcs = VCSClientFactory.newClient(pkg_dir, manifest['__src_url'])
            assert vcs.update()
            self._update_src_manifest(
                dict(version=vcs.get_current_revision()), vcs.storage_dir)
        else:
            self.uninstall(pkg_dir, trigger_event=False)
            self.install(name, latest, trigger_event=False)

        telemetry.on_event(
            category=self.__class__.__name__,
            action="Update",
            label=manifest['name'])
        return True
Exemplo n.º 6
0
    def _install_from_piorepo(self, name, requirements):
        pkg_dir = None
        pkgdata = None
        versions = None
        for versions in PackageRepoIterator(name, self.repositories):
            pkgdata = self.max_satisfying_repo_version(versions, requirements)
            if not pkgdata:
                continue
            try:
                pkg_dir = self._install_from_url(name, pkgdata['url'],
                                                 requirements,
                                                 pkgdata.get("sha1"))
                break
            except Exception as e:  # pylint: disable=broad-except
                click.secho("Warning! Package Mirror: %s" % e, fg="yellow")
                click.secho("Looking for another mirror...", fg="yellow")

        if versions is None:
            util.internet_on(raise_exception=True)
            raise exception.UnknownPackage(name)
        elif not pkgdata:
            raise exception.UndefinedPackageVersion(requirements or "latest",
                                                    util.get_systype())
        return pkg_dir
Exemplo n.º 7
0
    def update(self, package, requirements=None, only_check=False):
        self.cache_reset()
        if isdir(package) and self.get_package_by_dir(package):
            pkg_dir = package
        else:
            pkg_dir = self.get_package_dir(*self.parse_pkg_uri(package))

        if not pkg_dir:
            raise exception.UnknownPackage("%s @ %s" %
                                           (package, requirements or "*"))

        manifest = self.load_manifest(pkg_dir)
        name = manifest["name"]

        click.echo(
            "{} {:<40} @ {:<15}".format(
                "Checking" if only_check else "Updating",
                click.style(manifest["name"], fg="cyan"),
                manifest["version"],
            ),
            nl=False,
        )
        if not util.internet_on():
            click.echo("[%s]" % (click.style("Off-line", fg="yellow")))
            return None

        latest = self.outdated(pkg_dir, requirements)
        if latest:
            click.echo("[%s]" % (click.style(latest, fg="red")))
        elif latest is False:
            click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
        else:
            click.echo("[%s]" % (click.style("Detached", fg="yellow")))

        if only_check or not latest:
            return True

        if "__src_url" in manifest:
            vcs = VCSClientFactory.newClient(pkg_dir, manifest["__src_url"])
            assert vcs.update()
            self._update_src_manifest(dict(version=vcs.get_current_revision()),
                                      vcs.storage_dir)
        else:
            self.uninstall(pkg_dir, after_update=True)
            self.install(name, latest, after_update=True)

        return True
Exemplo n.º 8
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 --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("")
Exemplo n.º 9
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 --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("")
Exemplo n.º 10
0
    def update(
            self,  # pylint: disable=too-many-return-statements
            name,
            requirements=None,
            only_check=False):
        name, requirements, url = self.parse_pkg_name(name, requirements)
        package_dir = self.get_package_dir(name, requirements, url)
        if not package_dir:
            click.secho("%s @ %s is not installed" %
                        (name, requirements or "*"),
                        fg="yellow")
            return

        is_vcs_pkg = False
        if self.get_vcs_manifest_path(package_dir):
            is_vcs_pkg = True
            manifest_path = self.get_vcs_manifest_path(package_dir)
        else:
            manifest_path = self.get_manifest_path(package_dir)

        manifest = self.load_manifest(manifest_path)
        click.echo(
            "%s %s @ %s: \t" %
            ("Checking" if only_check else "Updating",
             click.style(manifest['name'], fg="cyan"), manifest['version']),
            nl=False)
        if is_vcs_pkg:
            if only_check:
                click.echo("[%s]" % (click.style("Skip", fg="yellow")))
                return
            click.echo("[%s]" % (click.style("VCS", fg="yellow")))
            vcs = VCSClientFactory.newClient(package_dir, manifest['url'])
            if not vcs.can_be_updated:
                click.secho("Skip update because repository is fixed "
                            "to %s revision" % manifest['version'],
                            fg="yellow")
                return
            assert vcs.update()
            with open(manifest_path, "w") as fp:
                manifest['version'] = vcs.get_current_revision()
                json.dump(manifest, fp)
        else:
            latest_version = None
            try:
                latest_version = self.get_latest_repo_version(
                    name, requirements)
            except exception.PlatformioException:
                pass
            if not latest_version:
                click.echo("[%s]" % (click.style(
                    "Off-line" if not util.internet_on() else "Unknown",
                    fg="yellow")))
                return

            up_to_date = False
            try:
                up_to_date = (semantic_version.Version.coerce(
                    manifest['version']) >=
                              semantic_version.Version.coerce(latest_version))
            except ValueError:
                up_to_date = latest_version == manifest['version']

            if up_to_date:
                click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
                return

            click.echo("[%s]" % (click.style("Out-of-date", fg="red")))
            if only_check:
                return
            self.uninstall(name, manifest['version'], trigger_event=False)
            self.install(name, latest_version, trigger_event=False)

        telemetry.on_event(category=self.__class__.__name__,
                           action="Update",
                           label=manifest['name'])
        return True
Exemplo n.º 11
0
    def update(self, name, requirements=None, only_check=False):  # pylint: disable=too-many-return-statements
        name, requirements, url = self.parse_pkg_name(name, requirements)
        package_dir = self.get_package_dir(name, None, url)
        if not package_dir:
            click.secho("%s @ %s is not installed" % (name, requirements or "*"), fg="yellow")
            return

        is_vcs_pkg = False
        if self.get_vcs_manifest_path(package_dir):
            is_vcs_pkg = True
            manifest_path = self.get_vcs_manifest_path(package_dir)
        else:
            manifest_path = self.get_manifest_path(package_dir)

        manifest = self.load_manifest(manifest_path)
        click.echo(
            "%s %s @ %s: \t"
            % ("Checking" if only_check else "Updating", click.style(manifest["name"], fg="cyan"), manifest["version"]),
            nl=False,
        )
        if is_vcs_pkg:
            if only_check:
                click.echo("[%s]" % (click.style("Skip", fg="yellow")))
                return
            click.echo("[%s]" % (click.style("VCS", fg="yellow")))
            vcs = VCSClientFactory.newClient(package_dir, manifest["url"])
            if not vcs.can_be_updated:
                click.secho(
                    "Skip update because repository is fixed " "to %s revision" % manifest["version"], fg="yellow"
                )
                return
            assert vcs.update()
            with open(manifest_path, "w") as fp:
                manifest["version"] = vcs.get_current_revision()
                json.dump(manifest, fp)
        else:
            latest_version = None
            try:
                latest_version = self.get_latest_repo_version(name, requirements)
            except exception.PlatformioException:
                pass
            if not latest_version:
                click.echo("[%s]" % (click.style("Off-line" if not util.internet_on() else "Unknown", fg="yellow")))
                return

            up_to_date = False
            try:
                up_to_date = semantic_version.Version.coerce(manifest["version"]) >= semantic_version.Version.coerce(
                    latest_version
                )
            except ValueError:
                up_to_date = latest_version == manifest["version"]

            if up_to_date:
                click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
                return

            click.echo("[%s]" % (click.style("Out-of-date", fg="red")))
            if only_check:
                return
            self.uninstall(name, manifest["version"], trigger_event=False)
            self.install(name, latest_version, trigger_event=False)

        telemetry.on_event(category=self.__class__.__name__, action="Update", label=manifest["name"])
        return True