--- a/ProjectDjango/Project.py Sat Sep 28 13:28:03 2013 +0200 +++ b/ProjectDjango/Project.py Mon Sep 30 22:13:01 2013 +0200 @@ -7,6 +7,12 @@ Module implementing the Django project support. """ +from __future__ import unicode_literals # __IGNORE_WARNING__ +try: + str = unicode # __IGNORE_WARNING__ +except (NameError): + pass + import sys import os import re @@ -47,7 +53,7 @@ @param plugin reference to the plugin object @param parent parent (QObject) """ - super().__init__(parent) + super(Project, self).__init__(parent) self.__plugin = plugin self.__ui = parent @@ -900,7 +906,7 @@ if self.__getDjangoAdminCommand(variant): variants.append(variant) else: - cmd = self.__getDjangoAdminCommand() + cmd = self.__getDjangoAdminCommand(variant) if isWindowsPlatform(): if variant.lower() in cmd.lower(): variants.append(variant) @@ -945,7 +951,28 @@ if virtEnv and not os.path.exists(virtEnv): virtEnv = "" return virtEnv - + + def __getDebugEnvironment(self, language=""): + """ + Private method to get the path of the debugger environment. + + @param language Python variant to get the debugger environment + for (string, one of '', 'Python2' or 'Python3') + @return path of the debugger environment (string) + """ + if not language: + language = self.__e5project.getProjectLanguage() + if language == "Python3": + debugEnv = Preferences.getDebugger("Python3Interpreter") + elif language == "Python2": + debugEnv = Preferences.getDebugger("PythonInterpreter") + else: + debugEnv = sys.executable + debugEnv = os.path.dirname(debugEnv) + if debugEnv and not os.path.exists(debugEnv): + debugEnv = sys.exec_prefix + return debugEnv + def __getDjangoAdminCommand(self, language=""): """ Private method to build a django-admin.py command. @@ -972,7 +999,8 @@ "" else: if isWindowsPlatform(): - cmd = os.path.join(sys.exec_prefix, "Scripts", "django-admin.py") + debugEnv = self.__getDebugEnvironment(language) + cmd = os.path.join(debugEnv, "Scripts", "django-admin.py") else: if Utilities.isinpath("django-admin.py"): cmd = "django-admin.py" @@ -990,23 +1018,25 @@ @return python command (string) """ - python = "python" + language = self.__e5project.getProjectLanguage() + pythonExe = "python" if isWindowsPlatform(): - python += ".exe" + pythonExe += ".exe" else: - language = self.__e5project.getProjectLanguage() if language == "Python3": - python = "python3" + pythonExe = "python3" elif language == "Python2": - python = "python2" + pythonExe = "python2" virtualEnv = self.__getVirtualEnvironment() + if not virtualEnv: + virtualEnv = self.__getDebugEnvironment(language) if virtualEnv: if isWindowsPlatform(): - python = os.path.join(virtualEnv, "Scripts", python) + python = os.path.join(virtualEnv, "Scripts", pythonExe) if not os.path.exists(python): - python = os.path.join(virtualEnv, python) + python = os.path.join(virtualEnv, pythonExe) else: - python = os.path.join(virtualEnv, "bin", python) + python = os.path.join(virtualEnv, "bin", pythonExe) if not os.path.exists(python): python = python[:-1] # omit the version character