Exemplo n.º 1
0
 public void OnOperationStarted(ICondaEnvironmentManager sender, string operation)
 {
     _window.ShowAndActivate();
 }
Exemplo n.º 2
0
Arquivo: Conda.cs Projeto: tk811/PTVS
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service,
            string package,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            var condaFactory = await TryGetCondaFactoryAsync(factory, service);;

            if (condaFactory == null)
            {
                throw new InvalidOperationException("Cannot find conda");
            }
            condaFactory.ThrowIfNotRunnable();

            if (output != null)
            {
                output.WriteLine(Strings.PackageInstalling.FormatUI(package));
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                {
                    output.ShowAndActivate();
                }
                else
                {
                    output.Show();
                }
            }

            using (var proc = ProcessOutput.Run(
                       condaFactory.Configuration.InterpreterPath,
                       new[] { "-m", "conda", "install", "--yes", "-n", factory.Configuration.PrefixPath, package },
                       factory.Configuration.PrefixPath,
                       UnbufferedEnv,
                       false,
                       output
                       )) {
                var exitCode = await proc;
                if (output != null)
                {
                    if (exitCode == 0)
                    {
                        output.WriteLine(Strings.PackageInstallSucceeded.FormatUI(package));
                    }
                    else
                    {
                        output.WriteLine(Strings.PackageInstallFailedExitCode.FormatUI(package, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                    {
                        output.ShowAndActivate();
                    }
                    else
                    {
                        output.Show();
                    }
                }
                return(exitCode == 0);
            }
        }
Exemplo n.º 3
0
        private static async Task ContinueCreate(IServiceProvider provider, IPythonInterpreterFactory factory, string path, bool useVEnv, Redirector output)
        {
            path = PathUtils.TrimEndSeparator(path);
            var name = Path.GetFileName(path);
            var dir  = Path.GetDirectoryName(path);

            if (output != null)
            {
                output.WriteLine(Strings.VirtualEnvCreating.FormatUI(path));
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForVirtualEnvCreate)
                {
                    output.ShowAndActivate();
                }
                else
                {
                    output.Show();
                }
            }

            var workspaceFactoryProvider = provider.GetComponentModel().GetService <WorkspaceInterpreterFactoryProvider>();

            using (workspaceFactoryProvider?.SuppressDiscoverFactories(forceDiscoveryOnDispose: true)) {
                // Ensure the target directory exists.
                Directory.CreateDirectory(dir);

                using (var proc = ProcessOutput.Run(
                           factory.Configuration.InterpreterPath,
                           new[] { "-m", useVEnv ? "venv" : "virtualenv", name },
                           dir,
                           UnbufferedEnv,
                           false,
                           output
                           )) {
                    var exitCode = await proc;

                    if (output != null)
                    {
                        if (exitCode == 0)
                        {
                            output.WriteLine(Strings.VirtualEnvCreationSucceeded.FormatUI(path));
                        }
                        else
                        {
                            output.WriteLine(Strings.VirtualEnvCreationFailedExitCode.FormatUI(path, exitCode));
                        }
                        if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForVirtualEnvCreate)
                        {
                            output.ShowAndActivate();
                        }
                        else
                        {
                            output.Show();
                        }
                    }

                    if (exitCode != 0 || !Directory.Exists(path))
                    {
                        throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            IServiceProvider site,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            if (!(await factory.FindModulesAsync("pip")).Any())
            {
                if (site != null)
                {
                    try {
                        await QueryInstallPip(factory, site, SR.GetString(SR.InstallPip), elevate, output);
                    } catch (OperationCanceledException) {
                        return(false);
                    }
                }
                else
                {
                    await InstallPip(provider, factory, elevate, output);
                }
            }

            if (output != null)
            {
                output.WriteLine(SR.GetString(SR.PackageInstalling, package));
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                {
                    output.ShowAndActivate();
                }
                else
                {
                    output.Show();
                }
            }

            using (var proc = Run(factory, output, elevate, "install", GetInsecureArg(factory, output), package)) {
                var exitCode = await proc;

                if (output != null)
                {
                    if (exitCode == 0)
                    {
                        output.WriteLine(SR.GetString(SR.PackageInstallSucceeded, package));
                    }
                    else
                    {
                        output.WriteLine(SR.GetString(SR.PackageInstallFailedExitCode, package, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                    {
                        output.ShowAndActivate();
                    }
                    else
                    {
                        output.Show();
                    }
                }
                return(exitCode == 0);
            }
        }
Exemplo n.º 5
0
        public Task DeleteTemplateAsync(TemplateViewModel template) {
            try {
                string remote = template.RemoteUrl;

                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.DeletingTemplateStarted, template.ClonedPath));

                ShellUtils.DeleteDirectory(template.ClonedPath);

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.DeletingTemplateSuccess, template.ClonedPath));
                _outputWindow.ShowAndActivate();

                if (!string.IsNullOrEmpty(remote)) {
                    var t = Installed.Templates.SingleOrDefault(current => (current as TemplateViewModel)?.RemoteUrl == remote) as TemplateViewModel;
                    if (t != null) {
                        Installed.Templates.Remove(t);
                    }

                    t = Recommended.Templates.SingleOrDefault(current => (current as TemplateViewModel)?.RemoteUrl == remote) as TemplateViewModel;
                    if (t != null) {
                        t.ClonedPath = string.Empty;
                    }

                    t = GitHub.Templates.SingleOrDefault(current => (current as TemplateViewModel)?.RemoteUrl == remote) as TemplateViewModel;
                    if (t != null) {
                        t.ClonedPath = string.Empty;
                    }
                } else {
                    if (Installed.Templates.Contains(template)) {
                        Installed.Templates.Remove(template);
                    }
                }
            } catch (Exception ex) when (!ex.IsCriticalException()) {
                _outputWindow.WriteErrorLine(ex.Message);

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.DeletingTemplateFailed, template.ClonedPath));
                _outputWindow.ShowAndActivate();
            }

            return Task.CompletedTask;
        }