ProjectDjango/Project.py

changeset 27
47709d773da5
parent 26
2dd206cd1aa2
child 29
76d04dd67367
equal deleted inserted replaced
26:2dd206cd1aa2 27:47709d773da5
15 15
16 import sys 16 import sys
17 import os 17 import os
18 import re 18 import re
19 19
20 from PyQt4.QtCore import QObject, QProcess, QTimer, QUrl, QFileInfo 20 from PyQt4.QtCore import QObject, QTimer, QUrl, QFileInfo
21 from PyQt4.QtGui import QMenu, QInputDialog, QLineEdit, QDesktopServices, QDialog 21 from PyQt4.QtGui import QMenu, QInputDialog, QLineEdit, QDesktopServices, QDialog
22 from PyQt4.QtCore import QProcess as QProcessPyQt
22 23
23 from E5Gui.E5Application import e5App 24 from E5Gui.E5Application import e5App
24 from E5Gui import E5MessageBox, E5FileDialog 25 from E5Gui import E5MessageBox, E5FileDialog
25 from E5Gui.E5Action import E5Action 26 from E5Gui.E5Action import E5Action
26 27
36 class DjangoNoSiteSelectedException(Exception): 37 class DjangoNoSiteSelectedException(Exception):
37 """ 38 """
38 Exception thrown to signal, that there is no current site. 39 Exception thrown to signal, that there is no current site.
39 """ 40 """
40 pass 41 pass
42
43
44 class QProcess(QProcessPyQt):
45 """
46 Class transforming the call arguments in case of gnome-terminal.
47 """
48 def start(self, cmd, args=[], mode=QProcessPyQt.ReadWrite):
49 """
50 Starts the given program (cmd) in a new process, if none is already
51 running, passing the command line arguments in argss.
52
53 @param cmd start the given program cmd (string)
54 @keyparam args list of parameters (list of strings)
55 @keyparam mode access mode (QIODevice.OpenMode)
56 """
57 if cmd.endswith('gnome-terminal') and args[0] == '-e':
58 args = ['-e', ' '.join(args[1:])]
59
60 super(QProcess, self).start(cmd, args, mode)
61
62 @staticmethod
63 def startDetached(cmd, args=[], path=''):
64 """
65 Starts the given program (cmd) in a new process, if none is already
66 running, passing the command line arguments in argss.
67
68 @param cmd start the given program cmd (string)
69 @keyparam args list of parameters (list of strings)
70 @keyparam path new working directory (string)
71 @return tuple of successful start and process id (boolean, integer)
72 """
73 if cmd.endswith('gnome-terminal') and args[0] == '-e':
74 args = ['-e', ' '.join(args[1:])]
75
76 return QProcessPyQt.startDetached(cmd, args, path)
41 77
42 78
43 class Project(QObject): 79 class Project(QObject):
44 """ 80 """
45 Class implementing the Django project support. 81 Class implementing the Django project support.
994 ] 1030 ]
995 for cmd in cmds: 1031 for cmd in cmds:
996 if os.path.exists(cmd): 1032 if os.path.exists(cmd):
997 break 1033 break
998 else: 1034 else:
999 "" 1035 cmd = ""
1000 else: 1036 else:
1001 if isWindowsPlatform(): 1037 if isWindowsPlatform():
1002 debugEnv = self.__getDebugEnvironment(language) 1038 debugEnv = self.__getDebugEnvironment(language)
1003 cmd = os.path.join(debugEnv, "Scripts", "django-admin.py") 1039 cmd = os.path.join(debugEnv, "Scripts", "django-admin.py")
1004 else: 1040 else:
1026 if language == "Python3": 1062 if language == "Python3":
1027 pythonExe = "python3" 1063 pythonExe = "python3"
1028 elif language == "Python2": 1064 elif language == "Python2":
1029 pythonExe = "python2" 1065 pythonExe = "python2"
1030 virtualEnv = self.__getVirtualEnvironment() 1066 virtualEnv = self.__getVirtualEnvironment()
1031 if not virtualEnv: 1067 if isWindowsPlatform() and not virtualEnv:
1032 virtualEnv = self.__getDebugEnvironment(language) 1068 virtualEnv = self.__getDebugEnvironment(language)
1033 if virtualEnv: 1069 if virtualEnv:
1034 if isWindowsPlatform(): 1070 if isWindowsPlatform():
1035 python = os.path.join(virtualEnv, "Scripts", pythonExe) 1071 python = os.path.join(virtualEnv, "Scripts", pythonExe)
1036 if not os.path.exists(python): 1072 if not os.path.exists(python):
1037 python = os.path.join(virtualEnv, pythonExe) 1073 python = os.path.join(virtualEnv, pythonExe)
1038 else: 1074 else:
1039 python = os.path.join(virtualEnv, "bin", pythonExe) 1075 python = os.path.join(virtualEnv, "bin", pythonExe)
1040 if not os.path.exists(python): 1076 if not os.path.exists(python):
1041 python = python[:-1] # omit the version character 1077 python = python[:-1] # omit the version character
1078 else:
1079 python = pythonExe
1042 1080
1043 return python 1081 return python
1044 1082
1045 def __djangoInfo(self): 1083 def __djangoInfo(self):
1046 """ 1084 """
1071 Public method to get the Django version. 1109 Public method to get the Django version.
1072 1110
1073 @return Django version (string) 1111 @return Django version (string)
1074 """ 1112 """
1075 if not self.__djangoVersion: 1113 if not self.__djangoVersion:
1114 args = ['--version']
1076 ioEncoding = Preferences.getSystem("IOEncoding") 1115 ioEncoding = Preferences.getSystem("IOEncoding")
1077 cmd = self.__getDjangoAdminCommand() 1116 cmd = self.__getDjangoAdminCommand()
1117 if isWindowsPlatform():
1118 args.insert(0, cmd)
1119 cmd = self.__getPythonExecutable()
1078 1120
1079 process = QProcess() 1121 process = QProcess()
1080 process.start(cmd, ['--version']) 1122 process.start(cmd, args)
1081 procStarted = process.waitForStarted() 1123 procStarted = process.waitForStarted()
1082 if procStarted: 1124 if procStarted:
1083 finished = process.waitForFinished(30000) 1125 finished = process.waitForFinished(30000)
1084 if finished and process.exitCode() == 0: 1126 if finished and process.exitCode() == 0:
1085 output = \ 1127 output = \

eric ide

mercurial