public async Task <bool> ExecuteAsync(string arguments, IPackageManagerUI ui, CancellationToken cancellationToken) { AbortOnInvalidConfiguration(); await AbortIfNotReady(cancellationToken); using (await _working.LockAsync(cancellationToken)) { bool success = false; string args; if (!SupportsDashMPip) { args = "-c \"import pip; pip.main()\" "; } else { args = "-m pip "; } args += arguments; var operation = args; ui?.OnOutputTextReceived(operation); ui?.OnOperationStarted(Strings.ExecutingCommandStarted.FormatUI(arguments)); try { using (var output = ProcessOutput.Run( _factory.Configuration.InterpreterPath, new[] { args }, _factory.Configuration.PrefixPath, UnbufferedEnv, false, PackageManagerUIRedirector.Get(ui), quoteArgs: false, elevate: await ShouldElevate(ui, operation) )) { if (!output.IsStarted) { return(false); } var exitCode = await output; success = exitCode == 0; } return(success); } catch (IOException) { return(false); } finally { if (!success) { // Check whether we failed because pip is missing UpdateIsReadyAsync(true, CancellationToken.None).DoNotWait(); } var msg = success ? Strings.ExecutingCommandSucceeded : Strings.ExecutingCommandFailed; ui?.OnOutputTextReceived(msg.FormatUI(arguments)); ui?.OnOperationFinished(operation, success); await CacheInstalledPackagesAsync(true, cancellationToken); } } }
public async Task <bool> InstallAsync(PackageSpec package, IPackageManagerUI ui, CancellationToken cancellationToken) { AbortOnInvalidConfiguration(); await AbortIfNotReady(cancellationToken); bool success = false; var args = new List <string>(); args.Add("install"); args.Add("-p"); args.Add(ProcessOutput.QuoteSingleArgument(_factory.Configuration.GetPrefixPath())); args.Add("-y"); args.Add(package.FullSpec); var name = string.IsNullOrEmpty(package.Name) ? package.FullSpec : package.Name; var operation = string.Join(" ", args); using (await _working.LockAsync(cancellationToken)) { ui?.OnOperationStarted(this, operation); ui?.OnOutputTextReceived(this, Strings.InstallingPackageStarted.FormatUI(name)); var envVars = await GetEnvironmentVariables(); try { using (var output = ProcessOutput.Run( _condaPath, args, _factory.Configuration.GetPrefixPath(), envVars, false, PackageManagerUIRedirector.Get(this, ui), quoteArgs: false, elevate: await ShouldElevate(ui, operation) )) { if (!output.IsStarted) { return(false); } var exitCode = await output; success = exitCode == 0; } return(success); } catch (IOException) { return(false); } finally { if (!success) { // Check whether we failed because conda is missing UpdateIsReadyAsync(true, CancellationToken.None).DoNotWait(); } var msg = success ? Strings.InstallingPackageSuccess : Strings.InstallingPackageFailed; ui?.OnOutputTextReceived(this, msg.FormatUI(name)); ui?.OnOperationFinished(this, operation, success); await CacheInstalledPackagesAsync(true, false, cancellationToken); } } }
public async Task <bool> InstallAsync(PackageSpec package, IPackageManagerUI ui, CancellationToken cancellationToken) { ui?.OnOperationStarted(this, "install " + package.FullSpec); _installed.Add(package); await Task.Delay(100, cancellationToken); _seenChange = true; ui?.OnOperationFinished(this, "install " + package.FullSpec, true); return(true); }
public async Task <bool> ExecuteAsync(string arguments, IPackageManagerUI ui, CancellationToken cancellationToken) { AbortOnInvalidConfiguration(); await AbortIfNotReady(cancellationToken); using (await _working.LockAsync(cancellationToken)) { bool success = false; var args = string.Join(" ", _commands.Base().Select(ProcessOutput.QuoteSingleArgument)) + " " + arguments; var operation = args.Trim(); ui?.OnOutputTextReceived(this, operation); ui?.OnOperationStarted(this, Strings.ExecutingCommandStarted.FormatUI(arguments)); var envVars = await GetEnvironmentVariables(); try { using (var output = ProcessOutput.Run( _factory.Configuration.InterpreterPath, new[] { args.Trim() }, _factory.Configuration.GetPrefixPath(), envVars, false, PackageManagerUIRedirector.Get(this, ui), quoteArgs: false, elevate: await ShouldElevate(ui, operation) )) { if (!output.IsStarted) { return(false); } var exitCode = await output; success = exitCode == 0; } return(success); } catch (IOException) { return(false); } finally { if (!success) { // Check whether we failed because pip is missing UpdateIsReadyAsync(true, CancellationToken.None).DoNotWait(); } var msg = success ? Strings.ExecutingCommandSucceeded : Strings.ExecutingCommandFailed; ui?.OnOutputTextReceived(this, msg.FormatUI(arguments)); ui?.OnOperationFinished(this, operation, success); await CacheInstalledPackagesAsync(true, false, cancellationToken); } } }
public async Task <bool> InstallAsync(PackageSpec package, IPackageManagerUI ui, CancellationToken cancellationToken) { AbortOnInvalidConfiguration(); await AbortIfNotReady(cancellationToken); bool success = false; var args = _commands.Install(package.FullSpec).ToArray(); var operation = string.Join(" ", args); var name = string.IsNullOrEmpty(package.Name) ? package.FullSpec : package.Name; using (await _working.LockAsync(cancellationToken)) { ui?.OnOperationStarted(this, operation); ui?.OnOutputTextReceived(this, Strings.InstallingPackageStarted.FormatUI(name)); try { using (var output = ProcessOutput.Run( _factory.Configuration.InterpreterPath, args, _factory.Configuration.PrefixPath, UnbufferedEnv, false, PackageManagerUIRedirector.Get(this, ui), quoteArgs: false, elevate: await ShouldElevate(ui, operation) )) { if (!output.IsStarted) { return(false); } var exitCode = await output; success = exitCode == 0; } return(success); } catch (IOException) { return(false); } finally { if (!success) { // Check whether we failed because pip is missing UpdateIsReadyAsync(true, CancellationToken.None).DoNotWait(); } var msg = success ? Strings.InstallingPackageSuccess : Strings.InstallingPackageFailed; ui?.OnOutputTextReceived(this, msg.FormatUI(name)); ui?.OnOperationFinished(this, operation, success); await CacheInstalledPackagesAsync(true, false, cancellationToken); } } }
public async Task PrepareAsync(IPackageManagerUI ui, CancellationToken cancellationToken) { if (IsReady) { return; } AbortOnInvalidConfiguration(); await UpdateIsReadyAsync(false, cancellationToken); if (IsReady) { return; } var operation = "pip_downloader.py"; var args = _extraInterpreterArgs .Concat(new[] { PythonToolsInstallPath.GetFile("pip_downloader.py", GetType().Assembly) }); using (await _working.LockAsync(cancellationToken)) { ui?.OnOperationStarted(this, operation); ui?.OnOutputTextReceived(this, Strings.InstallingPipStarted); using (var proc = ProcessOutput.Run( _factory.Configuration.InterpreterPath, args, _factory.Configuration.PrefixPath, UnbufferedEnv, false, PackageManagerUIRedirector.Get(this, ui), elevate: await ShouldElevate(ui, operation) )) { try { IsReady = (await proc == 0); } catch (OperationCanceledException) { IsReady = false; } } ui?.OnOutputTextReceived(this, IsReady ? Strings.InstallingPipSuccess : Strings.InstallingPackageFailed); ui?.OnOperationFinished(this, operation, IsReady); } }
public async Task PrepareAsync(IPackageManagerUI ui, CancellationToken cancellationToken) { if (IsReady) { return; } AbortOnInvalidConfiguration(); await UpdateIsReadyAsync(false, cancellationToken); if (IsReady) { return; } var operation = "pip_downloader.py"; using (await _working.LockAsync(cancellationToken)) { ui?.OnOperationStarted(this, operation); ui?.OnOutputTextReceived(this, Strings.InstallingPipStarted); var envVars = await GetEnvironmentVariables(); using (var proc = ProcessOutput.Run( _factory.Configuration.InterpreterPath, _commands.Prepare(), _factory.Configuration.GetPrefixPath(), envVars, false, PackageManagerUIRedirector.Get(this, ui), elevate: await ShouldElevate(ui, operation) )) { try { IsReady = (await proc == 0); } catch (OperationCanceledException) { IsReady = false; } } ui?.OnOutputTextReceived(this, IsReady ? Strings.InstallingPipSuccess : Strings.InstallingPackageFailed); ui?.OnOperationFinished(this, operation, IsReady); } }
public async Task <bool> UninstallAsync(PackageSpec package, IPackageManagerUI ui, CancellationToken cancellationToken) { AbortOnInvalidConfiguration(); await AbortIfNotReady(cancellationToken); bool success = false; var args = _extraInterpreterArgs.ToList(); if (!SupportsDashMPip) { args.Add("-c"); args.Add("\"import pip; pip.main()\""); } else { args.Add("-m"); args.Add("pip"); } args.Add("uninstall"); args.Add("-y"); args.Add(package.FullSpec); var name = string.IsNullOrEmpty(package.Name) ? package.FullSpec : package.Name; var operation = string.Join(" ", args); try { using (await _working.LockAsync(cancellationToken)) { ui?.OnOperationStarted(this, operation); ui?.OnOutputTextReceived(this, Strings.UninstallingPackageStarted.FormatUI(name)); using (var output = ProcessOutput.Run( _factory.Configuration.InterpreterPath, args, _factory.Configuration.PrefixPath, UnbufferedEnv, false, PackageManagerUIRedirector.Get(this, ui), elevate: await ShouldElevate(ui, operation) )) { if (!output.IsStarted) { // The finally block handles output return(false); } var exitCode = await output; success = exitCode == 0; } return(success); } } catch (IOException) { return(false); } finally { if (!success) { // Check whether we failed because pip is missing UpdateIsReadyAsync(false, CancellationToken.None).DoNotWait(); } if (IsReady) { await CacheInstalledPackagesAsync(false, false, cancellationToken); if (!success) { // Double check whether the package has actually // been uninstalled, to avoid reporting errors // where, for all practical purposes, there is no // error. if (!(await GetInstalledPackageAsync(package, cancellationToken)).IsValid) { success = true; } } } var msg = success ? Strings.UninstallingPackageSuccess : Strings.UninstallingPackageFailed; ui?.OnOutputTextReceived(this, msg.FormatUI(name)); ui?.OnOperationFinished(this, operation, success); } }