Exemplo n.º 1
0
    def install(self,
                name,
                requirements=None,
                silent=False,
                trigger_event=True,
                force=False):
        name, requirements, url = self.parse_pkg_uri(name, requirements)
        package_dir = self.get_package_dir(name, requirements, url)

        # avoid circle dependencies
        if not self.INSTALL_HISTORY:
            self.INSTALL_HISTORY = []
        history_key = "%s-%s-%s" % (name, requirements or "", url or "")
        if history_key in self.INSTALL_HISTORY:
            return package_dir
        self.INSTALL_HISTORY.append(history_key)

        if package_dir and force:
            self.uninstall(package_dir)
            package_dir = None

        if not package_dir or not silent:
            msg = "Installing " + click.style(name, fg="cyan")
            if requirements:
                msg += " @ " + requirements
            self.print_message(msg)
        if package_dir:
            if not silent:
                click.secho(
                    "{name} @ {version} is already installed".format(
                        **self.load_manifest(package_dir)),
                    fg="yellow")
            return package_dir

        if url:
            pkg_dir = self._install_from_url(
                name, url, requirements, track=True)
        else:
            pkg_dir = self._install_from_piorepo(name, requirements)

        if not pkg_dir or not self.manifest_exists(pkg_dir):
            raise exception.PackageInstallError(name, requirements or "*",
                                                util.get_systype())

        manifest = self.load_manifest(pkg_dir)
        assert manifest

        if trigger_event:
            telemetry.on_event(
                category=self.__class__.__name__,
                action="Install",
                label=manifest['name'])

        if not silent:
            click.secho(
                "{name} @ {version} has been successfully installed!".format(
                    **manifest),
                fg="green")

        return pkg_dir
Exemplo n.º 2
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("")
Exemplo n.º 3
0
    def install(self, name):
        click.echo("Installing %s package:" % click.style(name, fg="cyan"))

        if self.is_installed(name):
            click.secho("Already installed", fg="yellow")
            return False

        info = self.get_info(name)
        pkg_dir = join(self._package_dir, name)
        if not isdir(pkg_dir):
            makedirs(pkg_dir)

        dlpath = None
        try:
            dlpath = self.download(info['url'], pkg_dir, info['sha1'])
        except (requests.exceptions.ConnectionError,
                exception.FDUnrecognizedStatusCode):
            if info['url'].startswith("http://sourceforge.net"):
                dlpath = self.download(
                    "http://dl.platformio.org/packages/%s" %
                    basename(info['url']), pkg_dir, info['sha1'])

        assert isfile(dlpath)

        if self.unpack(dlpath, pkg_dir):
            self._register(name, info['version'])
        # remove archive
        remove(dlpath)

        telemetry.on_event(
            category="PackageManager", action="Install", label=name)
Exemplo n.º 4
0
    def install(self, id_, version=None):
        if self.is_installed(id_):
            raise LibAlreadyInstalledError()

        dlinfo = get_api_result("/lib/download/" + str(id_),
                                dict(version=version) if version else None)
        dlpath = None
        tmplib_dir = join(self.lib_dir, str(id_))
        try:
            dlpath = self.download(dlinfo['url'], gettempdir())
            if not isdir(tmplib_dir):
                makedirs(tmplib_dir)
            self.unpack(dlpath, tmplib_dir)
        finally:
            if dlpath:
                remove(dlpath)

        info = self.get_info(id_)
        rename(tmplib_dir, join(self.lib_dir, "%s_ID%d" % (
            re.sub(r"[^\da-zA-Z]+", "_", info['name']), id_)))

        telemetry.on_event(
            category="LibraryManager", action="Install",
            label="#%d %s" % (id_, info['name'])
        )

        return True
Exemplo n.º 5
0
 def uninstall(self, id_):
     for libdir, item in self.get_installed().iteritems():
         if "id" in item and item["id"] == id_:
             rmtree(join(self.lib_dir, libdir))
             telemetry.on_event(category="LibraryManager", action="Uninstall", label="#%d %s" % (id_, item["name"]))
             return True
     raise LibNotInstalledError(id_)
