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 install(
        self, name, requirements=None, silent=False, after_update=False, force=False
    ):  # pylint: disable=unused-argument
        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

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

        return pkg_dir
Exemplo n.º 3
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