ProjectDjango/Project.py

changeset 27
47709d773da5
parent 26
2dd206cd1aa2
child 29
76d04dd67367
--- a/ProjectDjango/Project.py	Mon Sep 30 22:13:01 2013 +0200
+++ b/ProjectDjango/Project.py	Fri Oct 04 12:06:56 2013 +0200
@@ -17,8 +17,9 @@
 import os
 import re
 
-from PyQt4.QtCore import QObject, QProcess, QTimer, QUrl, QFileInfo
+from PyQt4.QtCore import QObject, QTimer, QUrl, QFileInfo
 from PyQt4.QtGui import QMenu, QInputDialog, QLineEdit, QDesktopServices, QDialog
+from PyQt4.QtCore import QProcess as QProcessPyQt
 
 from E5Gui.E5Application import e5App
 from E5Gui import E5MessageBox, E5FileDialog
@@ -40,6 +41,41 @@
     pass
 
 
+class QProcess(QProcessPyQt):
+    """
+    Class transforming the call arguments in case of gnome-terminal.
+    """
+    def start(self, cmd, args=[], mode=QProcessPyQt.ReadWrite):
+        """
+        Starts the given program (cmd) in a new process, if none is already
+        running, passing the command line arguments in argss.
+        
+        @param cmd start the given program cmd (string)
+        @keyparam args list of parameters (list of strings)
+        @keyparam mode access mode (QIODevice.OpenMode)
+        """
+        if cmd.endswith('gnome-terminal') and args[0] == '-e':
+            args = ['-e', ' '.join(args[1:])]
+        
+        super(QProcess, self).start(cmd, args, mode)
+    
+    @staticmethod
+    def startDetached(cmd, args=[], path=''):
+        """
+        Starts the given program (cmd) in a new process, if none is already
+        running, passing the command line arguments in argss.
+        
+        @param cmd start the given program cmd (string)
+        @keyparam args list of parameters (list of strings)
+        @keyparam path new working directory (string)
+        @return tuple of successful start and process id (boolean, integer)
+        """
+        if cmd.endswith('gnome-terminal') and args[0] == '-e':
+            args = ['-e', ' '.join(args[1:])]
+        
+        return QProcessPyQt.startDetached(cmd, args, path)
+
+
 class Project(QObject):
     """
     Class implementing the Django project support.
@@ -996,7 +1032,7 @@
                     if os.path.exists(cmd):
                         break
                 else:
-                    ""
+                    cmd = ""
         else:
             if isWindowsPlatform():
                 debugEnv = self.__getDebugEnvironment(language)
@@ -1028,7 +1064,7 @@
             elif language == "Python2":
                 pythonExe = "python2"
         virtualEnv = self.__getVirtualEnvironment()
-        if not virtualEnv:
+        if isWindowsPlatform() and not virtualEnv:
             virtualEnv = self.__getDebugEnvironment(language)
         if virtualEnv:
             if isWindowsPlatform():
@@ -1039,6 +1075,8 @@
                 python = os.path.join(virtualEnv, "bin", pythonExe)
                 if not os.path.exists(python):
                     python = python[:-1]    # omit the version character
+        else:
+            python = pythonExe
         
         return python
     
@@ -1073,11 +1111,15 @@
         @return Django version (string)
         """
         if not self.__djangoVersion:
+            args = ['--version']
             ioEncoding = Preferences.getSystem("IOEncoding")
             cmd = self.__getDjangoAdminCommand()
+            if isWindowsPlatform():
+                args.insert(0, cmd)
+                cmd = self.__getPythonExecutable()
             
             process = QProcess()
-            process.start(cmd, ['--version'])
+            process.start(cmd, args)
             procStarted = process.waitForStarted()
             if procStarted:
                 finished = process.waitForFinished(30000)

eric ide

mercurial