Exemplo n.º 6
0
    def install(
        self, name, requirements=None, silent=False, trigger_event=True, interactive=False
    ):  # pylint: disable=unused-argument
        name, requirements, url = self.parse_pkg_name(name, requirements)
        package_dir = self.get_package_dir(name, requirements, url)

        if not package_dir or not silent:
            msg = "Installing " + click.style(name, fg="cyan")
            if requirements:
                msg += " @ " + requirements
            self.print_message(msg)
        if package_dir:
            if not silent:
                click.secho(
                    "{name} @ {version} is already installed".format(**self.load_manifest(package_dir)), fg="yellow"
                )
            return package_dir

        if url:
            pkg_dir = self._install_from_url(name, url, requirements)
        else:
            pkg_dir = self._install_from_piorepo(name, requirements)
        if not pkg_dir or not self.manifest_exists(pkg_dir):
            raise exception.PackageInstallError(name, requirements or "*", util.get_systype())

        self.reset_cache()
        manifest = self.load_manifest(pkg_dir)

        if trigger_event:
            telemetry.on_event(category=self.__class__.__name__, action="Install", label=manifest["name"])

        click.secho("{name} @ {version} has been successfully installed!".format(**manifest), fg="green")

        return pkg_dir
Exemplo n.º 7
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("")
Exemplo n.º 8
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("")
Exemplo n.º 9
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.º 10
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("")
Exemplo n.º 11
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.º 12
0
    def uninstall(self, name):
        click.echo("Uninstalling %s package: \t" %
                   click.style(name, fg="cyan"), nl=False)

        if not self.is_installed(name):
            click.secho("Not installed", fg="yellow")
            return False

        rmtree(join(self._package_dir, name))
        self._unregister(name)
        click.echo("[%s]" % click.style("OK", fg="green"))

        # report usage
        telemetry.on_event(
            category="PackageManager", action="Uninstall", label=name)
Exemplo n.º 13
0
    def uninstall(self, name):
        click.echo("Uninstalling %s package: \t" %
                   click.style(name, fg="cyan"), nl=False)

        if not self.is_installed(name):
            click.secho("Not installed", fg="yellow")
            return False

        rmtree(join(self._package_dir, name))
        self._unregister(name)
        click.echo("[%s]" % click.style("OK", fg="green"))

        # report usage
        telemetry.on_event(
            category="PackageManager", action="Uninstall", label=name)
Exemplo n.º 14
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("")
Exemplo n.º 15
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("")
Exemplo n.º 16
0
    def uninstall(self, package, requirements=None, after_update=False):
        # interprocess lock
        with LockFile(self.package_dir):
            self.cache_reset()

            if isdir(package) and self.get_package_by_dir(package):
                pkg_dir = package
            else:
                name, requirements, url = self.parse_pkg_uri(
                    package, requirements)
                pkg_dir = self.get_package_dir(name, requirements, url)

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

            manifest = self.load_manifest(pkg_dir)
            click.echo(
                "Uninstalling %s @ %s: \t" % (click.style(
                    manifest['name'], fg="cyan"), manifest['version']),
                nl=False)

            if islink(pkg_dir):
                os.unlink(pkg_dir)
            else:
                util.rmtree_(pkg_dir)
            self.cache_reset()

            # unfix package with the same name
            pkg_dir = self.get_package_dir(manifest['name'])
            if pkg_dir and "@" in pkg_dir:
                shutil.move(
                    pkg_dir,
                    join(self.package_dir, self.get_install_dirname(manifest)))
                self.cache_reset()

            click.echo("[%s]" % click.style("OK", fg="green"))

            if not after_update:
                telemetry.on_event(
                    category=self.__class__.__name__,
                    action="Uninstall",
                    label=manifest['name'])

        return True
