示例#1
0
    def _install_from_url(self, name, url, requirements=None, sha1=None):
        pkg_dir = None
        tmp_dir = mkdtemp("-package", "installing-", self.package_dir)

        try:
            if url.startswith("file://"):
                url = url[7:]
                if isfile(url):
                    self.unpack(url, tmp_dir)
                else:
                    util.rmtree_(tmp_dir)
                    shutil.copytree(url, tmp_dir)
            elif url.startswith(("http://", "https://")):
                dlpath = self.download(url, tmp_dir, sha1)
                assert isfile(dlpath)
                self.unpack(dlpath, tmp_dir)
                os.remove(dlpath)
            else:
                vcs = VCSClientFactory.newClient(tmp_dir, url)
                assert vcs.export()
                with open(join(vcs.storage_dir, self.VCS_MANIFEST_NAME), "w") as fp:
                    json.dump(
                        {"name": name, "version": vcs.get_current_revision(), "url": url, "requirements": requirements},
                        fp,
                    )

            pkg_dir = self.check_pkg_structure(tmp_dir)
            pkg_dir = self._install_from_tmp_dir(pkg_dir, requirements)
        finally:
            if isdir(tmp_dir):
                util.rmtree_(tmp_dir)
        return pkg_dir
示例#2
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
示例#3
0
    def outdated(self, pkg_dir, requirements=None):
        """
        Has 3 different results:
        `None` - unknown package, VCS is detached to commit
        `False` - package is up-to-date
        `String` - a found latest version
        """
        if not isdir(pkg_dir):
            return None
        latest = None
        manifest = self.load_manifest(pkg_dir)
        # skip detached package to a specific version
        if "@" in pkg_dir and "__src_url" not in manifest and not requirements:
            return None

        if "__src_url" in manifest:
            try:
                vcs = VCSClientFactory.newClient(pkg_dir,
                                                 manifest["__src_url"],
                                                 silent=True)
            except (AttributeError, exception.PlatformioException):
                return None
            if not vcs.can_be_updated:
                return None
            latest = vcs.get_latest_revision()
        else:
            try:
                latest = self.get_latest_repo_version(
                    "id=%d" %
                    manifest["id"] if "id" in manifest else manifest["name"],
                    requirements,
                    silent=True,
                )
            except (exception.PlatformioException, ValueError):
                return None

        if not latest:
            return None

        up_to_date = False
        try:
            assert "__src_url" not in manifest
            up_to_date = self.parse_semver_version(
                manifest["version"],
                raise_exception=True) >= self.parse_semver_version(
                    latest, raise_exception=True)
        except (AssertionError, ValueError):
            up_to_date = latest == manifest["version"]

        return False if up_to_date else latest
示例#4
0
    def outdated(self, pkg_dir, requirements=None):
        """
        Has 3 different results:
        `None` - unknown package, VCS is detached to commit
        `False` - package is up-to-date
        `String` - a found latest version
        """
        if not isdir(pkg_dir):
            return None
        latest = None
        manifest = self.load_manifest(pkg_dir)
        # skip detached package to a specific version
        if "@" in pkg_dir and "__src_url" not in manifest and not requirements:
            return None

        if "__src_url" in manifest:
            try:
                vcs = VCSClientFactory.newClient(
                    pkg_dir, manifest['__src_url'], silent=True)
            except (AttributeError, exception.PlatformioException):
                return None
            if not vcs.can_be_updated:
                return None
            latest = vcs.get_latest_revision()
        else:
            try:
                latest = self.get_latest_repo_version(
                    "id=%d" % manifest['id']
                    if "id" in manifest else manifest['name'],
                    requirements,
                    silent=True)
            except (exception.PlatformioException, ValueError):
                return None

        if not latest:
            return None

        up_to_date = False
        try:
            assert "__src_url" not in manifest
            up_to_date = (self.parse_semver_version(
                manifest['version'], raise_exception=True) >=
                          self.parse_semver_version(
                              latest, raise_exception=True))
        except (AssertionError, ValueError):
            up_to_date = latest == manifest['version']

        return False if up_to_date else latest
示例#5
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
示例#6
0
    def outdated(self, pkg_dir, requirements=None):
        """
        Has 3 different results:
        `None` - unknown package, VCS is fixed to commit
        `False` - package is up-to-date
        `String` - a found latest version
        """
        assert isdir(pkg_dir)
        latest = None
        manifest = self.load_manifest(pkg_dir)
        # skip a fixed package to a specific version
        if "@" in pkg_dir and "__src_url" not in manifest:
            return None

        if "__src_url" in manifest:
            try:
                vcs = VCSClientFactory.newClient(pkg_dir,
                                                 manifest['__src_url'],
                                                 silent=True)
            except (AttributeError, exception.PlatformioException):
                return None
            if not vcs.can_be_updated:
                return None
            latest = vcs.get_latest_revision()
        else:
            try:
                latest = self.get_latest_repo_version(
                    "id=%d" %
                    manifest['id'] if "id" in manifest else manifest['name'],
                    requirements,
                    silent=True)
            except (exception.PlatformioException, ValueError):
                return None

        if not latest:
            return None

        up_to_date = False
        try:
            assert "__src_url" not in manifest
            up_to_date = (semantic_version.Version.coerce(manifest['version'])
                          >= semantic_version.Version.coerce(latest))
        except (AssertionError, ValueError):
            up_to_date = latest == manifest['version']

        return False if up_to_date else latest
