Ejemplo n.º 1
0
            private KeyValuePair <string, string> InitializeEnvironment()
            {
                var pythonPathVar = _settings.PathEnv;
                var pythonPath    = _searchPaths;

                if (!string.IsNullOrWhiteSpace(pythonPathVar))
                {
                    if (_app != null)
                    {
                        var settingsManager = SettingsManagerCreator.GetSettingsManager(_dte);
                        if (settingsManager != null)
                        {
                            var store = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);
                            if (store != null && store.CollectionExists(@"PythonTools\Options\General"))
                            {
                                var  settingStr = store.GetString(@"PythonTools\Options\General", "ClearGlobalPythonPath", "True");
                                bool settingBool;
                                if (bool.TryParse(settingStr, out settingBool) && !settingBool)
                                {
                                    pythonPath += ";" + Environment.GetEnvironmentVariable(pythonPathVar);
                                }
                            }
                        }
                    }
                    _env[pythonPathVar] = pythonPath;
                }

                foreach (var envVar in _settings.Environment)
                {
                    _env[envVar.Key] = envVar.Value;
                }
                return(new KeyValuePair <string, string>(pythonPathVar, pythonPath));
            }
Ejemplo n.º 2
0
        public static SettingsManager GetAppSettings(DTE dte)
        {
            //dte = this.package.GetServiceOfType(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;
            SettingsManager sm = SettingsManagerCreator.GetSettingsManager(dte);

            return(sm);
            //string appFolder= sm.GetApplicationDataFolder(ApplicationDataFolder.Configuration);
            //var store = sm.GetWritableSettingsStore(SettingsScope.UserSettings);
        }
Ejemplo n.º 3
0
        public static SettingsManager GetAppSettings(ClouderSyncPackage package)
        {
            var dte = package.GetServiceOfType(typeof(EnvDTE.DTE));

            if (dte is DTE)
            {
                return(SettingsManagerCreator.GetSettingsManager((DTE)dte));
            }
            return(SettingsManagerCreator.GetSettingsManager(package));
        }
Ejemplo n.º 4
0
        private void OfferUpgrade(IServiceProvider provider)
        {
            if (!_recommendUpgrade)
            {
                return;
            }

            var sm    = SettingsManagerCreator.GetSettingsManager(provider);
            var store = sm.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (!store.CollectionExists(PythonConstants.DontShowUpgradeDialogAgainCollection) ||
                !store.GetBoolean(PythonConstants.DontShowUpgradeDialogAgainCollection, DontShowUpgradeDialogAgainProperty, false))
            {
                var dlg = new TaskDialog(provider)
                {
                    Title             = Strings.ProductTitle,
                    MainInstruction   = Strings.AzureToolsUpgradeRecommended,
                    Content           = Strings.AzureToolsUpgradeInstructions,
                    AllowCancellation = true,
                    VerificationText  = Strings.DontShowAgain
                };
                var download = new TaskDialogButton(Strings.DownloadAndInstall);
                dlg.Buttons.Add(download);
                var cont = new TaskDialogButton(Strings.ContinueWithoutAzureToolsUpgrade);
                dlg.Buttons.Add(cont);
                dlg.Buttons.Add(TaskDialogButton.Cancel);

                var response = dlg.ShowModal();

                if (dlg.SelectedVerified)
                {
                    var rwStore = sm.GetWritableSettingsStore(SettingsScope.UserSettings);
                    rwStore.CreateCollection(PythonConstants.DontShowUpgradeDialogAgainCollection);
                    rwStore.SetBoolean(PythonConstants.DontShowUpgradeDialogAgainCollection, DontShowUpgradeDialogAgainProperty, true);
                }

                if (response == download)
                {
                    Process.Start(new ProcessStartInfo(AzureToolsDownload));
                    throw new WizardCancelledException();
                }
                else if (response == TaskDialogButton.Cancel)
                {
                    // User cancelled, so go back to the New Project dialog
                    throw new WizardBackoutException();
                }
            }
        }