Exemplo n.º 17
0
    def uninstall(self, package, requirements=None, after_update=False):
        # interprocess lock
        with LockFile(self.package_dir):
            self.cache_reset()

            if isdir(package) and self.get_package_by_dir(package):
                pkg_dir = package
            else:
                name, requirements, url = self.parse_pkg_uri(
                    package, requirements)
                pkg_dir = self.get_package_dir(name, requirements, url)

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

            manifest = self.load_manifest(pkg_dir)
            click.echo("Uninstalling %s @ %s: \t" % (click.style(
                manifest['name'], fg="cyan"), manifest['version']),
                       nl=False)

            if islink(pkg_dir):
                os.unlink(pkg_dir)
            else:
                fs.rmtree(pkg_dir)
            self.cache_reset()

            # unfix package with the same name
            pkg_dir = self.get_package_dir(manifest['name'])
            if pkg_dir and "@" in pkg_dir:
                shutil.move(
                    pkg_dir,
                    join(self.package_dir, self.get_install_dirname(manifest)))
                self.cache_reset()

            click.echo("[%s]" % click.style("OK", fg="green"))

            if not after_update:
                telemetry.on_event(category=self.__class__.__name__,
                                   action="Uninstall",
                                   label=manifest['name'])

        return True
Exemplo n.º 18
0
    def install(self,
                name,
                requirements=None,
                silent=False,
                trigger_event=True,
                interactive=False):  # pylint: disable=unused-argument
        name, requirements, url = self.parse_pkg_name(name, requirements)
        package_dir = self.get_package_dir(name, requirements, url)

        if not package_dir or not silent:
            msg = "Installing " + click.style(name, fg="cyan")
            if requirements:
                msg += " @ " + requirements
            self.print_message(msg)
        if package_dir:
            if not silent:
                click.secho("{name} @ {version} is already installed".format(
                    **self.load_manifest(package_dir)),
                            fg="yellow")
            return package_dir

        if url:
            pkg_dir = self._install_from_url(name, url, requirements)
        else:
            pkg_dir = self._install_from_piorepo(name, requirements)
        if not pkg_dir or not self.manifest_exists(pkg_dir):
            raise exception.PackageInstallError(name, requirements or "*",
                                                util.get_systype())

        self.reset_cache()
        manifest = self.load_manifest(pkg_dir)

        if trigger_event:
            telemetry.on_event(category=self.__class__.__name__,
                               action="Install",
                               label=manifest['name'])

        click.secho(
            "{name} @ {version} has been successfully installed!".format(
                **manifest),
            fg="green")

        return pkg_dir
Exemplo n.º 19
0
    def install(self, name):
        click.echo("Installing %s package:" % click.style(name, fg="cyan"))

        if self.is_installed(name):
            click.secho("Already installed", fg="yellow")
            return False

        info = self.get_info(name)
        pkg_dir = join(self._package_dir, name)
        if not isdir(pkg_dir):
            makedirs(pkg_dir)

        dlpath = self.download(info['url'], pkg_dir, info['sha1'])
        if self.unpack(dlpath, pkg_dir):
            self._register(name, info['version'])
        # remove archive
        remove(dlpath)

        telemetry.on_event(
            category="PackageManager", action="Install", label=name)
Exemplo n.º 20
0
    def install(self, name):
        click.echo("Installing %s package:" % click.style(name, fg="cyan"))

        if self.is_installed(name):
            click.secho("Already installed", fg="yellow")
            return False

        info = self.get_info(name)
        pkg_dir = join(self._package_dir, name)
        if not isdir(pkg_dir):
            makedirs(pkg_dir)

        dlpath = self.download(info['url'], pkg_dir, info['sha1'])
        if self.unpack(dlpath, pkg_dir):
            self._register(name, info['version'])
        # remove archive
        remove(dlpath)

        telemetry.on_event(
            category="PackageManager", action="Install", label=name)
Exemplo n.º 21
0
    def update(self, name):
        click.echo("Updating %s package:" % click.style(name, fg="yellow"))

        installed = self.get_installed()
        current_version = installed[name]['version']
        latest_version = self.get_info(name)['version']

        click.echo("Versions: Current=%d, Latest=%d \t " %
                   (current_version, latest_version), nl=False)

        if current_version == latest_version:
            click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
            return True
        else:
            click.echo("[%s]" % (click.style("Out-of-date", fg="red")))

        self.uninstall(name)
        self.install(name)

        telemetry.on_event(
            category="PackageManager", action="Update", label=name)
