Esempio n. 1
0
        private static IEnumerable <string> EnumerateAllFiles(
            string source,
            string filters,
            List <string> virtualEnvPaths
            )
        {
            var files    = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var patterns = filters.Split(';').Concat(new[] { "*.py" }).Select(p => p.Trim()).ToArray();

            var directories = new List <string>()
            {
                source
            };
            var skipDirectories = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            try {
                directories.AddRange(Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories));
            } catch (UnauthorizedAccessException) {
            }

            foreach (var dir in directories)
            {
                if (UnwindDirectory(dir).Any(skipDirectories.Contains))
                {
                    continue;
                }

                try {
                    if (virtualEnvPaths != null)
                    {
                        var origPrefix = DerivedInterpreterFactory.GetOrigPrefixPath(dir);
                        if (!string.IsNullOrEmpty(origPrefix))
                        {
                            virtualEnvPaths.Add(dir);
                            skipDirectories.Add(PathUtils.TrimEndSeparator(dir));
                            continue;
                        }
                    }

                    foreach (var filter in patterns)
                    {
                        files.UnionWith(Directory.EnumerateFiles(dir, filter));
                    }
                } catch (UnauthorizedAccessException) {
                }
            }

            return(files
                   .Where(path => path.StartsWith(source))
                   .Select(path => path.Substring(source.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
                   .Distinct(StringComparer.OrdinalIgnoreCase));
        }
Esempio n. 2
0
        public static async Task ShowDialog(
            PythonProjectNode project,
            IInterpreterOptionsService service,
            bool browseForExisting = false
            )
        {
            using (var view = new AddVirtualEnvironmentView(project, service, project.Interpreters.ActiveInterpreter)) {
                var wnd = new AddVirtualEnvironment(view);

                if (browseForExisting)
                {
                    var path = project.Site.BrowseForDirectory(IntPtr.Zero, project.ProjectHome);
                    if (string.IsNullOrEmpty(path))
                    {
                        throw new OperationCanceledException();
                    }
                    view.VirtualEnvName             = path;
                    view.WillInstallRequirementsTxt = false;
                    await view.WaitForReady();

                    if (view.WillAddVirtualEnv)
                    {
                        await view.Create();

                        return;
                    }

                    view.ShowBrowsePathError = true;
                    view.BrowseOrigPrefix    = DerivedInterpreterFactory.GetOrigPrefixPath(path);
                }

                wnd.VirtualEnvPathTextBox.ScrollToEnd();
                wnd.VirtualEnvPathTextBox.SelectAll();
                wnd.VirtualEnvPathTextBox.Focus();

                wnd.ShowModal();
                var op = wnd._currentOperation;
                if (op != null)
                {
                    await op;
                }
            }
        }