public async Task <bool> ExecuteAsync(string arguments, IPackageManagerUI ui, CancellationToken cancellationToken) { AbortOnInvalidConfiguration(); await AbortIfNotReady(cancellationToken); return(false); }
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 static Redirector Get(IPackageManager sender, IPackageManagerUI ui) { if (ui != null) { return(new PackageManagerUIRedirector(sender, ui)); } return(null); }
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> 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; } }
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); } }
private async Task <bool> ShouldElevate(IPackageManagerUI ui, string operation) { // Check with the UI first, as it takes into account global elevation options var elevate = ui == null ? false : await ui.ShouldElevateAsync(this, operation); if (!elevate) { // Package manager UI thinks we don't need to elevate, but we may have to. // Apply the same logic as conda.gateways.disk.test.prefix_is_writable() // Check for errors when opening in append mode for first file that matches: // - ./conda-meta/history // - ./conda-meta/conda*.json // - ./conda-meta/*.json // - ./python.exe try { var metaPath = Path.Combine(_factory.Configuration.PrefixPath, "conda-meta"); var filePath = Directory.EnumerateFiles(metaPath, "history") .Union(Directory.EnumerateFiles(metaPath, "conda*.json")) .Union(Directory.EnumerateFiles(metaPath, "*.json")) .Union(Directory.EnumerateFiles(_factory.Configuration.PrefixPath, "python.exe")) .FirstOrDefault(); if (filePath != null) { using (new FileStream(filePath, FileMode.Append)) { } } } catch (ArgumentException) { } catch (IOException) { } catch (NotSupportedException) { } catch (SecurityException) { } catch (UnauthorizedAccessException) { elevate = true; } } return(elevate); }
public Task PrepareAsync(IPackageManagerUI ui, CancellationToken cancellationToken) { throw new NotImplementedException(); }
private PackageManagerUIRedirector(IPackageManager sender, IPackageManagerUI ui) { _sender = sender; _ui = ui; }
public Task <bool> UninstallAsync(PackageSpec package, IPackageManagerUI ui, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public Task <bool> ExecuteAsync(string arguments, IPackageManagerUI ui, CancellationToken cancellationToken) { throw new NotSupportedException(); }
public static Redirector Get(IPackageManager sender, IPackageManagerUI ui) { if (ui != null) { return new PackageManagerUIRedirector(sender, ui); } return null; }
public Task<bool> UninstallAsync(PackageSpec package, IPackageManagerUI ui, CancellationToken cancellationToken) { throw new NotSupportedException(); }
public Task PrepareAsync(IPackageManagerUI ui, CancellationToken cancellationToken) { return Task.FromResult<object>(null); }
private Task<bool> ShouldElevate(IPackageManagerUI ui, string operation) { return ui == null ? Task.FromResult(false) : ui.ShouldElevateAsync(this, operation); }
public Task <bool> InstallAsync(PackageSpec package, IPackageManagerUI ui, CancellationToken cancellationToken) { throw new NotSupportedException(); }
public Task PrepareAsync(IPackageManagerUI ui, CancellationToken cancellationToken) { return(Task.FromResult <object>(null)); }
public Task<bool> ExecuteAsync(string arguments, IPackageManagerUI ui, CancellationToken cancellationToken) { throw new NotSupportedException(); }
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 = _extraInterpreterArgs.ToList(); if (!SupportsDashMPip) { args.Add("-c"); args.Add("\"import pip; pip.main()\""); } else { args.Add("-m"); args.Add("pip"); } string argStr = (string.Join(" ", args.Select(ProcessOutput.QuoteSingleArgument)) + " " + arguments).Trim(); var operation = argStr; ui?.OnOutputTextReceived(this, operation); ui?.OnOperationStarted(this, Strings.ExecutingCommandStarted.FormatUI(arguments)); try { using (var output = ProcessOutput.Run( _factory.Configuration.InterpreterPath, new[] { argStr }, _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.ExecutingCommandSucceeded : Strings.ExecutingCommandFailed; ui?.OnOutputTextReceived(this, msg.FormatUI(arguments)); ui?.OnOperationFinished(this, operation, success); await CacheInstalledPackagesAsync(true, false, cancellationToken); } } }
private Task <bool> ShouldElevate(IPackageManagerUI ui, string operation) { return(ui == null?Task.FromResult(false) : ui.ShouldElevateAsync(this, operation)); }
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.InstallingPackageStarted.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); } }
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); } }
private PackageManagerUIRedirector(IPackageManagerUI ui) { _ui = ui; }