54 |
54 |
55 @param cmd start the given program cmd (string) |
55 @param cmd start the given program cmd (string) |
56 @keyparam args list of parameters (list of strings) |
56 @keyparam args list of parameters (list of strings) |
57 @keyparam mode access mode (QIODevice.OpenMode) |
57 @keyparam mode access mode (QIODevice.OpenMode) |
58 """ |
58 """ |
59 if cmd.endswith('gnome-terminal') and args[0] == '-e': |
59 if cmd.endswith(('gnome-terminal', 'konsole')): |
60 args = ['-e', ' '.join(args[1:])] |
60 if '-e' in args: |
|
61 index = args.index('-e') + 1 |
|
62 cargs = ' '.join(args[index:]) |
|
63 args[index:] = [cargs] |
61 |
64 |
62 super(QProcess, self).start(cmd, args, mode) |
65 super(QProcess, self).start(cmd, args, mode) |
63 |
66 |
64 @staticmethod |
67 @staticmethod |
65 def startDetached(cmd, args=[], path=''): |
68 def startDetached(cmd, args=[], path=''): |
70 @param cmd start the given program cmd (string) |
73 @param cmd start the given program cmd (string) |
71 @keyparam args list of parameters (list of strings) |
74 @keyparam args list of parameters (list of strings) |
72 @keyparam path new working directory (string) |
75 @keyparam path new working directory (string) |
73 @return tuple of successful start and process id (boolean, integer) |
76 @return tuple of successful start and process id (boolean, integer) |
74 """ |
77 """ |
75 if cmd.endswith('gnome-terminal') and args[0] == '-e': |
78 if cmd.endswith(('gnome-terminal', 'konsole')): |
76 args = ['-e', ' '.join(args[1:])] |
79 if '-e' in args: |
|
80 index = args.index('-e') + 1 |
|
81 cargs = ' '.join(args[index:]) |
|
82 args[index:] = [cargs] |
77 |
83 |
78 return QProcessPyQt.startDetached(cmd, args, path) |
84 return QProcessPyQt.startDetached(cmd, args, path) |
79 |
85 |
80 |
86 |
81 class Project(QObject): |
87 class Project(QObject): |
550 """<p>Shows the modification made to the settings.</p>""" |
556 """<p>Shows the modification made to the settings.</p>""" |
551 )) |
557 )) |
552 self.diffSettingsAct.triggered.connect(self.__diffSettings) |
558 self.diffSettingsAct.triggered.connect(self.__diffSettings) |
553 self.actions.append(self.diffSettingsAct) |
559 self.actions.append(self.diffSettingsAct) |
554 |
560 |
555 self.cleanupAct = E5Action( |
|
556 self.tr('Cleanup'), |
|
557 self.tr('&Cleanup'), |
|
558 0, 0, |
|
559 self, 'django_tools_cleanup') |
|
560 self.cleanupAct.setStatusTip(self.tr( |
|
561 'Cleans out old data from the database')) |
|
562 self.cleanupAct.setWhatsThis(self.tr( |
|
563 """<b>Cleanup</b>""" |
|
564 """<p>Cleans out old data from the database.</p>""" |
|
565 )) |
|
566 self.cleanupAct.triggered.connect(self.__cleanup) |
|
567 self.actions.append(self.cleanupAct) |
|
568 |
|
569 self.validateAct = E5Action( |
|
570 self.tr('Validate'), |
|
571 self.tr('&Validate'), |
|
572 0, 0, |
|
573 self, 'django_tools_validate') |
|
574 self.validateAct.setStatusTip(self.tr( |
|
575 'Validates all installed models')) |
|
576 self.validateAct.setWhatsThis(self.tr( |
|
577 """<b>Validate</b>""" |
|
578 """<p>Validates all installed models.</p>""" |
|
579 )) |
|
580 self.validateAct.triggered.connect(self.__validate) |
|
581 self.actions.append(self.validateAct) |
|
582 |
|
583 self.runPythonShellAct = E5Action( |
561 self.runPythonShellAct = E5Action( |
584 self.tr('Start Python Console'), |
562 self.tr('Start Python Console'), |
585 self.tr('Start &Python Console'), |
563 self.tr('Start &Python Console'), |
586 0, 0, |
564 0, 0, |
587 self, 'django_tools_pythonconsole') |
565 self, 'django_tools_pythonconsole') |
637 """<b>Run Testsuite</b>""" |
615 """<b>Run Testsuite</b>""" |
638 """<p>Run the test suite for applications or the whole site.</p>""" |
616 """<p>Run the test suite for applications or the whole site.</p>""" |
639 )) |
617 )) |
640 self.runTestAct.triggered.connect(self.__runTestSuite) |
618 self.runTestAct.triggered.connect(self.__runTestSuite) |
641 self.actions.append(self.runTestAct) |
619 self.actions.append(self.runTestAct) |
|
620 |
|
621 self.runDeprecationTestAct = E5Action( |
|
622 self.tr('Run Testsuite (-Wall)'), |
|
623 self.tr('Run Testsuite (-Wall)'), |
|
624 0, 0, |
|
625 self, 'django_tools_run_deprecation_test') |
|
626 self.runDeprecationTestAct.setStatusTip(self.tr( |
|
627 'Run the test suite for applications or the whole site with' |
|
628 ' activated deprecation warnings')) |
|
629 self.runDeprecationTestAct.setWhatsThis(self.tr( |
|
630 """<b>Run Testsuite (-Wall)</b>""" |
|
631 """<p>Run the test suite for applications or the whole site""" |
|
632 """ with activated deprecation warnings.</p>""" |
|
633 )) |
|
634 self.runDeprecationTestAct.triggered.connect( |
|
635 lambda: self.__runTestSuite(deprecation=True)) |
|
636 self.actions.append(self.runDeprecationTestAct) |
642 |
637 |
643 self.runTestServerAct = E5Action( |
638 self.runTestServerAct = E5Action( |
644 self.tr('Run Testserver'), |
639 self.tr('Run Testserver'), |
645 self.tr('Run Test&server'), |
640 self.tr('Run Test&server'), |
646 0, 0, |
641 0, 0, |
865 @rtype QMenu |
860 @rtype QMenu |
866 """ |
861 """ |
867 menu = QMenu(self.tr("&Database"), self.__ui) |
862 menu = QMenu(self.tr("&Database"), self.__ui) |
868 menu.setTearOffEnabled(True) |
863 menu.setTearOffEnabled(True) |
869 |
864 |
870 menu.addAction(self.syncDatabaseAct) |
865 if self.getDjangoVersion() < (1, 7, 0): |
871 menu.addSeparator() |
866 menu.addAction(self.syncDatabaseAct) |
|
867 menu.addSeparator() |
872 menu.addAction(self.inspectDatabaseAct) |
868 menu.addAction(self.inspectDatabaseAct) |
873 menu.addSeparator() |
869 menu.addSeparator() |
874 menu.addAction(self.flushDatabaseAct) |
870 menu.addAction(self.flushDatabaseAct) |
875 menu.addSeparator() |
871 menu.addSeparator() |
876 menu.addAction(self.databaseClientAct) |
872 menu.addAction(self.databaseClientAct) |
945 """ |
941 """ |
946 menu = QMenu(self.tr("&Tools"), self.__ui) |
942 menu = QMenu(self.tr("&Tools"), self.__ui) |
947 menu.setTearOffEnabled(True) |
943 menu.setTearOffEnabled(True) |
948 |
944 |
949 menu.addAction(self.diffSettingsAct) |
945 menu.addAction(self.diffSettingsAct) |
950 menu.addAction(self.cleanupAct) |
|
951 menu.addAction(self.validateAct) |
|
952 menu.addSeparator() |
946 menu.addSeparator() |
953 menu.addAction(self.runPythonShellAct) |
947 menu.addAction(self.runPythonShellAct) |
954 |
948 |
955 self.__menus["tools"] = menu |
949 self.__menus["tools"] = menu |
956 |
950 |
968 |
962 |
969 menu.addAction(self.dumpDataAct) |
963 menu.addAction(self.dumpDataAct) |
970 menu.addAction(self.loadDataAct) |
964 menu.addAction(self.loadDataAct) |
971 menu.addSeparator() |
965 menu.addSeparator() |
972 menu.addAction(self.runTestAct) |
966 menu.addAction(self.runTestAct) |
|
967 menu.addAction(self.runDeprecationTestAct) |
973 menu.addAction(self.runTestServerAct) |
968 menu.addAction(self.runTestServerAct) |
974 |
969 |
975 self.__menus["testing"] = menu |
970 self.__menus["testing"] = menu |
976 |
971 |
977 return menu |
972 return menu |
1598 if consoleCmd and consoleCmd[0] == '@': |
1593 if consoleCmd and consoleCmd[0] == '@': |
1599 return (True, consoleCmd[1:]) |
1594 return (True, consoleCmd[1:]) |
1600 else: |
1595 else: |
1601 return (False, consoleCmd) |
1596 return (False, consoleCmd) |
1602 |
1597 |
|
1598 def __adjustWorkingDirectory(self, args, wd): |
|
1599 """ |
|
1600 Private method to adjust the working directory in the arguments list. |
|
1601 |
|
1602 @param args list of arguments to be modified |
|
1603 @type list of str |
|
1604 @param wd working directory |
|
1605 @type str |
|
1606 """ |
|
1607 if args[0].endswith("konsole") and "--workdir" in args: |
|
1608 index = args.index("--workdir") |
|
1609 args[index + 1] = wd |
|
1610 elif args[0].endswith("gnome-terminal"): |
|
1611 for index in range(len(args)): |
|
1612 if args[index].startswith("--working-directory="): |
|
1613 args[index] = "--working-directory={0}".format(wd) |
|
1614 break |
|
1615 |
1603 ################################################################## |
1616 ################################################################## |
1604 ## slots below implement creation functions |
1617 ## slots below implement creation functions |
1605 ################################################################## |
1618 ################################################################## |
1606 |
1619 |
1607 def startProjectOrApplication(self): |
1620 def startProjectOrApplication(self): |
2017 args.append(self.__getPythonExecutable()) |
2030 args.append(self.__getPythonExecutable()) |
2018 args.append("manage.py") |
2031 args.append("manage.py") |
2019 args.append("syncdb") |
2032 args.append("syncdb") |
2020 try: |
2033 try: |
2021 wd = self.__sitePath() |
2034 wd = self.__sitePath() |
|
2035 self.__adjustWorkingDirectory(args, wd) |
2022 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2036 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2023 if not started: |
2037 if not started: |
2024 E5MessageBox.critical( |
2038 E5MessageBox.critical( |
2025 None, |
2039 None, |
2026 self.tr('Process Generation Error'), |
2040 self.tr('Process Generation Error'), |
2095 args.append(self.__getPythonExecutable()) |
2109 args.append(self.__getPythonExecutable()) |
2096 args.append("manage.py") |
2110 args.append("manage.py") |
2097 args.append("dbshell") |
2111 args.append("dbshell") |
2098 try: |
2112 try: |
2099 wd = self.__sitePath() |
2113 wd = self.__sitePath() |
|
2114 self.__adjustWorkingDirectory(args, wd) |
2100 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2115 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2101 if not started: |
2116 if not started: |
2102 E5MessageBox.critical( |
2117 E5MessageBox.critical( |
2103 None, |
2118 None, |
2104 self.tr('Process Generation Error'), |
2119 self.tr('Process Generation Error'), |
2521 dia = DjangoDialog(title, fixed=True, linewrap=False) |
2536 dia = DjangoDialog(title, fixed=True, linewrap=False) |
2522 res = dia.startProcess(args, path, False) |
2537 res = dia.startProcess(args, path, False) |
2523 if res: |
2538 if res: |
2524 dia.exec_() |
2539 dia.exec_() |
2525 |
2540 |
2526 def __cleanup(self): |
|
2527 """ |
|
2528 Private slot to clean out old data from the database. |
|
2529 """ |
|
2530 title = self.tr("Cleanup") |
|
2531 |
|
2532 args = [] |
|
2533 args.append(self.__getPythonExecutable()) |
|
2534 args.append("manage.py") |
|
2535 args.append("cleanup") |
|
2536 |
|
2537 try: |
|
2538 path = self.__sitePath() |
|
2539 except DjangoNoSiteSelectedException: |
|
2540 return |
|
2541 |
|
2542 dia = DjangoDialog( |
|
2543 title, |
|
2544 msgSuccess=self.tr("Database cleaned up successfully.")) |
|
2545 res = dia.startProcess(args, path) |
|
2546 if res: |
|
2547 dia.exec_() |
|
2548 |
|
2549 def __validate(self): |
|
2550 """ |
|
2551 Private slot to validate all installed models. |
|
2552 """ |
|
2553 title = self.tr("Validate") |
|
2554 |
|
2555 args = [] |
|
2556 args.append(self.__getPythonExecutable()) |
|
2557 args.append("manage.py") |
|
2558 args.append("validate") |
|
2559 |
|
2560 try: |
|
2561 path = self.__sitePath() |
|
2562 except DjangoNoSiteSelectedException: |
|
2563 return |
|
2564 |
|
2565 dia = DjangoDialog(title) |
|
2566 res = dia.startProcess(args, path) |
|
2567 if res: |
|
2568 dia.exec_() |
|
2569 |
|
2570 def __runPythonShell(self): |
2541 def __runPythonShell(self): |
2571 """ |
2542 """ |
2572 Private slot to start a Python console for a Django project. |
2543 Private slot to start a Python console for a Django project. |
2573 """ |
2544 """ |
2574 consoleCmd = self.__isSpawningConsole( |
2545 consoleCmd = self.__isSpawningConsole( |
2586 else: |
2557 else: |
2587 if self.__plugin.getPreferences("UsePlainPythonPy3"): |
2558 if self.__plugin.getPreferences("UsePlainPythonPy3"): |
2588 args.append("--plain") |
2559 args.append("--plain") |
2589 try: |
2560 try: |
2590 wd = self.__sitePath() |
2561 wd = self.__sitePath() |
|
2562 self.__adjustWorkingDirectory(args, wd) |
2591 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2563 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2592 if not started: |
2564 if not started: |
2593 E5MessageBox.critical( |
2565 E5MessageBox.critical( |
2594 None, |
2566 None, |
2595 self.tr('Process Generation Error'), |
2567 self.tr('Process Generation Error'), |
2702 dia = DjangoDialog(title) |
2674 dia = DjangoDialog(title) |
2703 res = dia.startProcess(args, wd) |
2675 res = dia.startProcess(args, wd) |
2704 if res: |
2676 if res: |
2705 dia.exec_() |
2677 dia.exec_() |
2706 |
2678 |
2707 def __runTestSuite(self): |
2679 def __runTestSuite(self, deprecation=False): |
2708 """ |
2680 """ |
2709 Private slot to run the test suite for applications or the whole site. |
2681 Private slot to run the test suite for applications or the whole site. |
|
2682 |
|
2683 @param deprecation flag indicating to test for deprecation warnings |
|
2684 @type bool |
2710 """ |
2685 """ |
2711 consoleCmd = self.__isSpawningConsole( |
2686 consoleCmd = self.__isSpawningConsole( |
2712 self.__plugin.getPreferences("ConsoleCommandNoClose"))[1] |
2687 self.__plugin.getPreferences("ConsoleCommandNoClose"))[1] |
2713 if consoleCmd: |
2688 if consoleCmd: |
2714 try: |
2689 try: |
2717 return |
2692 return |
2718 |
2693 |
2719 args = Utilities.parseOptionString(consoleCmd) |
2694 args = Utilities.parseOptionString(consoleCmd) |
2720 args[0] = Utilities.getExecutablePath(args[0]) |
2695 args[0] = Utilities.getExecutablePath(args[0]) |
2721 args.append(self.__getPythonExecutable()) |
2696 args.append(self.__getPythonExecutable()) |
|
2697 if deprecation: |
|
2698 args.append("-Wall") |
2722 args.append("manage.py") |
2699 args.append("manage.py") |
2723 args.append("test") |
2700 args.append("test") |
2724 args += self.__getApplications() |
2701 args += self.__getApplications() |
2725 |
2702 |
|
2703 self.__adjustWorkingDirectory(args, wd) |
2726 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2704 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2727 if not started: |
2705 if not started: |
2728 E5MessageBox.critical( |
2706 E5MessageBox.critical( |
2729 None, |
2707 None, |
2730 self.tr('Process Generation Error'), |
2708 self.tr('Process Generation Error'), |
2814 args.append("manage.py") |
2792 args.append("manage.py") |
2815 args.append("changepassword") |
2793 args.append("changepassword") |
2816 args.append(userName) |
2794 args.append(userName) |
2817 try: |
2795 try: |
2818 wd = self.__sitePath() |
2796 wd = self.__sitePath() |
|
2797 self.__adjustWorkingDirectory(args, wd) |
2819 started, pid = QProcess.startDetached( |
2798 started, pid = QProcess.startDetached( |
2820 args[0], args[1:], wd) |
2799 args[0], args[1:], wd) |
2821 if not started: |
2800 if not started: |
2822 E5MessageBox.critical( |
2801 E5MessageBox.critical( |
2823 None, |
2802 None, |
2839 args.append(self.__getPythonExecutable()) |
2818 args.append(self.__getPythonExecutable()) |
2840 args.append("manage.py") |
2819 args.append("manage.py") |
2841 args.append("createsuperuser") |
2820 args.append("createsuperuser") |
2842 try: |
2821 try: |
2843 wd = self.__sitePath() |
2822 wd = self.__sitePath() |
|
2823 self.__adjustWorkingDirectory(args, wd) |
2844 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2824 started, pid = QProcess.startDetached(args[0], args[1:], wd) |
2845 if not started: |
2825 if not started: |
2846 E5MessageBox.critical( |
2826 E5MessageBox.critical( |
2847 None, |
2827 None, |
2848 self.tr('Process Generation Error'), |
2828 self.tr('Process Generation Error'), |