50 @keyparam mode access mode (QIODevice.OpenMode) |
51 @keyparam mode access mode (QIODevice.OpenMode) |
51 """ |
52 """ |
52 if args is None: |
53 if args is None: |
53 args = [] |
54 args = [] |
54 |
55 |
55 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal', |
56 if ( |
56 'mate-terminal')): |
57 cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal', |
57 if '-e' in args: |
58 'mate-terminal')) and |
58 index = args.index('-e') + 1 |
59 '-e' in args |
59 cargs = ' '.join(args[index:]) |
60 ): |
60 args[index:] = [cargs] |
61 index = args.index('-e') + 1 |
61 |
62 cargs = ' '.join(args[index:]) |
62 super(QProcess, self).start(cmd, args, mode) |
63 args[index:] = [cargs] |
|
64 |
|
65 super().start(cmd, args, mode) |
63 |
66 |
64 @staticmethod |
67 @staticmethod |
65 def startDetached(cmd, args=None, path=''): |
68 def startDetached(cmd, args=None, path=''): |
66 """ |
69 """ |
67 Public static method to start the given program (cmd) in a new process, |
70 Public static method to start the given program (cmd) in a new process, |
390 |
395 |
391 def __initDatabaseSqlActions(self): |
396 def __initDatabaseSqlActions(self): |
392 """ |
397 """ |
393 Private method to define the database SQL related actions. |
398 Private method to define the database SQL related actions. |
394 """ |
399 """ |
395 self.databaseSqlCreateTablesAct = E5Action( |
|
396 self.tr('Create Tables'), |
|
397 self.tr('Create &Tables'), |
|
398 0, 0, |
|
399 self, 'django_database_sql_create_tables') |
|
400 self.databaseSqlCreateTablesAct.setStatusTip(self.tr( |
|
401 'Prints the CREATE TABLE SQL statements for one or more' |
|
402 ' applications')) |
|
403 self.databaseSqlCreateTablesAct.setWhatsThis(self.tr( |
|
404 """<b>Create Tables</b>""" |
|
405 """<p>Prints the CREATE TABLE SQL statements for one or """ |
|
406 """more applications.</p>""" |
|
407 )) |
|
408 self.databaseSqlCreateTablesAct.triggered.connect( |
|
409 self.__databaseSqlCreateTables) |
|
410 self.actions.append(self.databaseSqlCreateTablesAct) |
|
411 |
|
412 self.databaseSqlCreateIndexesAct = E5Action( |
|
413 self.tr('Create Indexes'), |
|
414 self.tr('Create &Indexes'), |
|
415 0, 0, |
|
416 self, 'django_database_sql_create_indexes') |
|
417 self.databaseSqlCreateIndexesAct.setStatusTip(self.tr( |
|
418 'Prints the CREATE INDEX SQL statements for one or more' |
|
419 ' applications')) |
|
420 self.databaseSqlCreateIndexesAct.setWhatsThis(self.tr( |
|
421 """<b>Create Indexes</b>""" |
|
422 """<p>Prints the CREATE INDEX SQL statements for one or """ |
|
423 """more applications.</p>""" |
|
424 )) |
|
425 self.databaseSqlCreateIndexesAct.triggered.connect( |
|
426 self.__databaseSqlCreateIndexes) |
|
427 self.actions.append(self.databaseSqlCreateIndexesAct) |
|
428 |
|
429 self.databaseSqlCreateEverythingAct = E5Action( |
|
430 self.tr('Create Everything'), |
|
431 self.tr('Create &Everything'), |
|
432 0, 0, |
|
433 self, 'django_database_sql_create_everything') |
|
434 self.databaseSqlCreateEverythingAct.setStatusTip(self.tr( |
|
435 'Prints the CREATE ... SQL statements for one or more' |
|
436 ' applications')) |
|
437 self.databaseSqlCreateEverythingAct.setWhatsThis(self.tr( |
|
438 """<b>Create Everything</b>""" |
|
439 """<p>Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL """ |
|
440 """statements for one or more applications.</p>""" |
|
441 )) |
|
442 self.databaseSqlCreateEverythingAct.triggered.connect( |
|
443 self.__databaseSqlCreateEverything) |
|
444 self.actions.append(self.databaseSqlCreateEverythingAct) |
|
445 |
|
446 self.databaseSqlCustomAct = E5Action( |
|
447 self.tr('Custom Statements'), |
|
448 self.tr('&Custom Statements'), |
|
449 0, 0, |
|
450 self, 'django_database_sql_custom') |
|
451 self.databaseSqlCustomAct.setStatusTip(self.tr( |
|
452 'Prints the custom table modifying SQL statements for ' |
|
453 'one or more applications')) |
|
454 self.databaseSqlCustomAct.setWhatsThis(self.tr( |
|
455 """<b>Custom Statements</b>""" |
|
456 """<p>Prints the custom table modifying SQL statements """ |
|
457 """for one or more applications.</p>""" |
|
458 )) |
|
459 self.databaseSqlCustomAct.triggered.connect( |
|
460 self.__databaseSqlCustom) |
|
461 self.actions.append(self.databaseSqlCustomAct) |
|
462 |
|
463 self.databaseSqlDropTablesAct = E5Action( |
|
464 self.tr('Drop Tables'), |
|
465 self.tr('&Drop Tables'), |
|
466 0, 0, |
|
467 self, 'django_database_sql_drop_tables') |
|
468 self.databaseSqlDropTablesAct.setStatusTip(self.tr( |
|
469 'Prints the DROP TABLE SQL statements for ' |
|
470 'one or more applications')) |
|
471 self.databaseSqlDropTablesAct.setWhatsThis(self.tr( |
|
472 """<b>Drop Tables</b>""" |
|
473 """<p>Prints the DROP TABLE SQL statements """ |
|
474 """for one or more applications.</p>""" |
|
475 )) |
|
476 self.databaseSqlDropTablesAct.triggered.connect( |
|
477 self.__databaseSqlDropTables) |
|
478 self.actions.append(self.databaseSqlDropTablesAct) |
|
479 |
|
480 self.databaseSqlDropIndexesAct = E5Action( |
|
481 self.tr('Drop Indexes'), |
|
482 self.tr('&Drop Indexes'), |
|
483 0, 0, |
|
484 self, 'django_database_sql_drop_indexes') |
|
485 self.databaseSqlDropIndexesAct.setStatusTip(self.tr( |
|
486 'Prints the DROP INDEX SQL statements for ' |
|
487 'one or more applications')) |
|
488 self.databaseSqlDropIndexesAct.setWhatsThis(self.tr( |
|
489 """<b>Drop Indexes</b>""" |
|
490 """<p>Prints the DROP INDEX SQL statements """ |
|
491 """for one or more applications.</p>""" |
|
492 )) |
|
493 self.databaseSqlDropIndexesAct.triggered.connect( |
|
494 self.__databaseSqlDropIndexes) |
|
495 self.actions.append(self.databaseSqlDropIndexesAct) |
|
496 |
|
497 self.databaseSqlFlushAct = E5Action( |
400 self.databaseSqlFlushAct = E5Action( |
498 self.tr('Flush Database'), |
401 self.tr('Flush Database'), |
499 self.tr('&Flush Database'), |
402 self.tr('&Flush Database'), |
500 0, 0, |
403 0, 0, |
501 self, 'django_database_sql_flush_database') |
404 self, 'django_database_sql_flush_database') |
921 @rtype QMenu |
824 @rtype QMenu |
922 """ |
825 """ |
923 menu = QMenu(self.tr("Show &SQL"), self.__ui) |
826 menu = QMenu(self.tr("Show &SQL"), self.__ui) |
924 menu.setTearOffEnabled(True) |
827 menu.setTearOffEnabled(True) |
925 |
828 |
926 if self.getDjangoVersion() < (1, 9, 0): |
|
927 menu.addAction(self.databaseSqlCreateTablesAct) |
|
928 menu.addAction(self.databaseSqlCreateIndexesAct) |
|
929 menu.addAction(self.databaseSqlCreateEverythingAct) |
|
930 menu.addSeparator() |
|
931 menu.addAction(self.databaseSqlCustomAct) |
|
932 menu.addSeparator() |
|
933 menu.addAction(self.databaseSqlDropTablesAct) |
|
934 menu.addAction(self.databaseSqlDropIndexesAct) |
|
935 menu.addSeparator() |
|
936 menu.addAction(self.databaseSqlFlushAct) |
829 menu.addAction(self.databaseSqlFlushAct) |
937 menu.addAction(self.databaseSqlResetSeqAct) |
830 menu.addAction(self.databaseSqlResetSeqAct) |
938 menu.addSeparator() |
831 menu.addSeparator() |
939 menu.addAction(self.databaseSqlMigrateAct) |
832 menu.addAction(self.databaseSqlMigrateAct) |
940 menu.addAction(self.databaseSqlMigrateBackwardsAct) |
833 menu.addAction(self.databaseSqlMigrateBackwardsAct) |
2302 args.append(self.__getPythonExecutable()) |
2188 args.append(self.__getPythonExecutable()) |
2303 args.append("manage.py") |
2189 args.append("manage.py") |
2304 args.append("dbshell") |
2190 args.append("dbshell") |
2305 if self.__currentDatabase: |
2191 if self.__currentDatabase: |
2306 args.append("--database={0}".format(self.__currentDatabase)) |
2192 args.append("--database={0}".format(self.__currentDatabase)) |
2307 try: |
2193 with contextlib.suppress(DjangoNoSiteSelectedException): |
2308 wd = self.__sitePath() |
2194 wd = self.__sitePath() |
2309 self.__adjustWorkingDirectory(args, wd) |
2195 self.__adjustWorkingDirectory(args, wd) |
2310 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2196 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2311 if not started: |
2197 if not started: |
2312 E5MessageBox.critical( |
2198 E5MessageBox.critical( |
2313 None, |
2199 None, |
2314 self.tr('Process Generation Error'), |
2200 self.tr('Process Generation Error'), |
2315 self.tr('The Django process could not be started.')) |
2201 self.tr('The Django process could not be started.')) |
2316 except DjangoNoSiteSelectedException: |
|
2317 pass |
|
2318 |
2202 |
2319 ####################################################################### |
2203 ####################################################################### |
2320 ## slots below implement database functions outputting SQL statements |
2204 ## slots below implement database functions outputting SQL statements |
2321 ####################################################################### |
2205 ####################################################################### |
2322 |
2206 |
2354 dia = DjangoDialog(title, fixed=True, linewrap=False, |
2238 dia = DjangoDialog(title, fixed=True, linewrap=False, |
2355 saveFilters=fileFilter) |
2239 saveFilters=fileFilter) |
2356 res = dia.startProcess(args, path, False) |
2240 res = dia.startProcess(args, path, False) |
2357 if res: |
2241 if res: |
2358 dia.exec() |
2242 dia.exec() |
2359 |
|
2360 def __databaseSqlCreateTables(self): |
|
2361 """ |
|
2362 Private slot to print the CREATE TABLE SQL statements for one |
|
2363 or more applications. |
|
2364 |
|
2365 Note: available before Django v1.9.0 |
|
2366 """ |
|
2367 self.__sqlCommand(self.tr("Create Tables"), "sql") |
|
2368 |
|
2369 def __databaseSqlCreateIndexes(self): |
|
2370 """ |
|
2371 Private slot to print the CREATE INDEX SQL statements for one |
|
2372 or more applications. |
|
2373 |
|
2374 Note: available before Django v1.9.0 |
|
2375 """ |
|
2376 self.__sqlCommand(self.tr("Create Indexes"), "sqlindexes") |
|
2377 |
|
2378 def __databaseSqlCreateEverything(self): |
|
2379 """ |
|
2380 Private slot to print the CREATE TABLE, custom SQL and |
|
2381 CREATE INDEX SQL statements for one or more applications. |
|
2382 |
|
2383 Note: available before Django v1.9.0 |
|
2384 """ |
|
2385 self.__sqlCommand(self.tr("Create Everything"), "sqlall") |
|
2386 |
|
2387 def __databaseSqlCustom(self): |
|
2388 """ |
|
2389 Private slot to print the custom table modifying SQL statements |
|
2390 for one or more applications. |
|
2391 |
|
2392 Note: available before Django v1.9.0 |
|
2393 """ |
|
2394 self.__sqlCommand(self.tr("Custom Statements"), "sqlcustom") |
|
2395 |
|
2396 def __databaseSqlDropTables(self): |
|
2397 """ |
|
2398 Private slot to print the DROP TABLE SQL statements for one or |
|
2399 more applications. |
|
2400 |
|
2401 Note: available before Django v1.9.0 |
|
2402 """ |
|
2403 self.__sqlCommand(self.tr("Drop Tables"), "sqlclear") |
|
2404 |
|
2405 def __databaseSqlDropIndexes(self): |
|
2406 """ |
|
2407 Private slot to print the DROP INDEX SQL statements for one or |
|
2408 more applications. |
|
2409 |
|
2410 Note: available before Django v1.9.0 |
|
2411 """ |
|
2412 self.__sqlCommand(self.tr("Drop Indexes"), "sqldropindexes") |
|
2413 |
2243 |
2414 def __databaseSqlFlushDatabase(self): |
2244 def __databaseSqlFlushDatabase(self): |
2415 """ |
2245 """ |
2416 Private slot to print a list of statements to return all database |
2246 Private slot to print a list of statements to return all database |
2417 tables to their initial state. |
2247 tables to their initial state. |
2610 |
2441 |
2611 args = [] |
2442 args = [] |
2612 args.append("manage.py") |
2443 args.append("manage.py") |
2613 args.append("showmigrations") |
2444 args.append("showmigrations") |
2614 args.append("--list") |
2445 args.append("--list") |
2615 if self.getDjangoVersion() >= (1, 9, 0): |
2446 if self.__currentDatabase: |
2616 if self.__currentDatabase: |
2447 args.append("--database={0}".format(self.__currentDatabase)) |
2617 args.append("--database={0}".format(self.__currentDatabase)) |
|
2618 |
2448 |
2619 migrations = {} |
2449 migrations = {} |
2620 proc = QProcess() |
2450 proc = QProcess() |
2621 if path: |
2451 if path: |
2622 proc.setWorkingDirectory(path) |
2452 proc.setWorkingDirectory(path) |
2623 proc.start(self.__getPythonExecutable(), args) |
2453 proc.start(self.__getPythonExecutable(), args) |
2624 if proc.waitForStarted(): |
2454 if proc.waitForStarted() and proc.waitForFinished(): |
2625 if proc.waitForFinished(): |
2455 output = str(proc.readAllStandardOutput(), |
2626 output = str(proc.readAllStandardOutput(), |
2456 Preferences.getSystem("IOEncoding"), 'replace') |
2627 Preferences.getSystem("IOEncoding"), 'replace') |
2457 if output: |
2628 if output: |
2458 recentApp = "" |
2629 recentApp = "" |
2459 for line in output.splitlines(): |
2630 for line in output.splitlines(): |
2460 if not line.startswith(" "): |
2631 if not line.startswith(" "): |
2461 # application name |
2632 # application name |
2462 recentApp = line.strip() |
2633 recentApp = line.strip() |
2463 migrations[recentApp] = [] |
2634 migrations[recentApp] = [] |
2464 else: |
2635 else: |
2465 # migration name |
2636 # migration name |
2466 line = line.strip() |
2637 line = line.strip() |
2467 applied = line[1] != " " |
2638 applied = line[1] != " " |
2468 name = line[3:].strip() |
2639 name = line[3:].strip() |
2469 if recentApp: |
2640 if recentApp: |
2470 migrations[recentApp].append((applied, name)) |
2641 migrations[recentApp].append((applied, name)) |
|
2642 return migrations |
2471 return migrations |
2643 |
2472 |
2644 def __makeMigrations(self): |
2473 def __makeMigrations(self): |
2645 """ |
2474 """ |
2646 Private slot to generate migrations for the Django project. |
2475 Private slot to generate migrations for the Django project. |
2790 args = Utilities.parseOptionString(consoleCmd) |
2619 args = Utilities.parseOptionString(consoleCmd) |
2791 args[0] = Utilities.getExecutablePath(args[0]) |
2620 args[0] = Utilities.getExecutablePath(args[0]) |
2792 args.append(self.__getPythonExecutable()) |
2621 args.append(self.__getPythonExecutable()) |
2793 args.append("manage.py") |
2622 args.append("manage.py") |
2794 args.append("shell") |
2623 args.append("shell") |
2795 if self.getDjangoVersion() < (1, 10, 0): |
2624 args.append("--interface={0}".format( |
2796 if (self.__plugin.getPreferences("Python3ConsoleType") == |
2625 self.__plugin.getPreferences("Python3ConsoleType"))) |
2797 "python"): |
2626 with contextlib.suppress(DjangoNoSiteSelectedException): |
2798 args.append("--plain") |
|
2799 else: |
|
2800 args.append("--interface={0}".format( |
|
2801 self.__plugin.getPreferences("Python3ConsoleType"))) |
|
2802 try: |
|
2803 wd = self.__sitePath() |
2627 wd = self.__sitePath() |
2804 self.__adjustWorkingDirectory(args, wd) |
2628 self.__adjustWorkingDirectory(args, wd) |
2805 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2629 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2806 if not started: |
2630 if not started: |
2807 E5MessageBox.critical( |
2631 E5MessageBox.critical( |
2808 None, |
2632 None, |
2809 self.tr('Process Generation Error'), |
2633 self.tr('Process Generation Error'), |
2810 self.tr('The Django process could not be started.')) |
2634 self.tr('The Django process could not be started.')) |
2811 except DjangoNoSiteSelectedException: |
|
2812 pass |
|
2813 |
2635 |
2814 def __sendTestEmail(self): |
2636 def __sendTestEmail(self): |
2815 """ |
2637 """ |
2816 Private slot to send a test email through Django. |
2638 Private slot to send a test email through Django. |
2817 """ |
2639 """ |
2818 if self.getDjangoVersion() < (1, 9, 0): |
|
2819 return |
|
2820 |
|
2821 title = self.tr("Send Test Email") |
2640 title = self.tr("Send Test Email") |
2822 |
2641 |
2823 from .DjangoSendTestEmailDataDialog import ( |
2642 from .DjangoSendTestEmailDataDialog import ( |
2824 DjangoSendTestEmailDataDialog |
2643 DjangoSendTestEmailDataDialog |
2825 ) |
2644 ) |
3102 args[0] = Utilities.getExecutablePath(args[0]) |
2916 args[0] = Utilities.getExecutablePath(args[0]) |
3103 args.append(self.__getPythonExecutable()) |
2917 args.append(self.__getPythonExecutable()) |
3104 args.append("manage.py") |
2918 args.append("manage.py") |
3105 args.append("changepassword") |
2919 args.append("changepassword") |
3106 args.append(userName) |
2920 args.append(userName) |
3107 try: |
2921 with contextlib.suppress(DjangoNoSiteSelectedException): |
3108 wd = self.__sitePath() |
2922 wd = self.__sitePath() |
3109 self.__adjustWorkingDirectory(args, wd) |
2923 self.__adjustWorkingDirectory(args, wd) |
3110 started, pid = QProcess.startDetached( |
2924 started, pid = QProcess.startDetached( |
3111 args[0], args[1:], wd) |
2925 args[0], args[1:], wd) |
3112 if not started: |
2926 if not started: |
3113 E5MessageBox.critical( |
2927 E5MessageBox.critical( |
3114 None, |
2928 None, |
3115 self.tr('Process Generation Error'), |
2929 self.tr('Process Generation Error'), |
3116 self.tr('The Django process could not be' |
2930 self.tr('The Django process could not be' |
3117 ' started.')) |
2931 ' started.')) |
3118 except DjangoNoSiteSelectedException: |
|
3119 pass |
|
3120 |
2932 |
3121 def __createSuperUser(self): |
2933 def __createSuperUser(self): |
3122 """ |
2934 """ |
3123 Private slot to create a super user account. |
2935 Private slot to create a super user account. |
3124 """ |
2936 """ |
3128 args = Utilities.parseOptionString(consoleCmd) |
2940 args = Utilities.parseOptionString(consoleCmd) |
3129 args[0] = Utilities.getExecutablePath(args[0]) |
2941 args[0] = Utilities.getExecutablePath(args[0]) |
3130 args.append(self.__getPythonExecutable()) |
2942 args.append(self.__getPythonExecutable()) |
3131 args.append("manage.py") |
2943 args.append("manage.py") |
3132 args.append("createsuperuser") |
2944 args.append("createsuperuser") |
3133 try: |
2945 with contextlib.suppress(DjangoNoSiteSelectedException): |
3134 wd = self.__sitePath() |
2946 wd = self.__sitePath() |
3135 self.__adjustWorkingDirectory(args, wd) |
2947 self.__adjustWorkingDirectory(args, wd) |
3136 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2948 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
3137 if not started: |
2949 if not started: |
3138 E5MessageBox.critical( |
2950 E5MessageBox.critical( |
3139 None, |
2951 None, |
3140 self.tr('Process Generation Error'), |
2952 self.tr('Process Generation Error'), |
3141 self.tr('The Django process could not be started.')) |
2953 self.tr('The Django process could not be started.')) |
3142 except DjangoNoSiteSelectedException: |
|
3143 pass |
|
3144 |
2954 |
3145 ################################################################## |
2955 ################################################################## |
3146 ## slots below implement session functions |
2956 ## slots below implement session functions |
3147 ################################################################## |
2957 ################################################################## |
3148 |
2958 |