10 import contextlib |
10 import contextlib |
11 import os |
11 import os |
12 import re |
12 import re |
13 import shutil |
13 import shutil |
14 |
14 |
15 from PyQt6.QtCore import QObject, QTimer, QUrl, QFileInfo, QIODeviceBase |
15 from PyQt6.QtCore import ( |
|
16 QFileInfo, |
|
17 QIODeviceBase, |
|
18 QObject, |
|
19 QProcess as QProcessPyQt, |
|
20 QTimer, |
|
21 QUrl, |
|
22 ) |
16 from PyQt6.QtGui import QDesktopServices |
23 from PyQt6.QtGui import QDesktopServices |
17 from PyQt6.QtWidgets import QMenu, QInputDialog, QLineEdit, QDialog |
24 from PyQt6.QtWidgets import QDialog, QInputDialog, QLineEdit, QMenu |
18 from PyQt6.QtCore import QProcess as QProcessPyQt |
|
19 |
25 |
20 from eric7 import Preferences, Utilities |
26 from eric7 import Preferences, Utilities |
21 |
27 |
22 try: |
28 try: |
23 from eric7.EricGui import EricPixmapCache |
29 from eric7.EricGui import EricPixmapCache |
24 except ImportError: |
30 except ImportError: |
25 from UI import PixmapCache as EricPixmapCache |
31 from UI import PixmapCache as EricPixmapCache |
|
32 |
26 from eric7.EricGui.EricAction import EricAction |
33 from eric7.EricGui.EricAction import EricAction |
27 from eric7.EricWidgets import EricMessageBox, EricFileDialog |
34 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
28 from eric7.EricWidgets.EricApplication import ericApp |
35 from eric7.EricWidgets.EricApplication import ericApp |
29 from eric7.Globals import isWindowsPlatform |
36 |
|
37 try: |
|
38 from eric7.SystemUtilities.OSUtilities import isWindowsPlatform |
|
39 except ImportError: |
|
40 # imports for eric < 23.1 |
|
41 from eric7.Globals import isWindowsPlatform |
|
42 try: |
|
43 from eric7.SystemUtilities.FileSystemUtilities import ( |
|
44 getExecutablePath, |
|
45 getExecutablePaths, |
|
46 isinpath, |
|
47 ) |
|
48 except ImportError: |
|
49 # imports for eric < 23.1 |
|
50 from eric7.Utilities import getExecutablePath, getExecutablePaths, isinpath |
30 |
51 |
31 from .DjangoDialog import DjangoDialog |
52 from .DjangoDialog import DjangoDialog |
32 |
53 |
33 |
54 |
34 class DjangoNoSiteSelectedError(Exception): |
55 class DjangoNoSiteSelectedError(Exception): |
1372 if cmd: |
1393 if cmd: |
1373 variants.append(variant) |
1394 variants.append(variant) |
1374 else: |
1395 else: |
1375 if cmd: |
1396 if cmd: |
1376 try: |
1397 try: |
1377 fullCmds = Utilities.getExecutablePaths(cmd) |
1398 fullCmds = getExecutablePaths(cmd) |
1378 except AttributeError: |
1399 except AttributeError: |
1379 fullCmds = self.__getExecutablePaths(cmd) |
1400 fullCmds = self.__getExecutablePaths(cmd) |
1380 for fullCmd in fullCmds: |
1401 for fullCmd in fullCmds: |
1381 try: |
1402 try: |
1382 with open(fullCmd, "r", encoding="utf-8") as f: |
1403 with open(fullCmd, "r", encoding="utf-8") as f: |
1896 shutil.rmtree(ppath, ignore_errors=True) |
1917 shutil.rmtree(ppath, ignore_errors=True) |
1897 |
1918 |
1898 args = [] |
1919 args = [] |
1899 cmd = self.__getDjangoAdminCommand() |
1920 cmd = self.__getDjangoAdminCommand() |
1900 if cmd: |
1921 if cmd: |
1901 if Utilities.isWindowsPlatform(): |
1922 if isWindowsPlatform(): |
1902 args.append(self.__getPythonExecutable()) |
1923 args.append(self.__getPythonExecutable()) |
1903 args.append(cmd) |
1924 args.append(cmd) |
1904 else: |
1925 else: |
1905 EricMessageBox.critical( |
1926 EricMessageBox.critical( |
1906 self.__ui, |
1927 self.__ui, |
2170 consoleCmd = self.__isSpawningConsole( |
2191 consoleCmd = self.__isSpawningConsole( |
2171 self.__plugin.getPreferences("ConsoleCommand") |
2192 self.__plugin.getPreferences("ConsoleCommand") |
2172 )[1] |
2193 )[1] |
2173 if consoleCmd: |
2194 if consoleCmd: |
2174 args = Utilities.parseOptionString(consoleCmd) |
2195 args = Utilities.parseOptionString(consoleCmd) |
2175 args[0] = Utilities.getExecutablePath(args[0]) |
2196 args[0] = getExecutablePath(args[0]) |
2176 args.append(self.__getPythonExecutable()) |
2197 args.append(self.__getPythonExecutable()) |
2177 args.append("manage.py") |
2198 args.append("manage.py") |
2178 args.append("runserver") |
2199 args.append("runserver") |
2179 if self.__plugin.getPreferences("UseIPv6"): |
2200 if self.__plugin.getPreferences("UseIPv6"): |
2180 args.append("--ipv6") |
2201 args.append("--ipv6") |
2183 addr = self.__plugin.getPreferences("ServerAddress") |
2204 addr = self.__plugin.getPreferences("ServerAddress") |
2184 if addr: |
2205 if addr: |
2185 args.append(addr) |
2206 args.append(addr) |
2186 |
2207 |
2187 with contextlib.suppress(DjangoNoSiteSelectedError): |
2208 with contextlib.suppress(DjangoNoSiteSelectedError): |
2188 if Utilities.isWindowsPlatform(): |
2209 if isWindowsPlatform(): |
2189 serverProcStarted, pid = QProcess.startDetached( |
2210 serverProcStarted, pid = QProcess.startDetached( |
2190 args[0], args[1:], self.__sitePath() |
2211 args[0], args[1:], self.__sitePath() |
2191 ) |
2212 ) |
2192 else: |
2213 else: |
2193 if self.__serverProc is not None: |
2214 if self.__serverProc is not None: |
2429 consoleCmd = self.__isSpawningConsole( |
2450 consoleCmd = self.__isSpawningConsole( |
2430 self.__plugin.getPreferences("ConsoleCommand") |
2451 self.__plugin.getPreferences("ConsoleCommand") |
2431 )[1] |
2452 )[1] |
2432 if consoleCmd: |
2453 if consoleCmd: |
2433 args = Utilities.parseOptionString(consoleCmd) |
2454 args = Utilities.parseOptionString(consoleCmd) |
2434 args[0] = Utilities.getExecutablePath(args[0]) |
2455 args[0] = getExecutablePath(args[0]) |
2435 args.append(self.__getPythonExecutable()) |
2456 args.append(self.__getPythonExecutable()) |
2436 args.append("manage.py") |
2457 args.append("manage.py") |
2437 args.append("dbshell") |
2458 args.append("dbshell") |
2438 if self.__currentDatabase: |
2459 if self.__currentDatabase: |
2439 args.append("--database={0}".format(self.__currentDatabase)) |
2460 args.append("--database={0}".format(self.__currentDatabase)) |
2880 consoleCmd = self.__isSpawningConsole( |
2901 consoleCmd = self.__isSpawningConsole( |
2881 self.__plugin.getPreferences("ConsoleCommand") |
2902 self.__plugin.getPreferences("ConsoleCommand") |
2882 )[1] |
2903 )[1] |
2883 if consoleCmd: |
2904 if consoleCmd: |
2884 args = Utilities.parseOptionString(consoleCmd) |
2905 args = Utilities.parseOptionString(consoleCmd) |
2885 args[0] = Utilities.getExecutablePath(args[0]) |
2906 args[0] = getExecutablePath(args[0]) |
2886 args.append(self.__getPythonExecutable()) |
2907 args.append(self.__getPythonExecutable()) |
2887 args.append("manage.py") |
2908 args.append("manage.py") |
2888 args.append("shell") |
2909 args.append("shell") |
2889 args.append( |
2910 args.append( |
2890 "--interface={0}".format( |
2911 "--interface={0}".format( |
3076 labels, pattern, tags, excludeTags, keep, reverse = dlg.getData() |
3097 labels, pattern, tags, excludeTags, keep, reverse = dlg.getData() |
3077 |
3098 |
3078 self.__plugin.setPreferences("KeepTestDatabase", keep) |
3099 self.__plugin.setPreferences("KeepTestDatabase", keep) |
3079 |
3100 |
3080 args = Utilities.parseOptionString(consoleCmd) |
3101 args = Utilities.parseOptionString(consoleCmd) |
3081 args[0] = Utilities.getExecutablePath(args[0]) |
3102 args[0] = getExecutablePath(args[0]) |
3082 args.append(self.__getPythonExecutable()) |
3103 args.append(self.__getPythonExecutable()) |
3083 if deprecation: |
3104 if deprecation: |
3084 args.append("-Wall") |
3105 args.append("-Wall") |
3085 args.append("manage.py") |
3106 args.append("manage.py") |
3086 args.append("test") |
3107 args.append("test") |
3119 dlg = DjangoRunTestServerDataDialog(self, self.__ui) |
3140 dlg = DjangoRunTestServerDataDialog(self, self.__ui) |
3120 if dlg.exec() == QDialog.DialogCode.Accepted: |
3141 if dlg.exec() == QDialog.DialogCode.Accepted: |
3121 fixtures = dlg.getData() |
3142 fixtures = dlg.getData() |
3122 |
3143 |
3123 args = Utilities.parseOptionString(consoleCmd) |
3144 args = Utilities.parseOptionString(consoleCmd) |
3124 args[0] = Utilities.getExecutablePath(args[0]) |
3145 args[0] = getExecutablePath(args[0]) |
3125 args.append(self.__getPythonExecutable()) |
3146 args.append(self.__getPythonExecutable()) |
3126 args.append("manage.py") |
3147 args.append("manage.py") |
3127 args.append("testserver") |
3148 args.append("testserver") |
3128 if self.__plugin.getPreferences("UseIPv6"): |
3149 if self.__plugin.getPreferences("UseIPv6"): |
3129 args.append("--ipv6") |
3150 args.append("--ipv6") |
3131 if addr: |
3152 if addr: |
3132 args.append("--addrport={0}".format(addr)) |
3153 args.append("--addrport={0}".format(addr)) |
3133 args += fixtures |
3154 args += fixtures |
3134 |
3155 |
3135 with contextlib.suppress(DjangoNoSiteSelectedError): |
3156 with contextlib.suppress(DjangoNoSiteSelectedError): |
3136 if Utilities.isWindowsPlatform(): |
3157 if isWindowsPlatform(): |
3137 serverProcStarted, pid = QProcess.startDetached( |
3158 serverProcStarted, pid = QProcess.startDetached( |
3138 args[0], args[1:], self.__sitePath() |
3159 args[0], args[1:], self.__sitePath() |
3139 ) |
3160 ) |
3140 else: |
3161 else: |
3141 if self.__testServerProc is not None: |
3162 if self.__testServerProc is not None: |
3186 self.tr("Enter the name of the user:"), |
3207 self.tr("Enter the name of the user:"), |
3187 QLineEdit.EchoMode.Normal, |
3208 QLineEdit.EchoMode.Normal, |
3188 ) |
3209 ) |
3189 if ok and userName != "": |
3210 if ok and userName != "": |
3190 args = Utilities.parseOptionString(consoleCmd) |
3211 args = Utilities.parseOptionString(consoleCmd) |
3191 args[0] = Utilities.getExecutablePath(args[0]) |
3212 args[0] = getExecutablePath(args[0]) |
3192 args.append(self.__getPythonExecutable()) |
3213 args.append(self.__getPythonExecutable()) |
3193 args.append("manage.py") |
3214 args.append("manage.py") |
3194 args.append("changepassword") |
3215 args.append("changepassword") |
3195 args.append(userName) |
3216 args.append(userName) |
3196 with contextlib.suppress(DjangoNoSiteSelectedError): |
3217 with contextlib.suppress(DjangoNoSiteSelectedError): |
3211 consoleCmd = self.__isSpawningConsole( |
3232 consoleCmd = self.__isSpawningConsole( |
3212 self.__plugin.getPreferences("ConsoleCommandNoClose") |
3233 self.__plugin.getPreferences("ConsoleCommandNoClose") |
3213 )[1] |
3234 )[1] |
3214 if consoleCmd: |
3235 if consoleCmd: |
3215 args = Utilities.parseOptionString(consoleCmd) |
3236 args = Utilities.parseOptionString(consoleCmd) |
3216 args[0] = Utilities.getExecutablePath(args[0]) |
3237 args[0] = getExecutablePath(args[0]) |
3217 args.append(self.__getPythonExecutable()) |
3238 args.append(self.__getPythonExecutable()) |
3218 args.append("manage.py") |
3239 args.append("manage.py") |
3219 args.append("createsuperuser") |
3240 args.append("createsuperuser") |
3220 with contextlib.suppress(DjangoNoSiteSelectedError): |
3241 with contextlib.suppress(DjangoNoSiteSelectedError): |
3221 wd = self.__sitePath() |
3242 wd = self.__sitePath() |