コード例 #1
0
        public void UninstallPackage(string fastPackageReference, Request request)
        {
            var package = PythonPackage.FromFastReference(fastPackageReference, request);

            package.Uninstall(request);
        }
コード例 #2
0
        public void InstallPackage(string fastPackageReference, Request request)
        {
            request.Debug("Calling '{0}::InstallPackage' '{1}'", ProviderName, fastPackageReference);
            var package = PythonPackage.FromFastReference(fastPackageReference, request);

            if (package is PythonInstall)
            {
                ((PythonInstall)package).Install(request);
                return;
            }
            bool retried = false;

retry:
            List <PythonInstall> usableinstalls   = new List <PythonInstall>();
            List <PythonInstall> unusableinstalls = new List <PythonInstall>();

            foreach (var candidateinstall in PythonInstall.FindEnvironments(request))
            {
                if (package.CanInstall(candidateinstall, request))
                {
                    usableinstalls.Add(candidateinstall);
                }
                else
                {
                    unusableinstalls.Add(candidateinstall);
                }
            }
            if (usableinstalls.Count == 1)
            {
                package.Install(usableinstalls[0], request);
            }
            else if (usableinstalls.Count == 0)
            {
                // Need to install a Python
                if (retried)
                {
                    request.Error(ErrorCategory.NotImplemented, package.name, "Failed to install a Python interpreter");
                    return;
                }

                List <PythonPackage> candidate_pythons = new List <PythonPackage>(
                    PythonWebsite.Search("Python", null, null, null, true, request));
                candidate_pythons.Sort(new PackageVersionComparer());

                bool installed = false;

                for (int i = candidate_pythons.Count - 1; i >= 0; i--)
                {
                    if (Environment.Is64BitOperatingSystem &&
                        ((PythonInstall)candidate_pythons[i]).CanInstall(true, request) &&
                        package.CanInstall((PythonInstall)candidate_pythons[i], true, request))
                    {
                        ((PythonInstall)candidate_pythons[i]).Install(true, request);
                        installed = true;
                        break;
                    }
                    else if (((PythonInstall)candidate_pythons[i]).CanInstall(false, request) &&
                             package.CanInstall((PythonInstall)candidate_pythons[i], true, request))
                    {
                        ((PythonInstall)candidate_pythons[i]).Install(false, request);
                        installed = true;
                        break;
                    }
                }

                if (installed)
                {
                    retried = true;
                    goto retry;
                }
                else
                {
                    request.Error(ErrorCategory.NotImplemented, package.name, "Couldn't find a Python interpreter to install for this");
                    return;
                }
            }
            else if (usableinstalls.Count > 1)
            {
                if (request.GetOptionValue("Force") == "True")
                {
                    PythonInstall greatest = usableinstalls[0];
                    foreach (var candidate in usableinstalls)
                    {
                        if (candidate.version.Compare(greatest.version) > 0)
                        {
                            greatest = candidate;
                        }
                    }
                    package.Install(greatest, request);
                }
                else
                {
                    request.Warning("Multiple installed Python interpreters could satisfy this request:");
                    foreach (var install in usableinstalls)
                    {
                        request.Warning("  Python version '{0}' at '{1}'", install.version, install.exe_path);
                    }
                    request.Warning("Please select a Python to install to, using e.g. -PythonVersion 3.2 or -PythonLocation c:\\python32\\python.exe");
                    request.Error(ErrorCategory.NotSpecified, package.name, "Not enough information to select a Python interpreter for the install");
                }
            }
        }