ProjectPyramid/Project.py

changeset 95
2b0933087db9
parent 91
893e1f0baf23
child 99
d148b68ccc76
equal deleted inserted replaced
94:6853468b870d 95:2b0933087db9
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', 'xfce4-terminal',
60 args = ['-e', ' '.join(args[1:])] 60 'mate-terminal')):
61 if '-e' in args:
62 index = args.index('-e') + 1
63 cargs = ' '.join(args[index:])
64 args[index:] = [cargs]
61 65
62 super(QProcess, self).start(cmd, args, mode) 66 super(QProcess, self).start(cmd, args, mode)
63 67
64 @staticmethod 68 @staticmethod
65 def startDetached(cmd, args=[], path=''): 69 def startDetached(cmd, args=[], path=''):
70 @param cmd start the given program cmd (string) 74 @param cmd start the given program cmd (string)
71 @keyparam args list of parameters (list of strings) 75 @keyparam args list of parameters (list of strings)
72 @keyparam path new working directory (string) 76 @keyparam path new working directory (string)
73 @return tuple of successful start and process id (boolean, integer) 77 @return tuple of successful start and process id (boolean, integer)
74 """ 78 """
75 if cmd.endswith('gnome-terminal') and args[0] == '-e': 79 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
76 args = ['-e', ' '.join(args[1:])] 80 'mate-terminal')):
81 if '-e' in args:
82 index = args.index('-e') + 1
83 cargs = ' '.join(args[index:])
84 args[index:] = [cargs]
77 85
78 return QProcessPyQt.startDetached(cmd, args, path) 86 return QProcessPyQt.startDetached(cmd, args, path)
79 87
80 88
81 class Project(QObject): 89 class Project(QObject):
768 776
769 def __pyramidInfo(self): 777 def __pyramidInfo(self):
770 """ 778 """
771 Private slot to show some info about Pyramid. 779 Private slot to show some info about Pyramid.
772 """ 780 """
773 version = self.getPyramidVersion() 781 version = self.getPyramidVersionString()
774 url = "http://www.pylonsproject.org/projects/pyramid/about" 782 url = "http://www.pylonsproject.org/projects/pyramid/about"
775 783
776 msgBox = E5MessageBox.E5MessageBox( 784 msgBox = E5MessageBox.E5MessageBox(
777 E5MessageBox.Question, 785 E5MessageBox.Question,
778 self.tr("About Pyramid"), 786 self.tr("About Pyramid"),
790 buttons=E5MessageBox.Ok) 798 buttons=E5MessageBox.Ok)
791 msgBox.setIconPixmap(UI.PixmapCache.getPixmap( 799 msgBox.setIconPixmap(UI.PixmapCache.getPixmap(
792 os.path.join("ProjectPyramid", "icons", "pyramid64.png"))) 800 os.path.join("ProjectPyramid", "icons", "pyramid64.png")))
793 msgBox.exec_() 801 msgBox.exec_()
794 802
795 def getPyramidVersion(self): 803 def getPyramidVersionString(self):
796 """ 804 """
797 Public method to get the Pyramid version. 805 Public method to get the Pyramid version as a string.
798 806
799 @return Pyramid version (string) 807 @return Pyramid version
808 @rtype str
800 """ 809 """
801 if not self.__pyramidVersion: 810 if not self.__pyramidVersion:
802 cmd = self.getPyramidCommand("pcreate") 811 cmd = self.getPyramidCommand("pcreate")
803 if isWindowsPlatform(): 812 if isWindowsPlatform():
804 cmd = os.path.join(os.path.dirname(cmd), "pcreate-script.py") 813 cmd = os.path.join(os.path.dirname(cmd), "pcreate-script.py")
814 except (IOError, OSError): 823 except (IOError, OSError):
815 self.__pyramidVersion = "" 824 self.__pyramidVersion = ""
816 825
817 return self.__pyramidVersion 826 return self.__pyramidVersion
818 827
828 def getPyramidVersion(self):
829 """
830 Public method to get the Pyramid version as a tuple.
831
832 @return Pyramid version
833 @rtype tuple of int
834 """
835 pyramidVersionStr = self.getPyramidVersionString()
836 pyramidVersionList = []
837 if pyramidVersionStr:
838 for part in pyramidVersionStr.split("."):
839 try:
840 pyramidVersionList.append(int(part))
841 except ValueError:
842 pyramidVersionList.append(part)
843
844 return tuple(pyramidVersionList)
845
819 def isSpawningConsole(self, consoleCmd): 846 def isSpawningConsole(self, consoleCmd):
820 """ 847 """
821 Public method to check, if the given console is a spawning console. 848 Public method to check, if the given console is a spawning console.
822 849
823 @param consoleCmd console command (string) 850 @param consoleCmd console command (string)
828 if consoleCmd and consoleCmd[0] == '@': 855 if consoleCmd and consoleCmd[0] == '@':
829 return (True, consoleCmd[1:]) 856 return (True, consoleCmd[1:])
830 else: 857 else:
831 return (False, consoleCmd) 858 return (False, consoleCmd)
832 859
860 def __adjustWorkingDirectory(self, args, wd):
861 """
862 Private method to adjust the working directory in the arguments list.
863
864 @param args list of arguments to be modified
865 @type list of str
866 @param wd working directory
867 @type str
868 """
869 if args[0].endswith("konsole") and "--workdir" in args:
870 index = args.index("--workdir")
871 args[index + 1] = wd
872 elif args[0].endswith(("gnome-terminal", "mate-terminal")):
873 for index in range(len(args)):
874 if args[index].startswith("--working-directory="):
875 args[index] = "--working-directory={0}".format(wd)
876 break
877
833 ################################################################## 878 ##################################################################
834 ## slots below implement creation functions 879 ## slots below implement creation functions
835 ################################################################## 880 ##################################################################
836 881
837 def __createProject(self): 882 def __createProject(self):
1094 config.read(os.path.join(projectPath, "development.ini")) 1139 config.read(os.path.join(projectPath, "development.ini"))
1095 try: 1140 try:
1096 port = config.get("server:main", "port") 1141 port = config.get("server:main", "port")
1097 except (configparser.NoOptionError, configparser.NoSectionError): 1142 except (configparser.NoOptionError, configparser.NoSectionError):
1098 port = "8080" 1143 port = "8080"
1099 url = QUrl("http://localhost:{0}".format(port)) 1144 url = "http://localhost:{0}".format(port)
1100 res = QDesktopServices.openUrl(url) 1145 if self.__plugin.getPreferences("UseExternalBrowser"):
1101 if not res: 1146 res = QDesktopServices.openUrl(QUrl(url))
1102 E5MessageBox.critical( 1147 if not res:
1103 self.__ui, 1148 E5MessageBox.critical(
1104 self.tr('Run Web-Browser'), 1149 self.__ui,
1105 self.tr('Could not start the web-browser for the URL' 1150 self.tr('Run Web-Browser'),
1106 ' "{0}".').format(url.toString())) 1151 self.tr('Could not start the web-browser for the URL'
1152 ' "{0}".').format(url.toString()))
1153 else:
1154 self.__ui.launchHelpViewer(url)
1107 1155
1108 def __runPythonShell(self): 1156 def __runPythonShell(self):
1109 """ 1157 """
1110 Private slot to start a Python console for a Pyramid project. 1158 Private slot to start a Python console for a Pyramid project.
1111 """ 1159 """
1133 consoleType = self.__plugin.getPreferences( 1181 consoleType = self.__plugin.getPreferences(
1134 "Python3ConsoleType") 1182 "Python3ConsoleType")
1135 args.append("--python-shell={0}".format(consoleType)) 1183 args.append("--python-shell={0}".format(consoleType))
1136 args.append(os.path.join(projectPath, "development.ini")) 1184 args.append(os.path.join(projectPath, "development.ini"))
1137 1185
1186 self.__adjustWorkingDirectory(args, projectPath)
1138 started, pid = QProcess.startDetached( 1187 started, pid = QProcess.startDetached(
1139 args[0], args[1:], projectPath) 1188 args[0], args[1:], projectPath)
1140 if not started: 1189 if not started:
1141 E5MessageBox.critical( 1190 E5MessageBox.critical(
1142 self.__ui, 1191 self.__ui,

eric ide

mercurial