Ejemplo n.º 5
0
        public InterpreterOptionsService([Import(typeof(SVsServiceProvider), AllowDefault = true)] IServiceProvider provider)
        {
            _serviceThread = Thread.CurrentThread;
            _settings      = SettingsManagerCreator.GetSettingsManager(provider);
            if (provider != null)
            {
                _activityLog = provider.GetService(typeof(SVsActivityLog)) as IVsActivityLog;
            }
            else if (ServiceProvider.GlobalProvider != null)
            {
                _activityLog = ServiceProvider.GlobalProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog;
            }
            Initialize(provider);

            InitializeDefaultInterpreterWatcher(provider);
        }
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            var provider = WizardHelpers.GetProvider(automationObject);

            if (_wizard == null)
            {
                try {
                    Directory.Delete(replacementsDictionary["$destinationdirectory$"]);
                    Directory.Delete(replacementsDictionary["$solutiondirectory$"]);
                } catch {
                    // If it fails (doesn't exist/contains files/read-only), let the directory stay.
                }

                var dlg = new TaskDialog(provider)
                {
                    Title             = Resources.PythonToolsForVisualStudio,
                    MainInstruction   = Resources.AzureToolsRequired,
                    Content           = Resources.AzureToolsInstallInstructions,
                    AllowCancellation = true
                };
                var download = new TaskDialogButton(Resources.DownloadAndInstall);
                dlg.Buttons.Add(download);
                dlg.Buttons.Add(TaskDialogButton.Cancel);

                if (dlg.ShowModal() == download)
                {
                    Process.Start(new ProcessStartInfo(AzureToolsDownload));
                    throw new WizardCancelledException();
                }

                // User cancelled, so go back to the New Project dialog
                throw new WizardBackoutException();
            }

            if (_recommendUpgrade)
            {
                var sm    = SettingsManagerCreator.GetSettingsManager(provider);
                var store = sm.GetReadOnlySettingsStore(SettingsScope.UserSettings);

                if (!store.CollectionExists(PythonConstants.DontShowUpgradeDialogAgainCollection) ||
                    !store.GetBoolean(PythonConstants.DontShowUpgradeDialogAgainCollection, DontShowUpgradeDialogAgainProperty, false))
                {
                    var dlg = new TaskDialog(provider)
                    {
                        Title             = Resources.PythonToolsForVisualStudio,
                        MainInstruction   = Resources.AzureToolsUpgradeRecommended,
                        Content           = Resources.AzureToolsUpgradeInstructions,
                        AllowCancellation = true,
                        VerificationText  = Resources.DontShowAgain
                    };
                    var download = new TaskDialogButton(Resources.DownloadAndInstall);
                    dlg.Buttons.Add(download);
                    var cont = new TaskDialogButton(Resources.ContinueWithoutAzureToolsUpgrade);
                    dlg.Buttons.Add(cont);
                    dlg.Buttons.Add(TaskDialogButton.Cancel);

                    var response = dlg.ShowModal();

                    if (response != cont)
                    {
                        try {
                            Directory.Delete(replacementsDictionary["$destinationdirectory$"]);
                            Directory.Delete(replacementsDictionary["$solutiondirectory$"]);
                        } catch {
                            // If it fails (doesn't exist/contains files/read-only), let the directory stay.
                        }
                    }

                    if (dlg.SelectedVerified)
                    {
                        var rwStore = sm.GetWritableSettingsStore(SettingsScope.UserSettings);
                        rwStore.CreateCollection(PythonConstants.DontShowUpgradeDialogAgainCollection);
                        rwStore.SetBoolean(PythonConstants.DontShowUpgradeDialogAgainCollection, DontShowUpgradeDialogAgainProperty, true);
                    }

                    if (response == download)
                    {
                        Process.Start(new ProcessStartInfo(AzureToolsDownload));
                        throw new WizardCancelledException();
                    }
                    else if (response == TaskDialogButton.Cancel)
                    {
                        // User cancelled, so go back to the New Project dialog
                        throw new WizardBackoutException();
                    }
                }
            }

            // Run the original wizard to get the right replacements
            _wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
        }
