Esempio n. 1
0
 public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request)
 {
     request.Debug("Calling '{0}::FindPackage'({1},{2},{3},{4})", ProviderName, name, requiredVersion, minimumVersion, maximumVersion);
     foreach (var package in PythonWebsite.Search(name, requiredVersion, minimumVersion, maximumVersion, (request.GetOptionValue("AllVersions") == "True"), request))
     {
         package.YieldSelf(request);
     }
     foreach (var package in PyPI.Search(name, requiredVersion, minimumVersion, maximumVersion, request))
     {
         package.YieldSelf(request);
     }
 }
Esempio n. 2
0
 public static PythonPackage FromFastReference(string fastreference, Request request)
 {
     if (fastreference.StartsWith("distinfo:"))
     {
         string[]      parts   = fastreference.Substring(9).Split(new char[] { '|' }, 2);
         PythonInstall install = PythonInstall.FromPath(parts[0], request);
         return(FromDistInfo(parts[1], install, request));
     }
     else if (fastreference.StartsWith("egginfo:"))
     {
         string[]      parts   = fastreference.Substring(8).Split(new char[] { '|' }, 2);
         PythonInstall install = PythonInstall.FromPath(parts[0], request);
         return(FromEggInfo(parts[1], install, request));
     }
     else if (fastreference.StartsWith("pypi:"))
     {
         string[] parts     = fastreference.Substring(5).Split(new char[] { '#' }, 3);
         string   source    = parts[0];
         string   sourceurl = parts[1];
         parts = parts[2].Split(new char[] { '/' });
         string name    = parts[0];
         string version = parts[1];
         return(PyPI.GetPackage(new Tuple <string, string>(source, sourceurl), name, version, request));
     }
     else if (fastreference.StartsWith("archive:"))
     {
         string[] parts        = fastreference.Substring(8).Split(new char[] { '/' }, 3);
         string   name         = parts[0];
         string   version      = parts[1];
         string   archive_path = parts[2];
         foreach (var package in PackagesFromFile(archive_path, request))
         {
             if (package.name == name && package.version.Compare(version) == 0)
             {
                 return(package);
             }
         }
     }
     else if (fastreference.StartsWith("pythonweb:"))
     {
         return(PythonWebsite.PackageFromWebResource(fastreference.Substring(10), request));
     }
     else if (fastreference.StartsWith("installedpython:"))
     {
         return(PythonInstall.FromPath(fastreference.Substring(16), request));
     }
     return(null);
 }
Esempio n. 3
0
        private JObject FindDownload(bool install_64bit, out bool is_msi, Request request)
        {
            if (web_resource == null)
            {
                throw new InvalidOperationException("Installing an existing install of Python doesn't make sense");
            }

            JObject download = null;

            is_msi = false;
            foreach (JObject candidate in PythonWebsite.DownloadsFromWebResource(web_resource, request))
            {
                string name = candidate["name"].ToString();
                if (install_64bit)
                {
                    if (name == "Windows x86-64 MSI installer")
                    {
                        download = candidate;
                        is_msi   = true;
                        break;
                    }
                    else if (name == "Windows x86-64 executable installer")
                    {
                        download = candidate;
                        is_msi   = false;
                        break;
                    }
                }
                else
                {
                    if (name == "Windows x86 MSI installer")
                    {
                        download = candidate;
                        is_msi   = true;
                        break;
                    }
                    else if (name == "Windows x86 executable installer")
                    {
                        download = candidate;
                        is_msi   = false;
                        break;
                    }
                }
            }
            return(download);
        }
Esempio n. 4
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");
                }
            }
        }