Exemple #1
0
        private async Task <bool> ExportAsync(string envPath, string destinationSpecFilePath, string[] args, ICondaEnvironmentManagerUI ui, CancellationToken ct)
        {
            bool success = false;

            using (await _working.LockAsync(ct)) {
                await EnsureActivatedAsync();

                var operation = "conda " + string.Join(" ", args);

                ui?.OnOperationStarted(this, operation);
                ui?.OnOutputTextReceived(this, Strings.CondaExportStarted.FormatUI(envPath));
                try {
                    if (!PathUtils.IsValidPath(envPath))
                    {
                        ui?.OnErrorTextReceived(this, Strings.CondaFolderNotFoundError.FormatUI(envPath));
                        success = false;
                        return(success);
                    }

                    var entries    = new List <string>();
                    var capture    = new ListRedirector(entries);
                    var redirector = new TeeRedirector(CondaEnvironmentManagerUIRedirector.Get(this, ui), capture);

                    success = await DoOperationAsync(args, ui, ct, redirector);

                    if (success)
                    {
                        try {
                            using (var writer = new StreamWriter(destinationSpecFilePath, false, Encoding.UTF8)) {
                                foreach (var line in entries)
                                {
                                    await writer.WriteLineAsync(line);
                                }
                            }
                        } catch (IOException ex) {
                            ui?.OnErrorTextReceived(this, ex.Message);
                            success = false;
                        } catch (UnauthorizedAccessException ex) {
                            ui?.OnErrorTextReceived(this, ex.Message);
                            success = false;
                        } catch (ArgumentException ex) {
                            ui?.OnErrorTextReceived(this, ex.Message);
                            success = false;
                        }
                    }

                    return(success);
                } finally {
                    var msg = success ? Strings.CondaExportSuccess : Strings.CondaExportFailed;
                    ui?.OnOutputTextReceived(this, msg.FormatUI(envPath));
                    ui?.OnOperationFinished(this, operation, success);
                }
            }
        }
Exemple #2
0
        private static async Task <ProcessOutputResult> RunPythonScript(Redirector redirector, string interpreterPath, string script, string parameters)
        {
            var outputLines = new List <string>();
            var errorLines  = new List <string>();

            ProcessOutput output          = null;
            var           arguments       = "\"{0}\" {1}".FormatInvariant(script, parameters);
            var           listRedirector  = new ListRedirector(outputLines, errorLines);
            var           outerRedirector = new TeeRedirector(redirector, listRedirector);

            output = ProcessOutput.Run(interpreterPath, new string[] { arguments }, null, null, false, outerRedirector);

            var result = await WaitForOutput(interpreterPath, output);

            result.StandardOutputLines = outputLines.ToArray();
            result.StandardErrorLines  = errorLines.ToArray();

            return(result);
        }
Exemple #3
0
        private async void RunInOutput(IPythonProject project, CommandStartInfo startInfo)
        {
            Redirector redirector = OutputWindowRedirector.GetGeneral(project.Site);

            if (startInfo.ErrorRegex != null || startInfo.WarningRegex != null)
            {
                redirector = new TeeRedirector(redirector, new ErrorListRedirector(_project.Site, project as IVsHierarchy, startInfo.WorkingDirectory, _errorListProvider, startInfo.ErrorRegex, startInfo.WarningRegex));
            }
            redirector.ShowAndActivate();

            using (var process = ProcessOutput.Run(
                       startInfo.Filename,
                       new[] { startInfo.Arguments },
                       startInfo.WorkingDirectory,
                       startInfo.EnvironmentVariables,
                       false,
                       redirector,
                       quoteArgs: false
                       )) {
                await process;
            }
        }
Exemple #4
0
        public async Task <string> CloneAsync(string repoUrl, string targetParentFolderPath)
        {
            Directory.CreateDirectory(targetParentFolderPath);

            string localTemplateFolder = GetClonedFolder(repoUrl, targetParentFolderPath);

            if (Directory.Exists(localTemplateFolder))
            {
                ShellUtils.DeleteDirectory(localTemplateFolder);
            }

            // Ensure we always capture the output, because we need to check for errors in stderr
            var stdOut = new List <string>();
            var stdErr = new List <string>();

            Redirector redirector;

            if (_redirector != null)
            {
                redirector = new TeeRedirector(_redirector, new ListRedirector(stdOut, stdErr));
            }
            else
            {
                redirector = new ListRedirector(stdOut, stdErr);
            }

            var arguments = new string[] { "clone", repoUrl };

            using (var output = ProcessOutput.Run(_gitExeFilePath, arguments, targetParentFolderPath, GetEnvironment(), false, redirector)) {
                await output;

                var r = new ProcessOutputResult()
                {
                    ExeFileName         = _gitExeFilePath,
                    ExitCode            = output.ExitCode,
                    StandardOutputLines = stdOut.ToArray(),
                    StandardErrorLines  = stdErr.ToArray(),
                };

                if (output.ExitCode < 0 || HasFatalError(stdErr))
                {
                    if (Directory.Exists(localTemplateFolder))
                    {
                        // Don't leave a failed clone on disk
                        try {
                            ShellUtils.DeleteDirectory(localTemplateFolder);
                        } catch (Exception ex) when(!ex.IsCriticalException())
                        {
                        }
                    }

                    throw new ProcessException(r);
                }

                if (!Directory.Exists(localTemplateFolder))
                {
                    throw new ProcessException(r);
                }

                return(localTemplateFolder);
            }
        }
Exemple #5
0
        private async void RunInOutput(IPythonProject2 project, CommandStartInfo startInfo) {
            Redirector redirector = OutputWindowRedirector.GetGeneral(project.Site);
            if (startInfo.ErrorRegex != null || startInfo.WarningRegex != null) {
                redirector = new TeeRedirector(redirector, new ErrorListRedirector(_project.Site, project as IVsHierarchy, startInfo.WorkingDirectory, _errorListProvider, startInfo.ErrorRegex, startInfo.WarningRegex));
            }
            redirector.ShowAndActivate();

            using (var process = ProcessOutput.Run(
                startInfo.Filename,
                new[] { startInfo.Arguments },
                startInfo.WorkingDirectory,
                startInfo.EnvironmentVariables,
                false,
                redirector,
                quoteArgs: false
            )) {
                await process;
            }
        }