Ejemplo n.º 7
0
        private void RunTestCase(
            IFrameworkHandle frameworkHandle,
            IRunContext runContext,
            TestCase test,
            Dictionary <string, PythonProjectSettings> sourceToSettings
            )
        {
            var testResult = new TestResult(test);

            frameworkHandle.RecordStart(test);
            testResult.StartTime = DateTimeOffset.Now;

            PythonProjectSettings settings;

            if (!sourceToSettings.TryGetValue(test.Source, out settings))
            {
                sourceToSettings[test.Source] = settings = LoadProjectSettings(test.Source);
            }
            if (settings == null)
            {
                frameworkHandle.SendMessage(
                    TestMessageLevel.Error,
                    "Unable to determine interpreter to use for " + test.Source);
                RecordEnd(
                    frameworkHandle,
                    test,
                    testResult,
                    null,
                    "Unable to determine interpreter to use for " + test.Source,
                    TestOutcome.Failed);
                return;
            }

            var debugMode = PythonDebugMode.None;

            if (runContext.IsBeingDebugged && _app != null)
            {
                debugMode = settings.EnableNativeCodeDebugging ? PythonDebugMode.PythonAndNative : PythonDebugMode.PythonOnly;
            }

            var testCase = new PythonTestCase(settings, test, debugMode);

            var dte = _app != null?_app.GetDTE() : null;

            if (dte != null && debugMode != PythonDebugMode.None)
            {
                dte.Debugger.DetachAll();
            }

            if (!File.Exists(settings.Factory.Configuration.InterpreterPath))
            {
                frameworkHandle.SendMessage(TestMessageLevel.Error, "Interpreter path does not exist: " + settings.Factory.Configuration.InterpreterPath);
                return;
            }

            var env           = new Dictionary <string, string>();
            var pythonPathVar = settings.Factory.Configuration.PathEnvironmentVariable;
            var pythonPath    = testCase.SearchPaths;

            if (!string.IsNullOrWhiteSpace(pythonPathVar))
            {
                if (_app != null)
                {
                    var settingsManager = SettingsManagerCreator.GetSettingsManager(dte);
                    if (settingsManager != null)
                    {
                        var store = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);
                        if (store != null && store.CollectionExists(@"PythonTools\Options\General"))
                        {
                            var  settingStr = store.GetString(@"PythonTools\Options\General", "ClearGlobalPythonPath", "True");
                            bool settingBool;
                            if (bool.TryParse(settingStr, out settingBool) && !settingBool)
                            {
                                pythonPath += ";" + Environment.GetEnvironmentVariable(pythonPathVar);
                            }
                        }
                    }
                }
                env[pythonPathVar] = pythonPath;
            }

            foreach (var envVar in testCase.Environment)
            {
                env[envVar.Key] = envVar.Value;
            }

            using (var proc = ProcessOutput.Run(
                       !settings.IsWindowsApplication ?
                       settings.Factory.Configuration.InterpreterPath :
                       settings.Factory.Configuration.WindowsInterpreterPath,
                       testCase.Arguments,
                       testCase.WorkingDirectory,
                       env,
                       false,
                       null
                       )) {
                bool killed = false;

#if DEBUG
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "cd " + testCase.WorkingDirectory);
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "set " + (pythonPathVar ?? "") + "=" + (pythonPath ?? ""));
                frameworkHandle.SendMessage(TestMessageLevel.Informational, proc.Arguments);
#endif

                proc.Wait(TimeSpan.FromMilliseconds(500));
                if (debugMode != PythonDebugMode.None)
                {
                    if (proc.ExitCode.HasValue)
                    {
                        // Process has already exited
                        frameworkHandle.SendMessage(TestMessageLevel.Error, "Failed to attach debugger because the process has already exited.");
                        if (proc.StandardErrorLines.Any())
                        {
                            frameworkHandle.SendMessage(TestMessageLevel.Error, "Standard error from Python:");
                            foreach (var line in proc.StandardErrorLines)
                            {
                                frameworkHandle.SendMessage(TestMessageLevel.Error, line);
                            }
                        }
                    }

                    try {
                        if (debugMode == PythonDebugMode.PythonOnly)
                        {
                            string qualifierUri = string.Format("tcp://{0}@localhost:{1}", testCase.DebugSecret, testCase.DebugPort);
                            while (!_app.AttachToProcess(proc, PythonRemoteDebugPortSupplierUnsecuredId, qualifierUri))
                            {
                                if (proc.Wait(TimeSpan.FromMilliseconds(500)))
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            var engines = new[] { PythonDebugEngineGuid, VSConstants.DebugEnginesGuids.NativeOnly_guid };
                            while (!_app.AttachToProcess(proc, engines))
                            {
                                if (proc.Wait(TimeSpan.FromMilliseconds(500)))
                                {
                                    break;
                                }
                            }
                        }

#if DEBUG
                    } catch (COMException ex) {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, "Error occurred connecting to debuggee.");
                        frameworkHandle.SendMessage(TestMessageLevel.Error, ex.ToString());
                        try {
                            proc.Kill();
                        } catch (InvalidOperationException) {
                            // Process has already exited
                        }
                        killed = true;
                    }
#else
                    } catch (COMException) {
 internal static SettingsManager GetSettings(System.IServiceProvider serviceProvider)
 {
     return(SettingsManagerCreator.GetSettingsManager(serviceProvider));
 }
Ejemplo n.º 9
0
        private PythonToolsOptionsService(IServiceProvider serviceProvider)
        {
            var settingsManager = SettingsManagerCreator.GetSettingsManager(serviceProvider);

            _settingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
        }
 private ConfigurablePythonInterpreterFactoryProvider([Import(typeof(SVsServiceProvider), AllowDefault = true)] IServiceProvider provider)
 {
     _settings = SettingsManagerCreator.GetSettingsManager(provider);
     DiscoverInterpreterFactories();
 }