private async Task <ConfigurationValues> AutoDetectAsync(ConfigurationValues view)
        {
            if (!Directory.Exists(view.PrefixPath))
            {
                if (File.Exists(view.InterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.InterpreterPath);
                }
                else if (File.Exists(view.WindowsInterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.WindowsInterpreterPath);
                }
                else
                {
                    // Don't have enough information, so abort without changing
                    // any settings.
                    return(view);
                }
                while (Directory.Exists(view.PrefixPath) && !File.Exists(PathUtils.FindFile(view.PrefixPath, "site.py")))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.PrefixPath);
                }
            }

            if (!Directory.Exists(view.PrefixPath))
            {
                // If view.PrefixPath is not valid by this point, we can't find anything
                // else, so abort withou changing any settings.
                return(view);
            }

            if (string.IsNullOrEmpty(view.Description))
            {
                view.Description = PathUtils.GetFileOrDirectoryName(view.PrefixPath);
            }

            if (!File.Exists(view.InterpreterPath))
            {
                view.InterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.ConsoleExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }
            if (!File.Exists(view.WindowsInterpreterPath))
            {
                view.WindowsInterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.WindowsExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }

            if (File.Exists(view.InterpreterPath))
            {
                using (var output = ProcessOutput.RunHiddenAndCapture(
                           view.InterpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
                           )) {
                    var exitCode = await output;
                    if (exitCode == 0)
                    {
                        view.VersionName = output.StandardOutputLines.FirstOrDefault() ?? view.VersionName;
                    }
                }

                var arch = InterpreterArchitecture.FromExe(view.InterpreterPath);
                if (arch != InterpreterArchitecture.Unknown)
                {
                    view.ArchitectureName = arch.ToString();
                }
            }

            return(view);
        }
示例#2
0
        private async Task <ConfigurationValues> AutoDetectAsync(ConfigurationValues view)
        {
            if (!Directory.Exists(view.PrefixPath))
            {
                if (File.Exists(view.InterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.InterpreterPath);
                }
                else if (File.Exists(view.WindowsInterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.WindowsInterpreterPath);
                }
                else if (Directory.Exists(view.LibraryPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.LibraryPath);
                }
                else
                {
                    // Don't have enough information, so abort without changing
                    // any settings.
                    return(view);
                }
                while (Directory.Exists(view.PrefixPath) && !File.Exists(CommonUtils.FindFile(view.PrefixPath, "site.py")))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.PrefixPath);
                }
            }

            if (!Directory.Exists(view.PrefixPath))
            {
                // If view.PrefixPath is not valid by this point, we can't find anything
                // else, so abort withou changing any settings.
                return(view);
            }

            if (!File.Exists(view.InterpreterPath))
            {
                view.InterpreterPath = CommonUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.ConsoleExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }
            if (!File.Exists(view.WindowsInterpreterPath))
            {
                view.WindowsInterpreterPath = CommonUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.WindowsExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }
            if (!Directory.Exists(view.LibraryPath))
            {
                var sitePy = CommonUtils.FindFile(
                    view.PrefixPath,
                    "os.py",
                    firstCheck: new[] { "lib" }
                    );
                if (File.Exists(sitePy))
                {
                    view.LibraryPath = Path.GetDirectoryName(sitePy);
                }
            }

            if (File.Exists(view.InterpreterPath))
            {
                using (var output = ProcessOutput.RunHiddenAndCapture(
                           view.InterpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
                           )) {
                    var exitCode = await output;
                    if (exitCode == 0)
                    {
                        view.VersionName = output.StandardOutputLines.FirstOrDefault() ?? view.VersionName;
                    }
                }

                var binaryType = Microsoft.PythonTools.Interpreter.NativeMethods.GetBinaryType(view.InterpreterPath);
                if (binaryType == ProcessorArchitecture.Amd64)
                {
                    view.ArchitectureName = "64-bit";
                }
                else if (binaryType == ProcessorArchitecture.X86)
                {
                    view.ArchitectureName = "32-bit";
                }
            }

            return(view);
        }
        private async Task<ConfigurationValues> AutoDetectAsync(ConfigurationValues view) {
            if (!Directory.Exists(view.PrefixPath)) {
                if (File.Exists(view.InterpreterPath)) {
                    view.PrefixPath = Path.GetDirectoryName(view.InterpreterPath);
                } else if (File.Exists(view.WindowsInterpreterPath)) {
                    view.PrefixPath = Path.GetDirectoryName(view.WindowsInterpreterPath);
                } else {
                    // Don't have enough information, so abort without changing
                    // any settings.
                    return view;
                }
                while (Directory.Exists(view.PrefixPath) && !File.Exists(PathUtils.FindFile(view.PrefixPath, "site.py"))) {
                    view.PrefixPath = Path.GetDirectoryName(view.PrefixPath);
                }
            }

            if (!Directory.Exists(view.PrefixPath)) {
                // If view.PrefixPath is not valid by this point, we can't find anything
                // else, so abort withou changing any settings.
                return view;
            }

            if (!File.Exists(view.InterpreterPath)) {
                view.InterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.ConsoleExecutable,
                    firstCheck: new[] { "scripts" }
                );
            }
            if (!File.Exists(view.WindowsInterpreterPath)) {
                view.WindowsInterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.WindowsExecutable,
                    firstCheck: new[] { "scripts" }
                );
            }

            if (File.Exists(view.InterpreterPath)) {
                using (var output = ProcessOutput.RunHiddenAndCapture(
                    view.InterpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
                )) {
                    var exitCode = await output;
                    if (exitCode == 0) {
                        view.VersionName = output.StandardOutputLines.FirstOrDefault() ?? view.VersionName;
                    }
                }

                var binaryType = Infrastructure.NativeMethods.GetBinaryType(view.InterpreterPath);
                if (binaryType == ProcessorArchitecture.Amd64) {
                    view.ArchitectureName = "64-bit";
                } else if (binaryType == ProcessorArchitecture.X86) {
                    view.ArchitectureName = "32-bit";
                }
            }

            return view;
        }