Exemplo n.º 22
0
    def update(self, name):
        click.echo("Updating %s package:" % click.style(name, fg="yellow"))

        installed = self.get_installed()
        current_version = installed[name]['version']
        latest_version = self.get_info(name)['version']

        click.echo("Versions: Current=%d, Latest=%d \t " %
                   (current_version, latest_version), nl=False)

        if current_version == latest_version:
            click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
            return True
        else:
            click.echo("[%s]" % (click.style("Out-of-date", fg="red")))

        self.uninstall(name)
        self.install(name)

        telemetry.on_event(
            category="PackageManager", action="Update", label=name)
Exemplo n.º 23
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("")
Exemplo n.º 24
0
    def uninstall(self, name, requirements=None, trigger_event=True):
        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

        manifest = self.load_manifest(package_dir)
        click.echo(
            "Uninstalling %s @ %s: \t" % (click.style(manifest["name"], fg="cyan"), manifest["version"]), nl=False
        )

        if isdir(package_dir):
            if islink(package_dir):
                os.unlink(package_dir)
            else:
                util.rmtree_(package_dir)

        click.echo("[%s]" % click.style("OK", fg="green"))

        self.reset_cache()
        if trigger_event:
            telemetry.on_event(category=self.__class__.__name__, action="Uninstall", label=manifest["name"])
        return True
Exemplo n.º 25
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("")
Exemplo n.º 26
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.º 27
0
    def install(self,
                name,
                requirements=None,
                silent=False,
                after_update=False,
                force=False):
        pkg_dir = None
        # interprocess lock
        with LockFile(self.package_dir):
            self.cache_reset()

            name, requirements, url = self.parse_pkg_uri(name, requirements)
            package_dir = self.get_package_dir(name, requirements, url)

            # avoid circle dependencies
            if not self.INSTALL_HISTORY:
                self.INSTALL_HISTORY = []
            history_key = "%s-%s-%s" % (name, requirements or "", url or "")
            if history_key in self.INSTALL_HISTORY:
                return package_dir
            self.INSTALL_HISTORY.append(history_key)

            if package_dir and force:
                self.uninstall(package_dir)
                package_dir = None

            if not package_dir or not silent:
                msg = "Installing " + click.style(name, fg="cyan")
                if requirements:
                    msg += " @ " + requirements
                self.print_message(msg)
            if package_dir:
                if not silent:
                    click.secho(
                        "{name} @ {version} is already installed".format(
                            **self.load_manifest(package_dir)),
                        fg="yellow")
                return package_dir

            if url:
                pkg_dir = self._install_from_url(name,
                                                 url,
                                                 requirements,
                                                 track=True)
            else:
                pkg_dir = self._install_from_piorepo(name, requirements)

            if not pkg_dir or not self.manifest_exists(pkg_dir):
                raise exception.PackageInstallError(name, requirements or "*",
                                                    util.get_systype())

            manifest = self.load_manifest(pkg_dir)
            assert manifest

            if not after_update:
                telemetry.on_event(category=self.__class__.__name__,
                                   action="Install",
                                   label=manifest['name'])

            click.secho(
                "{name} @ {version} has been successfully installed!".format(
                    **manifest),
                fg="green")

        return pkg_dir
Exemplo n.º 28
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(
            "http://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("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("")
Exemplo n.º 29
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
Exemplo n.º 30
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")

        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():
                # @TODO Uncomment line below after first PIO3 release
                # 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 to keep PlatformIO alive! > %s" % (click.style(
            "donate", fg="cyan"), click.style(
                "http://platformio.org/donate", fg="cyan")))

    click.echo("*" * terminal_width)
    click.echo("")
Exemplo n.º 31
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'] 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.º 32
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("")