示例#7
0
    def _install_from_url(self,
                          name,
                          url,
                          requirements=None,
                          sha1=None,
                          track=False):
        tmp_dir = mkdtemp("-package", self.TMP_FOLDER_PREFIX, self.package_dir)
        src_manifest_dir = None
        src_manifest = {"name": name, "url": url, "requirements": requirements}

        try:
            if url.startswith("file://"):
                _url = url[7:]
                if isfile(_url):
                    self.unpack(_url, tmp_dir)
                else:
                    fs.rmtree(tmp_dir)
                    shutil.copytree(_url, tmp_dir)
            elif url.startswith(("http://", "https://")):
                dlpath = self.download(url, tmp_dir, sha1)
                assert isfile(dlpath)
                self.unpack(dlpath, tmp_dir)
                os.remove(dlpath)
            else:
                vcs = VCSClientFactory.newClient(tmp_dir, url)
                assert vcs.export()
                src_manifest_dir = vcs.storage_dir
                src_manifest["version"] = vcs.get_current_revision()

            _tmp_dir = tmp_dir
            if not src_manifest_dir:
                _tmp_dir = self.find_pkg_root(tmp_dir)
                src_manifest_dir = join(_tmp_dir, ".pio")

            # write source data to a special manifest
            if track:
                self._update_src_manifest(src_manifest, src_manifest_dir)

            return self._install_from_tmp_dir(_tmp_dir, requirements)
        finally:
            if isdir(tmp_dir):
                fs.rmtree(tmp_dir)
        return None
示例#8
0
    def _install_from_url(self,
                          name,
                          url,
                          requirements=None,
                          sha1=None,
                          track=False):
        tmp_dir = mkdtemp("-package", self.TMP_FOLDER_PREFIX, self.package_dir)
        src_manifest_dir = None
        src_manifest = {"name": name, "url": url, "requirements": requirements}

        try:
            if url.startswith("file://"):
                _url = url[7:]
                if isfile(_url):
                    self.unpack(_url, tmp_dir)
                else:
                    util.rmtree_(tmp_dir)
                    shutil.copytree(_url, tmp_dir)
            elif url.startswith(("http://", "https://")):
                dlpath = self.download(url, tmp_dir, sha1)
                assert isfile(dlpath)
                self.unpack(dlpath, tmp_dir)
                os.remove(dlpath)
            else:
                vcs = VCSClientFactory.newClient(tmp_dir, url)
                assert vcs.export()
                src_manifest_dir = vcs.storage_dir
                src_manifest['version'] = vcs.get_current_revision()

            _tmp_dir = tmp_dir
            if not src_manifest_dir:
                _tmp_dir = self.find_pkg_root(tmp_dir)
                src_manifest_dir = join(_tmp_dir, ".pio")

            # write source data to a special manifest
            if track:
                self._update_src_manifest(src_manifest, src_manifest_dir)

            return self._install_from_tmp_dir(_tmp_dir, requirements)
        finally:
            if isdir(tmp_dir):
                util.rmtree_(tmp_dir)
        return None
示例#9
0
    def _install_from_url(self, name, url, requirements=None, sha1=None):
        pkg_dir = None
        tmp_dir = mkdtemp("-package", "installing-", self.package_dir)

        try:
            if url.startswith("file://"):
                url = url[7:]
                if isfile(url):
                    self.unpack(url, tmp_dir)
                else:
                    util.rmtree_(tmp_dir)
                    copytree(url, tmp_dir)
            elif url.startswith(("http://", "https://")):
                dlpath = self.download(url, tmp_dir, sha1)
                assert isfile(dlpath)
                self.unpack(dlpath, tmp_dir)
                os.remove(dlpath)
            else:
                vcs = VCSClientFactory.newClient(tmp_dir, url)
                assert vcs.export()
                with open(join(vcs.storage_dir, self.VCS_MANIFEST_NAME),
                          "w") as fp:
                    json.dump(
                        {
                            "name": name,
                            "version": vcs.get_current_revision(),
                            "url": url,
                            "requirements": requirements
                        }, fp)

            pkg_dir = self.check_pkg_structure(tmp_dir)
            pkg_dir = self._install_from_tmp_dir(pkg_dir, requirements)
        finally:
            if isdir(tmp_dir):
                util.rmtree_(tmp_dir)
        return pkg_dir
示例#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
示例#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