ProjectDjango/Project.py

changeset 70
77f58dfc7eaa
parent 65
bceb78c1b1f0
child 72
0f95786f7868
equal deleted inserted replaced
69:a0e4c09061c3 70:77f58dfc7eaa
14 pass 14 pass
15 15
16 import sys 16 import sys
17 import os 17 import os
18 import re 18 import re
19 import shutil
19 20
20 from PyQt5.QtCore import QObject, QTimer, QUrl, QFileInfo 21 from PyQt5.QtCore import QObject, QTimer, QUrl, QFileInfo
21 from PyQt5.QtGui import QDesktopServices 22 from PyQt5.QtGui import QDesktopServices
22 from PyQt5.QtWidgets import QMenu, QInputDialog, QLineEdit, QDialog 23 from PyQt5.QtWidgets import QMenu, QInputDialog, QLineEdit, QDialog
23 from PyQt5.QtCore import QProcess as QProcessPyQt 24 from PyQt5.QtCore import QProcess as QProcessPyQt
1029 if self.__getDjangoAdminCommand(variant): 1030 if self.__getDjangoAdminCommand(variant):
1030 variants.append(variant) 1031 variants.append(variant)
1031 else: 1032 else:
1032 cmd = self.__getDjangoAdminCommand(variant) 1033 cmd = self.__getDjangoAdminCommand(variant)
1033 if isWindowsPlatform(): 1034 if isWindowsPlatform():
1034 if variant.lower() in cmd.lower(): 1035 if cmd:
1035 variants.append(variant) 1036 variants.append(variant)
1036 else: 1037 else:
1037 try: 1038 try:
1038 fullCmds = Utilities.getExecutablePaths(cmd) 1039 fullCmds = Utilities.getExecutablePaths(cmd)
1039 except AttributeError: 1040 except AttributeError:
1133 else: 1134 else:
1134 cmd = "" 1135 cmd = ""
1135 else: 1136 else:
1136 if isWindowsPlatform(): 1137 if isWindowsPlatform():
1137 debugEnv = self.__getDebugEnvironment(language) 1138 debugEnv = self.__getDebugEnvironment(language)
1138 cmd = os.path.join(debugEnv, "Scripts", "django-admin.py") 1139 for cmd in [
1140 # standard Python
1141 os.path.join(debugEnv, "Scripts", "django-admin.py"),
1142 # PyPy
1143 os.path.join(debugEnv, "bin", "django-admin.py"),
1144 ]:
1145 if os.path.exists(cmd):
1146 break
1147 else:
1148 cmd = ""
1139 else: 1149 else:
1140 if language == "Python2": 1150 if language == "Python2":
1141 cmds = ["django-admin2.py", "django-admin2", 1151 cmds = ["django-admin2.py", "django-admin2",
1142 "django-admin.py-2.7", "django-admin.py-2.6"] 1152 "django-admin.py-2.7", "django-admin.py-2.6"]
1143 elif language == "Python3": 1153 elif language == "Python3":
1144 cmds = ["django-admin3.py", "django-admin3", 1154 cmds = ["django-admin3.py", "django-admin3",
1155 "django-admin.py-3.6", "django-admin.py-3.5",
1145 "django-admin.py-3.4", "django-admin.py-3.3", 1156 "django-admin.py-3.4", "django-admin.py-3.3",
1146 "django-admin.py-3.2"] 1157 "django-admin.py-3.2"]
1147 else: 1158 else:
1148 cmds = [] 1159 cmds = []
1149 cmds.extend(["django-admin.py", "django-admin"]) 1160 cmds.extend(["django-admin.py", "django-admin"])
1160 Private method to build the Python command. 1171 Private method to build the Python command.
1161 1172
1162 @return python command (string) 1173 @return python command (string)
1163 """ 1174 """
1164 language = self.__e5project.getProjectLanguage() 1175 language = self.__e5project.getProjectLanguage()
1165 pythonExe = "python" 1176 virtualEnv = self.__getVirtualEnvironment()
1166 if isWindowsPlatform(): 1177 if isWindowsPlatform():
1167 pythonExe += ".exe" 1178 pythonExeList = ["python.exe", "pypy.exe"]
1179 if not virtualEnv:
1180 virtualEnv = self.__getDebugEnvironment(language)
1181 for pythonExe in pythonExeList:
1182 for python in [
1183 os.path.join(virtualEnv, "Scripts", pythonExe),
1184 os.path.join(virtualEnv, "bin", pythonExe),
1185 os.path.join(virtualEnv, pythonExe)
1186 ]:
1187 if os.path.exists(python):
1188 break
1189 else:
1190 python = ""
1191
1192 if python:
1193 break
1194 else:
1195 python = ""
1168 else: 1196 else:
1169 if language == "Python3": 1197 if language == "Python3":
1170 pythonExe = "python3" 1198 pythonExeList = ["python3", "pypy3"]
1171 elif language == "Python2": 1199 elif language == "Python2":
1172 pythonExe = "python2" 1200 pythonExeList = ["python2", "pypy2"]
1173 virtualEnv = self.__getVirtualEnvironment() 1201 if not virtualEnv:
1174 if isWindowsPlatform() and not virtualEnv: 1202 pythonExeList.append("pypy")
1175 virtualEnv = self.__getDebugEnvironment(language) 1203 virtualEnv = self.__getDebugEnvironment(language)
1176 if virtualEnv: 1204
1177 if isWindowsPlatform(): 1205 for pythonExe in pythonExeList:
1178 python = os.path.join(virtualEnv, "Scripts", pythonExe) 1206 for python in [
1179 if not os.path.exists(python): 1207 os.path.join(virtualEnv, "bin", pythonExe),
1180 python = os.path.join(virtualEnv, pythonExe) 1208 # omit the version character
1209 os.path.join(virtualEnv, "bin", pythonExe)[:-1],
1210 ]:
1211 if os.path.exists(python):
1212 break
1213 else:
1214 python = ""
1215
1216 if python:
1217 break
1181 else: 1218 else:
1182 python = os.path.join(virtualEnv, "bin", pythonExe) 1219 python = ""
1183 if not os.path.exists(python):
1184 python = python[:-1] # omit the version character
1185 else:
1186 python = pythonExe
1187 1220
1188 return python 1221 return python
1189 1222
1190 def __djangoInfo(self): 1223 def __djangoInfo(self):
1191 """ 1224 """
1197 msgBox = E5MessageBox.E5MessageBox( 1230 msgBox = E5MessageBox.E5MessageBox(
1198 E5MessageBox.Question, 1231 E5MessageBox.Question,
1199 self.tr("About Django"), 1232 self.tr("About Django"),
1200 self.tr( 1233 self.tr(
1201 "<p>Django is a high-level Python Web framework that" 1234 "<p>Django is a high-level Python Web framework that"
1202 " encourages rapid " 1235 " encourages rapid development and clean, pragmatic"
1203 "development and clean, pragmatic design.</p>" 1236 " design.</p>"
1204 "<p><table>" 1237 "<p><table>"
1205 "<tr><td>Version:</td><td>{0}</td></tr>" 1238 "<tr><td>Version:</td><td>{0}</td></tr>"
1206 "<tr><td>URL:</td><td><a href=\"{1}\">" 1239 "<tr><td>URL:</td><td><a href=\"{1}\">"
1207 "{1}</a></td></tr>" 1240 "{1}</a></td></tr>"
1208 "</table></p>" 1241 "</table></p>"
1370 (string) 1403 (string)
1371 @return flag indicating a successful creation (boolean) 1404 @return flag indicating a successful creation (boolean)
1372 """ 1405 """
1373 title = self.tr("Start Django Project") 1406 title = self.tr("Start Django Project")
1374 1407
1408 # remove the project directory if it exists already
1409 ppath = os.path.join(path, projectName)
1410 if os.path.exists(ppath):
1411 shutil.rmtree(ppath, ignore_errors=True)
1412
1375 args = [] 1413 args = []
1376 if Utilities.isWindowsPlatform(): 1414 if Utilities.isWindowsPlatform():
1377 args.append(self.__getPythonExecutable()) 1415 args.append(self.__getPythonExecutable())
1378 args.append(self.__getDjangoAdminCommand()) 1416 args.append(self.__getDjangoAdminCommand())
1379 else: 1417 else:
1442 @param isGlobal flag indicating a standalone Django application 1480 @param isGlobal flag indicating a standalone Django application
1443 (boolean) 1481 (boolean)
1444 @return flag indicating a successful creation (boolean) 1482 @return flag indicating a successful creation (boolean)
1445 """ 1483 """
1446 title = self.tr("Start Django Application") 1484 title = self.tr("Start Django Application")
1485
1486 # remove the application directory if it exists already
1487 apath = os.path.join(path, applName)
1488 if os.path.exists(apath):
1489 shutil.rmtree(apath, ignore_errors=True)
1447 1490
1448 args = [] 1491 args = []
1449 if isGlobal: 1492 if isGlobal:
1450 if Utilities.isWindowsPlatform(): 1493 if Utilities.isWindowsPlatform():
1451 args.append(self.__getPythonExecutable()) 1494 args.append(self.__getPythonExecutable())

eric ide

mercurial