ProjectPyramid/Project.py

changeset 54
71c83a661c83
parent 48
c313efdb01de
child 57
e654970c913e
equal deleted inserted replaced
53:a3ba38d3a25e 54:71c83a661c83
10 import os 10 import os
11 import configparser 11 import configparser
12 import re 12 import re
13 13
14 from PyQt4.QtCore import QObject, QFileInfo, QProcess, QTimer, QUrl 14 from PyQt4.QtCore import QObject, QFileInfo, QProcess, QTimer, QUrl
15 from PyQt4.QtGui import QMenu, QDialog, QInputDialog, QDesktopServices, QLineEdit 15 from PyQt4.QtGui import QMenu, QDialog, QInputDialog, QDesktopServices, \
16 QLineEdit
16 17
17 from E5Gui.E5Application import e5App 18 from E5Gui.E5Application import e5App
18 from E5Gui import E5MessageBox, E5FileDialog 19 from E5Gui import E5MessageBox, E5FileDialog
19 from E5Gui.E5Action import E5Action 20 from E5Gui.E5Action import E5Action
20 21
60 """ 61 """
61 Public method to define the Pyramid actions. 62 Public method to define the Pyramid actions.
62 """ 63 """
63 self.actions = [] 64 self.actions = []
64 65
65 self.selectProjectAct = E5Action(self.trUtf8('Current Pyramid Project'), 66 self.selectProjectAct = E5Action(
66 "", 67 self.trUtf8('Current Pyramid Project'),
67 0, 0, 68 "",
68 self, 'pyramid_current_project') 69 0, 0,
70 self, 'pyramid_current_project')
69 self.selectProjectAct.setStatusTip(self.trUtf8( 71 self.selectProjectAct.setStatusTip(self.trUtf8(
70 'Selects the current Pyramid project')) 72 'Selects the current Pyramid project'))
71 self.selectProjectAct.setWhatsThis(self.trUtf8( 73 self.selectProjectAct.setWhatsThis(self.trUtf8(
72 """<b>Current Pyramid Project</b>""" 74 """<b>Current Pyramid Project</b>"""
73 """<p>Selects the Pyramid project. Used for multi-project """ 75 """<p>Selects the Pyramid project. Used for multi-project """
78 80
79 ############################### 81 ###############################
80 ## create actions below ## 82 ## create actions below ##
81 ############################### 83 ###############################
82 84
83 self.createProjectAct = E5Action(self.trUtf8('Create Pyramid Project'), 85 self.createProjectAct = E5Action(
84 self.trUtf8('Create Pyramid &Project'), 86 self.trUtf8('Create Pyramid Project'),
85 0, 0, 87 self.trUtf8('Create Pyramid &Project'),
86 self, 'pyramid_create_project') 88 0, 0,
89 self, 'pyramid_create_project')
87 self.createProjectAct.setStatusTip(self.trUtf8( 90 self.createProjectAct.setStatusTip(self.trUtf8(
88 'Creates a new Pyramid project')) 91 'Creates a new Pyramid project'))
89 self.createProjectAct.setWhatsThis(self.trUtf8( 92 self.createProjectAct.setWhatsThis(self.trUtf8(
90 """<b>Create Pyramid Project</b>""" 93 """<b>Create Pyramid Project</b>"""
91 """<p>Creates a new Pyramid project using "pcreate".</p>""" 94 """<p>Creates a new Pyramid project using "pcreate".</p>"""
95 98
96 ############################## 99 ##############################
97 ## run actions below ## 100 ## run actions below ##
98 ############################## 101 ##############################
99 102
100 self.runServerAct = E5Action(self.trUtf8('Run Server'), 103 self.runServerAct = E5Action(
101 self.trUtf8('Run &Server'), 104 self.trUtf8('Run Server'),
102 0, 0, 105 self.trUtf8('Run &Server'),
103 self, 'pyramid_run_server') 106 0, 0,
107 self, 'pyramid_run_server')
104 self.runServerAct.setStatusTip(self.trUtf8( 108 self.runServerAct.setStatusTip(self.trUtf8(
105 'Starts the Pyramid Web server')) 109 'Starts the Pyramid Web server'))
106 self.runServerAct.setWhatsThis(self.trUtf8( 110 self.runServerAct.setWhatsThis(self.trUtf8(
107 """<b>Run Server</b>""" 111 """<b>Run Server</b>"""
108 """<p>Starts the Pyramid Web server using""" 112 """<p>Starts the Pyramid Web server using"""
109 """ "pserve --reload development.ini".</p>""" 113 """ "pserve --reload development.ini".</p>"""
110 )) 114 ))
111 self.runServerAct.triggered[()].connect(self.__runServer) 115 self.runServerAct.triggered[()].connect(self.__runServer)
112 self.actions.append(self.runServerAct) 116 self.actions.append(self.runServerAct)
113 117
114 self.runLoggingServerAct = E5Action(self.trUtf8('Run Server with Logging'), 118 self.runLoggingServerAct = E5Action(
115 self.trUtf8('Run Server with &Logging'), 119 self.trUtf8('Run Server with Logging'),
116 0, 0, 120 self.trUtf8('Run Server with &Logging'),
117 self, 'pyramid_run_logging_server') 121 0, 0,
122 self, 'pyramid_run_logging_server')
118 self.runLoggingServerAct.setStatusTip(self.trUtf8( 123 self.runLoggingServerAct.setStatusTip(self.trUtf8(
119 'Starts the Pyramid Web server with logging')) 124 'Starts the Pyramid Web server with logging'))
120 self.runLoggingServerAct.setWhatsThis(self.trUtf8( 125 self.runLoggingServerAct.setWhatsThis(self.trUtf8(
121 """<b>Run Server with Logging</b>""" 126 """<b>Run Server with Logging</b>"""
122 """<p>Starts the Pyramid Web server with logging using""" 127 """<p>Starts the Pyramid Web server with logging using"""
123 """ "pserve --log-file=server.log --reload development.ini".</p>""" 128 """ "pserve --log-file=server.log --reload development.ini".</p>"""
124 )) 129 ))
125 self.runLoggingServerAct.triggered[()].connect(self.__runLoggingServer) 130 self.runLoggingServerAct.triggered[()].connect(self.__runLoggingServer)
126 self.actions.append(self.runLoggingServerAct) 131 self.actions.append(self.runLoggingServerAct)
127 132
128 self.runBrowserAct = E5Action(self.trUtf8('Run Web-Browser'), 133 self.runBrowserAct = E5Action(
129 self.trUtf8('Run &Web-Browser'), 134 self.trUtf8('Run Web-Browser'),
130 0, 0, 135 self.trUtf8('Run &Web-Browser'),
131 self, 'pyramid_run_browser') 136 0, 0,
137 self, 'pyramid_run_browser')
132 self.runBrowserAct.setStatusTip(self.trUtf8( 138 self.runBrowserAct.setStatusTip(self.trUtf8(
133 'Starts the default Web-Browser with the URL of the Pyramid Web server')) 139 'Starts the default Web-Browser with the URL of the Pyramid Web'
140 ' server'))
134 self.runBrowserAct.setWhatsThis(self.trUtf8( 141 self.runBrowserAct.setWhatsThis(self.trUtf8(
135 """<b>Run Web-Browser</b>""" 142 """<b>Run Web-Browser</b>"""
136 """<p>Starts the default Web-Browser with the URL of the """ 143 """<p>Starts the default Web-Browser with the URL of the """
137 """Pyramid Web server.</p>""" 144 """Pyramid Web server.</p>"""
138 )) 145 ))
139 self.runBrowserAct.triggered[()].connect(self.__runBrowser) 146 self.runBrowserAct.triggered[()].connect(self.__runBrowser)
140 self.actions.append(self.runBrowserAct) 147 self.actions.append(self.runBrowserAct)
141 148
142 self.runPythonShellAct = E5Action(self.trUtf8('Start Pyramid Python Console'), 149 self.runPythonShellAct = E5Action(
143 self.trUtf8('Start Pyramid &Python Console'), 150 self.trUtf8('Start Pyramid Python Console'),
144 0, 0, 151 self.trUtf8('Start Pyramid &Python Console'),
145 self, 'pyramid_python_console') 152 0, 0,
153 self, 'pyramid_python_console')
146 self.runPythonShellAct.setStatusTip(self.trUtf8( 154 self.runPythonShellAct.setStatusTip(self.trUtf8(
147 'Starts an interactive Python interpreter')) 155 'Starts an interactive Python interpreter'))
148 self.runPythonShellAct.setWhatsThis(self.trUtf8( 156 self.runPythonShellAct.setWhatsThis(self.trUtf8(
149 """<b>Start Pyramid Python Console</b>""" 157 """<b>Start Pyramid Python Console</b>"""
150 """<p>Starts an interactive Python interpreter.</p>""" 158 """<p>Starts an interactive Python interpreter.</p>"""
154 162
155 ############################## 163 ##############################
156 ## setup actions below ## 164 ## setup actions below ##
157 ############################## 165 ##############################
158 166
159 self.setupDevelopAct = E5Action(self.trUtf8('Setup Development Environment'), 167 self.setupDevelopAct = E5Action(
160 self.trUtf8('Setup &Development Environment'), 168 self.trUtf8('Setup Development Environment'),
161 0, 0, 169 self.trUtf8('Setup &Development Environment'),
162 self, 'pyramid_setup_development') 170 0, 0,
171 self, 'pyramid_setup_development')
163 self.setupDevelopAct.setStatusTip(self.trUtf8( 172 self.setupDevelopAct.setStatusTip(self.trUtf8(
164 'Setup the Pyramid project in development mode')) 173 'Setup the Pyramid project in development mode'))
165 self.setupDevelopAct.setWhatsThis(self.trUtf8( 174 self.setupDevelopAct.setWhatsThis(self.trUtf8(
166 """<b>Setup Development Environment</b>""" 175 """<b>Setup Development Environment</b>"""
167 """<p>Setup the Pyramid project in development mode using""" 176 """<p>Setup the Pyramid project in development mode using"""
172 181
173 ############################### 182 ###############################
174 ## database actions below ## 183 ## database actions below ##
175 ############################### 184 ###############################
176 185
177 self.initializeDbAct = E5Action(self.trUtf8('Initialize Database'), 186 self.initializeDbAct = E5Action(
178 self.trUtf8('Initialize &Database'), 187 self.trUtf8('Initialize Database'),
179 0, 0, 188 self.trUtf8('Initialize &Database'),
180 self, 'pyramid_initialize_database') 189 0, 0,
190 self, 'pyramid_initialize_database')
181 self.initializeDbAct.setStatusTip(self.trUtf8( 191 self.initializeDbAct.setStatusTip(self.trUtf8(
182 'Initializes (or re-initializes) the database of the current' 192 'Initializes (or re-initializes) the database of the current'
183 ' Pyramid project')) 193 ' Pyramid project'))
184 self.initializeDbAct.setWhatsThis(self.trUtf8( 194 self.initializeDbAct.setWhatsThis(self.trUtf8(
185 """<b>Initialize Database</b>""" 195 """<b>Initialize Database</b>"""
186 """<p>Initializes (or re-initializes) the database of the current""" 196 """<p>Initializes (or re-initializes) the database of the"""
187 """ Pyramid project.</p>""" 197 """ current Pyramid project.</p>"""
188 )) 198 ))
189 self.initializeDbAct.triggered[()].connect(self.__initializeDatabase) 199 self.initializeDbAct.triggered[()].connect(self.__initializeDatabase)
190 self.actions.append(self.initializeDbAct) 200 self.actions.append(self.initializeDbAct)
191 201
192 ############################### 202 ###############################
193 ## show actions below ## 203 ## show actions below ##
194 ############################### 204 ###############################
195 205
196 self.showViewsAct = E5Action(self.trUtf8('Show Matching Views'), 206 self.showViewsAct = E5Action(
197 self.trUtf8('Show Matching &Views'), 207 self.trUtf8('Show Matching Views'),
198 0, 0, 208 self.trUtf8('Show Matching &Views'),
199 self, 'pyramid_show_views') 209 0, 0,
210 self, 'pyramid_show_views')
200 self.showViewsAct.setStatusTip(self.trUtf8( 211 self.showViewsAct.setStatusTip(self.trUtf8(
201 'Show views matching a given URL')) 212 'Show views matching a given URL'))
202 self.showViewsAct.setWhatsThis(self.trUtf8( 213 self.showViewsAct.setWhatsThis(self.trUtf8(
203 """<b>Show Matching Views</b>""" 214 """<b>Show Matching Views</b>"""
204 """<p>Show views matching a given URL.</p>""" 215 """<p>Show views matching a given URL.</p>"""
205 )) 216 ))
206 self.showViewsAct.triggered[()].connect(self.__showMatchingViews) 217 self.showViewsAct.triggered[()].connect(self.__showMatchingViews)
207 self.actions.append(self.showViewsAct) 218 self.actions.append(self.showViewsAct)
208 219
209 self.showRoutesAct = E5Action(self.trUtf8('Show Routes'), 220 self.showRoutesAct = E5Action(
210 self.trUtf8('Show &Routes'), 221 self.trUtf8('Show Routes'),
211 0, 0, 222 self.trUtf8('Show &Routes'),
212 self, 'pyramid_show_routes') 223 0, 0,
224 self, 'pyramid_show_routes')
213 self.showRoutesAct.setStatusTip(self.trUtf8( 225 self.showRoutesAct.setStatusTip(self.trUtf8(
214 'Show all URL dispatch routes used by a Pyramid application')) 226 'Show all URL dispatch routes used by a Pyramid application'))
215 self.showRoutesAct.setWhatsThis(self.trUtf8( 227 self.showRoutesAct.setWhatsThis(self.trUtf8(
216 """<b>Show Routes</b>""" 228 """<b>Show Routes</b>"""
217 """<p>Show all URL dispatch routes used by a Pyramid application""" 229 """<p>Show all URL dispatch routes used by a Pyramid application"""
218 """ in the order in which they are evaluated.</p>""" 230 """ in the order in which they are evaluated.</p>"""
219 )) 231 ))
220 self.showRoutesAct.triggered[()].connect(self.__showRoutes) 232 self.showRoutesAct.triggered[()].connect(self.__showRoutes)
221 self.actions.append(self.showRoutesAct) 233 self.actions.append(self.showRoutesAct)
222 234
223 self.showTweensAct = E5Action(self.trUtf8('Show Tween Objects'), 235 self.showTweensAct = E5Action(
224 self.trUtf8('Show &Tween Objects'), 236 self.trUtf8('Show Tween Objects'),
225 0, 0, 237 self.trUtf8('Show &Tween Objects'),
226 self, 'pyramid_show_routes') 238 0, 0,
239 self, 'pyramid_show_routes')
227 self.showTweensAct.setStatusTip(self.trUtf8( 240 self.showTweensAct.setStatusTip(self.trUtf8(
228 'Show all implicit and explicit tween objects used by a Pyramid application')) 241 'Show all implicit and explicit tween objects used by a Pyramid'
242 ' application'))
229 self.showTweensAct.setWhatsThis(self.trUtf8( 243 self.showTweensAct.setWhatsThis(self.trUtf8(
230 """<b>Show Tween Objects</b>""" 244 """<b>Show Tween Objects</b>"""
231 """<p>Show all implicit and explicit tween objects used by a""" 245 """<p>Show all implicit and explicit tween objects used by a"""
232 """ Pyramid application.</p>""" 246 """ Pyramid application.</p>"""
233 )) 247 ))
236 250
237 ################################## 251 ##################################
238 ## distribution actions below ## 252 ## distribution actions below ##
239 ################################## 253 ##################################
240 254
241 self.buildDistroAct = E5Action(self.trUtf8('Build Distribution'), 255 self.buildDistroAct = E5Action(
242 self.trUtf8('Build &Distribution'), 256 self.trUtf8('Build Distribution'),
243 0, 0, 257 self.trUtf8('Build &Distribution'),
244 self, 'pyramid_build_distribution') 258 0, 0,
259 self, 'pyramid_build_distribution')
245 self.buildDistroAct.setStatusTip(self.trUtf8( 260 self.buildDistroAct.setStatusTip(self.trUtf8(
246 'Builds a distribution file for the Pyramid project')) 261 'Builds a distribution file for the Pyramid project'))
247 self.buildDistroAct.setWhatsThis(self.trUtf8( 262 self.buildDistroAct.setWhatsThis(self.trUtf8(
248 """<b>Build Distribution</b>""" 263 """<b>Build Distribution</b>"""
249 """<p>Builds a distribution file for the Pyramid project using""" 264 """<p>Builds a distribution file for the Pyramid project using"""
254 269
255 ################################## 270 ##################################
256 ## documentation action below ## 271 ## documentation action below ##
257 ################################## 272 ##################################
258 273
259 self.documentationAct = E5Action(self.trUtf8('Documentation'), 274 self.documentationAct = E5Action(
260 self.trUtf8('D&ocumentation'), 275 self.trUtf8('Documentation'),
261 0, 0, 276 self.trUtf8('D&ocumentation'),
262 self, 'pyramid_documentation') 277 0, 0,
278 self, 'pyramid_documentation')
263 self.documentationAct.setStatusTip(self.trUtf8( 279 self.documentationAct.setStatusTip(self.trUtf8(
264 'Shows the help viewer with the Pyramid documentation')) 280 'Shows the help viewer with the Pyramid documentation'))
265 self.documentationAct.setWhatsThis(self.trUtf8( 281 self.documentationAct.setWhatsThis(self.trUtf8(
266 """<b>Documentation</b>""" 282 """<b>Documentation</b>"""
267 """<p>Shows the help viewer with the Pyramid documentation.</p>""" 283 """<p>Shows the help viewer with the Pyramid documentation.</p>"""
271 287
272 ############################## 288 ##############################
273 ## about action below ## 289 ## about action below ##
274 ############################## 290 ##############################
275 291
276 self.aboutPyramidAct = E5Action(self.trUtf8('About Pyramid'), 292 self.aboutPyramidAct = E5Action(
277 self.trUtf8('About P&yramid'), 293 self.trUtf8('About Pyramid'),
278 0, 0, 294 self.trUtf8('About P&yramid'),
279 self, 'pyramid_about') 295 0, 0,
296 self, 'pyramid_about')
280 self.aboutPyramidAct.setStatusTip(self.trUtf8( 297 self.aboutPyramidAct.setStatusTip(self.trUtf8(
281 'Shows some information about Pyramid')) 298 'Shows some information about Pyramid'))
282 self.aboutPyramidAct.setWhatsThis(self.trUtf8( 299 self.aboutPyramidAct.setWhatsThis(self.trUtf8(
283 """<b>About Pyramid</b>""" 300 """<b>About Pyramid</b>"""
284 """<p>Shows some information about Pyramid.</p>""" 301 """<p>Shows some information about Pyramid.</p>"""
331 """ 348 """
332 if self.__hooksInstalled: 349 if self.__hooksInstalled:
333 editor = self.__plugin.getPreferences("TranslationsEditor") 350 editor = self.__plugin.getPreferences("TranslationsEditor")
334 try: 351 try:
335 if editor: 352 if editor:
336 self.__translationsBrowser.addHookMethodAndMenuEntry("open", 353 self.__translationsBrowser.addHookMethodAndMenuEntry(
337 self.openPOEditor, 354 "open", self.openPOEditor,
338 self.trUtf8("Open with {0}").format(os.path.basename(editor))) 355 self.trUtf8("Open with {0}").format(
356 os.path.basename(editor)))
339 else: 357 else:
340 self.__translationsBrowser.removeHookMethod("open") 358 self.__translationsBrowser.removeHookMethod("open")
341 except KeyError: 359 except KeyError:
342 # ignore for older eric5 versions 360 # ignore for older eric5 versions
343 pass 361 pass
347 Public method to add our hook methods. 365 Public method to add our hook methods.
348 """ 366 """
349 if self.__e5project.getProjectType() == "Pyramid": 367 if self.__e5project.getProjectType() == "Pyramid":
350 self.__formsBrowser = \ 368 self.__formsBrowser = \
351 e5App().getObject("ProjectBrowser").getProjectBrowser("forms") 369 e5App().getObject("ProjectBrowser").getProjectBrowser("forms")
352 self.__formsBrowser.addHookMethodAndMenuEntry("newForm", 370 self.__formsBrowser.addHookMethodAndMenuEntry(
353 self.newForm, self.trUtf8("New template...")) 371 "newForm", self.newForm, self.trUtf8("New template..."))
354 372
355 if self.__e5project.getProjectLanguage() == "Python2": 373 if self.__e5project.getProjectLanguage() == "Python2":
356 # Babel and lingua are not yet available for Python 3 374 # Babel and lingua are not yet available for Python 3
357 self.__e5project.projectLanguageAddedByCode.connect( 375 self.__e5project.projectLanguageAddedByCode.connect(
358 self.__projectLanguageAdded) 376 self.__projectLanguageAdded)
359 self.__translationsBrowser = \ 377 self.__translationsBrowser = \
360 e5App().getObject("ProjectBrowser").getProjectBrowser("translations") 378 e5App().getObject("ProjectBrowser")\
361 self.__translationsBrowser.addHookMethodAndMenuEntry("extractMessages", 379 .getProjectBrowser("translations")
362 self.extractMessages, self.trUtf8("Extract Messages")) 380 self.__translationsBrowser.addHookMethodAndMenuEntry(
363 self.__translationsBrowser.addHookMethodAndMenuEntry("releaseAll", 381 "extractMessages", self.extractMessages,
364 self.compileCatalogs, self.trUtf8("Compile All Catalogs")) 382 self.trUtf8("Extract Messages"))
365 self.__translationsBrowser.addHookMethodAndMenuEntry("releaseSelected", 383 self.__translationsBrowser.addHookMethodAndMenuEntry(
366 self.compileSelectedCatalogs, 384 "releaseAll", self.compileCatalogs,
385 self.trUtf8("Compile All Catalogs"))
386 self.__translationsBrowser.addHookMethodAndMenuEntry(
387 "releaseSelected", self.compileSelectedCatalogs,
367 self.trUtf8("Compile Selected Catalogs")) 388 self.trUtf8("Compile Selected Catalogs"))
368 self.__translationsBrowser.addHookMethodAndMenuEntry("generateAll", 389 self.__translationsBrowser.addHookMethodAndMenuEntry(
369 self.updateCatalogs, self.trUtf8("Update All Catalogs")) 390 "generateAll", self.updateCatalogs,
370 self.__translationsBrowser.addHookMethodAndMenuEntry("generateSelected", 391 self.trUtf8("Update All Catalogs"))
371 self.updateSelectedCatalogs, self.trUtf8("Update Selected Catalogs")) 392 self.__translationsBrowser.addHookMethodAndMenuEntry(
393 "generateSelected", self.updateSelectedCatalogs,
394 self.trUtf8("Update Selected Catalogs"))
372 395
373 self.__hooksInstalled = True 396 self.__hooksInstalled = True
374 397
375 self.registerOpenHook() 398 self.registerOpenHook()
376 399
431 ex = selectedFilter.split("(*")[1].split(")")[0] 454 ex = selectedFilter.split("(*")[1].split(")")[0]
432 if ex: 455 if ex:
433 fname += ex 456 fname += ex
434 457
435 if os.path.exists(fname): 458 if os.path.exists(fname):
436 res = E5MessageBox.yesNo(self.__ui, 459 res = E5MessageBox.yesNo(
460 self.__ui,
437 self.trUtf8("New Form"), 461 self.trUtf8("New Form"),
438 self.trUtf8("""The file already exists! Overwrite it?"""), 462 self.trUtf8("""The file already exists! Overwrite"""
463 """ it?"""),
439 icon=E5MessageBox.Warning) 464 icon=E5MessageBox.Warning)
440 if not res: 465 if not res:
441 # user selected to not overwrite 466 # user selected to not overwrite
442 return 467 return
443 468
444 try: 469 try:
445 f = open(fname, "w", encoding="utf-8") 470 f = open(fname, "w", encoding="utf-8")
446 f.write(template) 471 f.write(template)
447 f.close() 472 f.close()
448 except IOError as e: 473 except IOError as e:
449 E5MessageBox.critical(self, 474 E5MessageBox.critical(
475 self.__ui,
450 self.trUtf8("New Form"), 476 self.trUtf8("New Form"),
451 self.trUtf8("<p>The new form file <b>{0}</b> could not be" 477 self.trUtf8("<p>The new form file <b>{0}</b> could"
452 " created.<br/>" 478 " not be created.<br/> Problem: {1}</p>")
453 "Problem: {1}</p>").format(fname, e)) 479 .format(fname, e))
454 return 480 return
455 481
456 self.__e5project.appendFile(fname) 482 self.__e5project.appendFile(fname)
457 self.__formsBrowser.sourceFile.emit(fname) 483 self.__formsBrowser.sourceFile.emit(fname)
458 484
472 """ 498 """
473 Private method to build all full path of an executable file from 499 Private method to build all full path of an executable file from
474 the environment. 500 the environment.
475 501
476 @param file filename of the executable (string) 502 @param file filename of the executable (string)
477 @return list of full executable names, if the executable file is accessible 503 @return list of full executable names, if the executable file is
478 via the searchpath defined by the PATH environment variable, or an 504 accessible via the searchpath defined by the PATH environment
479 empty list otherwise. 505 variable, or an empty list otherwise.
480 """ 506 """
481 paths = [] 507 paths = []
482 508
483 if os.path.isabs(file): 509 if os.path.isabs(file):
484 if os.access(file, os.X_OK): 510 if os.access(file, os.X_OK):
530 f.close() 556 f.close()
531 except (IOError, OSError): 557 except (IOError, OSError):
532 l0 = "" 558 l0 = ""
533 if variant.lower() in l0.lower() or \ 559 if variant.lower() in l0.lower() or \
534 "{0}.".format(variant[-1]) in l0 or \ 560 "{0}.".format(variant[-1]) in l0 or \
535 (variant == "Python2" and \ 561 (variant == "Python2" and
536 "python3" not in l0.lower() and \ 562 "python3" not in l0.lower() and
537 "python" in l0.lower()): 563 "python" in l0.lower()):
538 variants.append(variant) 564 variants.append(variant)
539 break 565 break
540 566
541 return variants 567 return variants
542 568
616 Private slot to show some info about Pyramid. 642 Private slot to show some info about Pyramid.
617 """ 643 """
618 version = self.getPyramidVersion() 644 version = self.getPyramidVersion()
619 url = "http://www.pylonsproject.org/projects/pyramid/about" 645 url = "http://www.pylonsproject.org/projects/pyramid/about"
620 646
621 msgBox = E5MessageBox.E5MessageBox(E5MessageBox.Question, 647 msgBox = E5MessageBox.E5MessageBox(
648 E5MessageBox.Question,
622 self.trUtf8("About Pyramid"), 649 self.trUtf8("About Pyramid"),
623 self.trUtf8( 650 self.trUtf8(
624 "<p>Pyramid is a high-level Python Web framework that encourages rapid " 651 "<p>Pyramid is a high-level Python Web framework that"
625 "development and clean, pragmatic design.</p>" 652 " encourages rapid development and clean, pragmatic"
653 " design.</p>"
626 "<p><table>" 654 "<p><table>"
627 "<tr><td>Version:</td><td>{0}</td></tr>" 655 "<tr><td>Version:</td><td>{0}</td></tr>"
628 "<tr><td>URL:</td><td><a href=\"{1}\">" 656 "<tr><td>URL:</td><td><a href=\"{1}\">"
629 "{1}</a></td></tr>" 657 "{1}</a></td></tr>"
630 "</table></p>" 658 "</table></p>"
694 if simulate: 722 if simulate:
695 args.append("--simulate") 723 args.append("--simulate")
696 args.append("--scaffold={0}".format(scaffold)) 724 args.append("--scaffold={0}".format(scaffold))
697 args.append(project) 725 args.append(project)
698 dlg = PyramidDialog(self.trUtf8("Create Pyramid Project"), 726 dlg = PyramidDialog(self.trUtf8("Create Pyramid Project"),
699 linewrap=False, parent=self.__ui) 727 linewrap=False, parent=self.__ui)
700 if dlg.startProcess(cmd, args, self.__e5project.getProjectPath()): 728 if dlg.startProcess(cmd, args, self.__e5project.getProjectPath()):
701 dlg.exec_() 729 dlg.exec_()
702 if dlg.normalExit() and not simulate: 730 if dlg.normalExit() and not simulate:
703 # search for files created by pcreate and add them to the project 731 # search for files created by pcreate and add them to the
704 projectPath = os.path.join(self.__e5project.getProjectPath(), project) 732 # project
733 projectPath = os.path.join(
734 self.__e5project.getProjectPath(), project)
705 for entry in os.walk(projectPath): 735 for entry in os.walk(projectPath):
706 for fileName in entry[2]: 736 for fileName in entry[2]:
707 fullName = os.path.join(entry[0], fileName) 737 fullName = os.path.join(entry[0], fileName)
708 self.__e5project.appendFile(fullName) 738 self.__e5project.appendFile(fullName)
709 739
710 # create the base directory for translations 740 # create the base directory for translations
711 i18nPath = os.path.join(projectPath, project.lower(), "i18n") 741 i18nPath = os.path.join(
742 projectPath, project.lower(), "i18n")
712 if not os.path.exists(i18nPath): 743 if not os.path.exists(i18nPath):
713 os.makedirs(i18nPath) 744 os.makedirs(i18nPath)
714 self.__e5project.setDirty(True) 745 self.__e5project.setDirty(True)
715 746
716 self.__setCurrentProject(project) 747 self.__setCurrentProject(project)
735 return projects 766 return projects
736 767
737 def __selectProject(self): 768 def __selectProject(self):
738 """ 769 """
739 Private method to select a Pyramid project to work with. 770 Private method to select a Pyramid project to work with.
740
741 @return selected project (string)
742 """ 771 """
743 projects = self.__findProjects() 772 projects = self.__findProjects()
744 if len(projects) == 0: 773 if len(projects) == 0:
745 project = None 774 project = None
746 elif len(projects) == 1: 775 elif len(projects) == 1:
765 794
766 def __projectPath(self): 795 def __projectPath(self):
767 """ 796 """
768 Private method to calculate the full path of the Pyramid project. 797 Private method to calculate the full path of the Pyramid project.
769 798
770 @exception PyramidNoProjectSelectedException raised, if no project is selected 799 @exception PyramidNoProjectSelectedException raised, if no project is
800 selected
771 @return path of the project (string) 801 @return path of the project (string)
772 """ 802 """
773 if self.__currentProject is None: 803 if self.__currentProject is None:
774 self.__selectProject() 804 self.__selectProject()
775 805
804 config.read(os.path.join(self.__projectPath(), "setup.cfg")) 834 config.read(os.path.join(self.__projectPath(), "setup.cfg"))
805 outputDir = config.get("init_catalog", "output_dir") 835 outputDir = config.get("init_catalog", "output_dir")
806 domain = config.get("init_catalog", "domain") 836 domain = config.get("init_catalog", "domain")
807 self.__e5project.pdata["TRANSLATIONPATTERN"] = [ 837 self.__e5project.pdata["TRANSLATIONPATTERN"] = [
808 os.path.join(project, outputDir, "%language%", 838 os.path.join(project, outputDir, "%language%",
809 "LC_MESSAGES", "{0}.po".format(domain)) 839 "LC_MESSAGES", "{0}.po".format(domain))
810 ] 840 ]
811 841
812 if self.__currentProject is None: 842 if self.__currentProject is None:
813 self.initializeDbAct.setEnabled(False) 843 self.initializeDbAct.setEnabled(False)
814 else: 844 else:
817 847
818 def __project(self): 848 def __project(self):
819 """ 849 """
820 Private method to get the name of the current Pyramid project. 850 Private method to get the name of the current Pyramid project.
821 851
822 @exception PyramidNoProjectSelectedException raised, if no project is selected 852 @exception PyramidNoProjectSelectedException raised, if no project is
853 selected
823 @return name of the project (string) 854 @return name of the project (string)
824 """ 855 """
825 if self.__currentProject is None: 856 if self.__currentProject is None:
826 self.__selectProject() 857 self.__selectProject()
827 858
844 self.__plugin.getPreferences("ConsoleCommand"))[1] 875 self.__plugin.getPreferences("ConsoleCommand"))[1]
845 if consoleCmd: 876 if consoleCmd:
846 try: 877 try:
847 projectPath = self.__projectPath() 878 projectPath = self.__projectPath()
848 except PyramidNoProjectSelectedException: 879 except PyramidNoProjectSelectedException:
849 E5MessageBox.warning(self.__ui, 880 E5MessageBox.warning(
881 self.__ui,
850 self.trUtf8('Run Server'), 882 self.trUtf8('Run Server'),
851 self.trUtf8('No current Pyramid project selected or no Pyramid ' 883 self.trUtf8('No current Pyramid project selected or no'
852 'project created yet. Aborting...')) 884 ' Pyramid project created yet. Aborting...'))
853 return 885 return
854 886
855 args = Utilities.parseOptionString(consoleCmd) 887 args = Utilities.parseOptionString(consoleCmd)
856 args[0] = Utilities.getExecutablePath(args[0]) 888 args[0] = Utilities.getExecutablePath(args[0])
857 args.append(self.getPyramidCommand("pserve")) 889 args.append(self.getPyramidCommand("pserve"))
871 self.__serverProc.finished.connect(self.__serverProcFinished) 903 self.__serverProc.finished.connect(self.__serverProcFinished)
872 self.__serverProc.setWorkingDirectory(projectPath) 904 self.__serverProc.setWorkingDirectory(projectPath)
873 self.__serverProc.start(args[0], args[1:]) 905 self.__serverProc.start(args[0], args[1:])
874 serverProcStarted = self.__serverProc.waitForStarted() 906 serverProcStarted = self.__serverProc.waitForStarted()
875 if not serverProcStarted: 907 if not serverProcStarted:
876 E5MessageBox.critical(self.__ui, 908 E5MessageBox.critical(
909 self.__ui,
877 self.trUtf8('Process Generation Error'), 910 self.trUtf8('Process Generation Error'),
878 self.trUtf8('The Pyramid server could not be started.')) 911 self.trUtf8('The Pyramid server could not be started.'))
879 912
880 def __runLoggingServer(self): 913 def __runLoggingServer(self):
881 """ 914 """
899 Private slot to start the default web browser with the server URL. 932 Private slot to start the default web browser with the server URL.
900 """ 933 """
901 try: 934 try:
902 projectPath = self.__projectPath() 935 projectPath = self.__projectPath()
903 except PyramidNoProjectSelectedException: 936 except PyramidNoProjectSelectedException:
904 E5MessageBox.warning(self.__ui, 937 E5MessageBox.warning(
938 self.__ui,
905 self.trUtf8('Run Web-Browser'), 939 self.trUtf8('Run Web-Browser'),
906 self.trUtf8('No current Pyramid project selected or no Pyramid project' 940 self.trUtf8('No current Pyramid project selected or no Pyramid'
907 ' created yet. Aborting...')) 941 ' project created yet. Aborting...'))
908 return 942 return
909 943
910 config = configparser.ConfigParser() 944 config = configparser.ConfigParser()
911 config.read(os.path.join(projectPath, "development.ini")) 945 config.read(os.path.join(projectPath, "development.ini"))
912 port = config.get("server:main", "port", fallback="6543") 946 port = config.get("server:main", "port", fallback="6543")
913 url = QUrl("http://localhost:{0}".format(port)) 947 url = QUrl("http://localhost:{0}".format(port))
914 res = QDesktopServices.openUrl(url) 948 res = QDesktopServices.openUrl(url)
915 if not res: 949 if not res:
916 E5MessageBox.critical(self.__ui, 950 E5MessageBox.critical(
951 self.__ui,
917 self.trUtf8('Run Web-Browser'), 952 self.trUtf8('Run Web-Browser'),
918 self.trUtf8('Could not start the web-browser for the URL "{0}".')\ 953 self.trUtf8('Could not start the web-browser for the URL'
919 .format(url.toString())) 954 ' "{0}".').format(url.toString()))
920 955
921 def __runPythonShell(self): 956 def __runPythonShell(self):
922 """ 957 """
923 Private slot to start a Python console for a Pyramid project. 958 Private slot to start a Python console for a Pyramid project.
924 """ 959 """
926 self.__plugin.getPreferences("ConsoleCommand"))[1] 961 self.__plugin.getPreferences("ConsoleCommand"))[1]
927 if consoleCmd: 962 if consoleCmd:
928 try: 963 try:
929 projectPath = self.__projectPath() 964 projectPath = self.__projectPath()
930 except PyramidNoProjectSelectedException: 965 except PyramidNoProjectSelectedException:
931 E5MessageBox.warning(self.__ui, 966 E5MessageBox.warning(
967 self.__ui,
932 self.trUtf8('Start Pyramid Python Console'), 968 self.trUtf8('Start Pyramid Python Console'),
933 self.trUtf8('No current Pyramid project selected or no Pyramid ' 969 self.trUtf8('No current Pyramid project selected or no'
934 'project created yet. Aborting...')) 970 ' Pyramid project created yet. Aborting...'))
935 return 971 return
936 972
937 args = Utilities.parseOptionString(consoleCmd) 973 args = Utilities.parseOptionString(consoleCmd)
938 args[0] = Utilities.getExecutablePath(args[0]) 974 args[0] = Utilities.getExecutablePath(args[0])
939 args.append(self.getPyramidCommand("pshell")) 975 args.append(self.getPyramidCommand("pshell"))
940 language = self.__e5project.getProjectLanguage() 976 language = self.__e5project.getProjectLanguage()
941 if language == "Python2": 977 if language == "Python2":
942 consoleType = self.__plugin.getPreferences("Python2ConsoleType") 978 consoleType = self.__plugin.getPreferences(
979 "Python2ConsoleType")
943 else: 980 else:
944 consoleType = self.__plugin.getPreferences("Python3ConsoleType") 981 consoleType = self.__plugin.getPreferences(
982 "Python3ConsoleType")
945 args.append("--python-shell={0}".format(consoleType)) 983 args.append("--python-shell={0}".format(consoleType))
946 args.append(os.path.join(projectPath, "development.ini")) 984 args.append(os.path.join(projectPath, "development.ini"))
947 985
948 started, pid = QProcess.startDetached(args[0], args[1:], projectPath) 986 started, pid = QProcess.startDetached(
987 args[0], args[1:], projectPath)
949 if not started: 988 if not started:
950 E5MessageBox.critical(self.__ui, 989 E5MessageBox.critical(
990 self.__ui,
951 self.trUtf8('Process Generation Error'), 991 self.trUtf8('Process Generation Error'),
952 self.trUtf8('The Pyramid Shell process could not be started.')) 992 self.trUtf8('The Pyramid Shell process could not be'
993 ' started.'))
953 994
954 ################################################################## 995 ##################################################################
955 ## slots below implement setup functions 996 ## slots below implement setup functions
956 ################################################################## 997 ##################################################################
957 998
958 def __setupDevelop(self): 999 def __setupDevelop(self):
959 """ 1000 """
960 Private slot to set up the development environment for the current project. 1001 Private slot to set up the development environment for the current
1002 project.
961 """ 1003 """
962 title = self.trUtf8("Setup Development Environment") 1004 title = self.trUtf8("Setup Development Environment")
963 try: 1005 try:
964 wd = self.__projectPath() 1006 wd = self.__projectPath()
965 except PyramidNoProjectSelectedException: 1007 except PyramidNoProjectSelectedException:
966 E5MessageBox.warning(self.__ui, 1008 E5MessageBox.warning(
1009 self.__ui,
967 title, 1010 title,
968 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1011 self.trUtf8('No current Pyramid project selected or no Pyramid'
969 ' created yet. Aborting...')) 1012 ' project created yet. Aborting...'))
970 return 1013 return
971 1014
972 cmd = self.getPythonCommand() 1015 cmd = self.getPythonCommand()
973 args = [] 1016 args = []
974 args.append("setup.py") 1017 args.append("setup.py")
975 args.append("develop") 1018 args.append("develop")
976 1019
977 dia = PyramidDialog(title, 1020 dia = PyramidDialog(
978 msgSuccess=self.trUtf8("Pyramid development environment setup successfully.")) 1021 title,
1022 msgSuccess=self.trUtf8("Pyramid development environment setup"
1023 " successfully."))
979 res = dia.startProcess(cmd, args, wd) 1024 res = dia.startProcess(cmd, args, wd)
980 if res: 1025 if res:
981 dia.exec_() 1026 dia.exec_()
982 1027
983 ################################################################## 1028 ##################################################################
984 ## slots below implement distribution functions 1029 ## slots below implement distribution functions
985 ################################################################## 1030 ##################################################################
986 1031
987 def __buildDistribution(self): 1032 def __buildDistribution(self):
988 """ 1033 """
989 Private slot to build a distribution file for the current Pyramid project. 1034 Private slot to build a distribution file for the current Pyramid
1035 project.
990 """ 1036 """
991 title = self.trUtf8("Build Distribution File") 1037 title = self.trUtf8("Build Distribution File")
992 try: 1038 try:
993 projectPath = self.__projectPath() 1039 projectPath = self.__projectPath()
994 except PyramidNoProjectSelectedException: 1040 except PyramidNoProjectSelectedException:
995 E5MessageBox.warning(self.__ui, 1041 E5MessageBox.warning(
1042 self.__ui,
996 title, 1043 title,
997 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1044 self.trUtf8('No current Pyramid project selected or no Pyramid'
998 ' created yet. Aborting...')) 1045 ' project created yet. Aborting...'))
999 return 1046 return
1000 1047
1001 from .DistributionTypeSelectionDialog import DistributionTypeSelectionDialog 1048 from .DistributionTypeSelectionDialog import \
1049 DistributionTypeSelectionDialog
1002 1050
1003 dlg = DistributionTypeSelectionDialog(self, projectPath, self.__ui) 1051 dlg = DistributionTypeSelectionDialog(self, projectPath, self.__ui)
1004 if dlg.exec_() == QDialog.Accepted: 1052 if dlg.exec_() == QDialog.Accepted:
1005 formats = dlg.getFormats() 1053 formats = dlg.getFormats()
1006 cmd = self.getPythonCommand() 1054 cmd = self.getPythonCommand()
1008 args.append("setup.py") 1056 args.append("setup.py")
1009 args.append("sdist") 1057 args.append("sdist")
1010 if formats: 1058 if formats:
1011 args.append("--formats={0}".format(','.join(formats))) 1059 args.append("--formats={0}".format(','.join(formats)))
1012 1060
1013 dia = PyramidDialog(title, 1061 dia = PyramidDialog(
1014 msgSuccess=self.trUtf8("Python distribution file built successfully.")) 1062 title,
1063 msgSuccess=self.trUtf8("Python distribution file built"
1064 " successfully."))
1015 res = dia.startProcess(cmd, args, projectPath) 1065 res = dia.startProcess(cmd, args, projectPath)
1016 if res: 1066 if res:
1017 dia.exec_() 1067 dia.exec_()
1018 1068
1019 ################################################################## 1069 ##################################################################
1028 """ 1078 """
1029 try: 1079 try:
1030 cmd = "initialize_{0}_db".format(self.__project()) 1080 cmd = "initialize_{0}_db".format(self.__project())
1031 return self.getPyramidCommand(cmd) 1081 return self.getPyramidCommand(cmd)
1032 except PyramidNoProjectSelectedException: 1082 except PyramidNoProjectSelectedException:
1033 E5MessageBox.warning(self.__ui, 1083 E5MessageBox.warning(
1084 self.__ui,
1034 self.trUtf8("Initialize Database"), 1085 self.trUtf8("Initialize Database"),
1035 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1086 self.trUtf8('No current Pyramid project selected or no Pyramid'
1036 ' created yet. Aborting...')) 1087 ' project created yet. Aborting...'))
1037 return "" 1088 return ""
1038 1089
1039 def __initializeDatabase(self): 1090 def __initializeDatabase(self):
1040 """ 1091 """
1041 Private slot to initialize the database of the Pyramid project. 1092 Private slot to initialize the database of the Pyramid project.
1042 """ 1093 """
1043 title = self.trUtf8("Initialize Database") 1094 title = self.trUtf8("Initialize Database")
1044 try: 1095 try:
1045 projectPath = self.__projectPath() 1096 projectPath = self.__projectPath()
1046 except PyramidNoProjectSelectedException: 1097 except PyramidNoProjectSelectedException:
1047 E5MessageBox.warning(self.__ui, 1098 E5MessageBox.warning(
1099 self.__ui,
1048 title, 1100 title,
1049 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1101 self.trUtf8('No current Pyramid project selected or no Pyramid'
1050 ' created yet. Aborting...')) 1102 ' project created yet. Aborting...'))
1051 return 1103 return
1052 1104
1053 cmd = self.__getInitDbCommand() 1105 cmd = self.__getInitDbCommand()
1054 args = [] 1106 args = []
1055 args.append("development.ini") 1107 args.append("development.ini")
1056 1108
1057 dia = PyramidDialog(title, 1109 dia = PyramidDialog(
1110 title,
1058 msgSuccess=self.trUtf8("Database initialized successfully.")) 1111 msgSuccess=self.trUtf8("Database initialized successfully."))
1059 res = dia.startProcess(cmd, args, projectPath) 1112 res = dia.startProcess(cmd, args, projectPath)
1060 if res: 1113 if res:
1061 dia.exec_() 1114 dia.exec_()
1062 1115
1070 """ 1123 """
1071 title = self.trUtf8("Show Matching Views") 1124 title = self.trUtf8("Show Matching Views")
1072 try: 1125 try:
1073 projectPath = self.__projectPath() 1126 projectPath = self.__projectPath()
1074 except PyramidNoProjectSelectedException: 1127 except PyramidNoProjectSelectedException:
1075 E5MessageBox.warning(self.__ui, 1128 E5MessageBox.warning(
1129 self.__ui,
1076 title, 1130 title,
1077 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1131 self.trUtf8('No current Pyramid project selected or no Pyramid'
1078 ' created yet. Aborting...')) 1132 ' project created yet. Aborting...'))
1079 return 1133 return
1080 1134
1081 url, ok = QInputDialog.getText( 1135 url, ok = QInputDialog.getText(
1082 self.__ui, 1136 self.__ui,
1083 self.trUtf8("Show Matching Views"), 1137 self.trUtf8("Show Matching Views"),
1103 """ 1157 """
1104 title = self.trUtf8("Show Routes") 1158 title = self.trUtf8("Show Routes")
1105 try: 1159 try:
1106 projectPath = self.__projectPath() 1160 projectPath = self.__projectPath()
1107 except PyramidNoProjectSelectedException: 1161 except PyramidNoProjectSelectedException:
1108 E5MessageBox.warning(self.__ui, 1162 E5MessageBox.warning(
1163 self.__ui,
1109 title, 1164 title,
1110 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1165 self.trUtf8('No current Pyramid project selected or no Pyramid'
1111 ' created yet. Aborting...')) 1166 ' project created yet. Aborting...'))
1112 return 1167 return
1113 1168
1114 from .PyramidRoutesDialog import PyramidRoutesDialog 1169 from .PyramidRoutesDialog import PyramidRoutesDialog
1115 1170
1116 dia = PyramidRoutesDialog(self) 1171 dia = PyramidRoutesDialog(self)
1124 """ 1179 """
1125 title = self.trUtf8("Show Tween Objects") 1180 title = self.trUtf8("Show Tween Objects")
1126 try: 1181 try:
1127 projectPath = self.__projectPath() 1182 projectPath = self.__projectPath()
1128 except PyramidNoProjectSelectedException: 1183 except PyramidNoProjectSelectedException:
1129 E5MessageBox.warning(self.__ui, 1184 E5MessageBox.warning(
1185 self.__ui,
1130 title, 1186 title,
1131 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1187 self.trUtf8('No current Pyramid project selected or no Pyramid'
1132 ' created yet. Aborting...')) 1188 ' project created yet. Aborting...'))
1133 return 1189 return
1134 1190
1135 cmd = self.getPyramidCommand("ptweens") 1191 cmd = self.getPyramidCommand("ptweens")
1136 args = [] 1192 args = []
1137 args.append("development.ini") 1193 args.append("development.ini")
1214 """ 1270 """
1215 title = self.trUtf8("Extract messages") 1271 title = self.trUtf8("Extract messages")
1216 try: 1272 try:
1217 projectPath = self.__projectPath() 1273 projectPath = self.__projectPath()
1218 except PyramidNoProjectSelectedException: 1274 except PyramidNoProjectSelectedException:
1219 E5MessageBox.warning(self.__ui, 1275 E5MessageBox.warning(
1276 self.__ui,
1220 title, 1277 title,
1221 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1278 self.trUtf8('No current Pyramid project selected or no Pyramid'
1222 ' created yet. Aborting...')) 1279 ' project created yet. Aborting...'))
1223 return 1280 return
1224 1281
1225 cmd = self.getPythonCommand() 1282 cmd = self.getPythonCommand()
1226 args = [] 1283 args = []
1227 args.append("setup.py") 1284 args.append("setup.py")
1228 args.append("extract_messages") 1285 args.append("extract_messages")
1229 1286
1230 dia = PyramidDialog(title, 1287 dia = PyramidDialog(
1288 title,
1231 msgSuccess=self.trUtf8("\nMessages extracted successfully.")) 1289 msgSuccess=self.trUtf8("\nMessages extracted successfully."))
1232 res = dia.startProcess(cmd, args, projectPath) 1290 res = dia.startProcess(cmd, args, projectPath)
1233 if res: 1291 if res:
1234 dia.exec_() 1292 dia.exec_()
1235 1293
1240 self.__e5project.appendFile(os.path.join(projectPath, potFile)) 1298 self.__e5project.appendFile(os.path.join(projectPath, potFile))
1241 else: 1299 else:
1242 try: 1300 try:
1243 lowerProject = self.__project().lower() 1301 lowerProject = self.__project().lower()
1244 except PyramidNoProjectSelectedException: 1302 except PyramidNoProjectSelectedException:
1245 E5MessageBox.warning(self.__ui, 1303 E5MessageBox.warning(
1304 self.__ui,
1246 title, 1305 title,
1247 self.trUtf8('No current Pyramid project selected or no Pyramid' 1306 self.trUtf8('No current Pyramid project selected or no'
1248 ' project created yet. Aborting...')) 1307 ' Pyramid project created yet.'
1308 ' Aborting...'))
1249 return 1309 return
1250 1310
1251 self.__e5project.appendFile(os.path.join( 1311 self.__e5project.appendFile(os.path.join(
1252 projectPath, lowerProject, "locale", "%s.pot" % lowerProject)) 1312 projectPath, lowerProject, "locale",
1313 "{0}.pot".format(lowerProject)))
1253 1314
1254 def __projectLanguageAdded(self, code): 1315 def __projectLanguageAdded(self, code):
1255 """ 1316 """
1256 Private slot handling the addition of a new language. 1317 Private slot handling the addition of a new language.
1257 1318
1258 @param code language code of the new language (string) 1319 @param code language code of the new language (string)
1259 """ 1320 """
1260 title = self.trUtf8("Initializing message catalog for '{0}'").format(code) 1321 title = self.trUtf8("Initializing message catalog for '{0}'")\
1322 .format(code)
1261 try: 1323 try:
1262 projectPath = self.__projectPath() 1324 projectPath = self.__projectPath()
1263 except PyramidNoProjectSelectedException: 1325 except PyramidNoProjectSelectedException:
1264 E5MessageBox.warning(self.__ui, 1326 E5MessageBox.warning(
1327 self.__ui,
1265 title, 1328 title,
1266 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1329 self.trUtf8('No current Pyramid project selected or no Pyramid'
1267 ' created yet. Aborting...')) 1330 ' project created yet. Aborting...'))
1268 return 1331 return
1269 1332
1270 cmd = self.getPythonCommand() 1333 cmd = self.getPythonCommand()
1271 args = [] 1334 args = []
1272 args.append("setup.py") 1335 args.append("setup.py")
1273 args.append("init_catalog") 1336 args.append("init_catalog")
1274 args.append("-l") 1337 args.append("-l")
1275 args.append(code) 1338 args.append(code)
1276 1339
1277 dia = PyramidDialog(title, 1340 dia = PyramidDialog(
1278 msgSuccess=self.trUtf8("\nMessage catalog initialized successfully.")) 1341 title,
1342 msgSuccess=self.trUtf8("\nMessage catalog initialized"
1343 " successfully."))
1279 res = dia.startProcess(cmd, args, projectPath) 1344 res = dia.startProcess(cmd, args, projectPath)
1280 if res: 1345 if res:
1281 dia.exec_() 1346 dia.exec_()
1282 1347
1283 langFile = self.__e4project.pdata["TRANSLATIONPATTERN"][0]\ 1348 langFile = self.__e4project.pdata["TRANSLATIONPATTERN"][0]\
1292 """ 1357 """
1293 title = self.trUtf8("Compiling message catalogs") 1358 title = self.trUtf8("Compiling message catalogs")
1294 try: 1359 try:
1295 projectPath = self.__projectPath() 1360 projectPath = self.__projectPath()
1296 except PyramidNoProjectSelectedException: 1361 except PyramidNoProjectSelectedException:
1297 E5MessageBox.warning(self.__ui, 1362 E5MessageBox.warning(
1363 self.__ui,
1298 title, 1364 title,
1299 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1365 self.trUtf8('No current Pyramid project selected or no Pyramid'
1300 ' created yet. Aborting...')) 1366 ' project created yet. Aborting...'))
1301 return 1367 return
1302 1368
1303 cmd = self.getPythonCommand() 1369 cmd = self.getPythonCommand()
1304 args = [] 1370 args = []
1305 args.append("setup.py") 1371 args.append("setup.py")
1306 args.append("compile_catalog") 1372 args.append("compile_catalog")
1307 1373
1308 dia = PyramidDialog(title, 1374 dia = PyramidDialog(
1309 msgSuccess=self.trUtf8("\nMessage catalogs compiled successfully.")) 1375 title,
1376 msgSuccess=self.trUtf8("\nMessage catalogs compiled"
1377 " successfully."))
1310 res = dia.startProcess(cmd, args, projectPath) 1378 res = dia.startProcess(cmd, args, projectPath)
1311 if res: 1379 if res:
1312 dia.exec_() 1380 dia.exec_()
1313 1381
1314 for entry in os.walk(projectPath): 1382 for entry in os.walk(projectPath):
1325 """ 1393 """
1326 title = self.trUtf8("Compiling message catalogs") 1394 title = self.trUtf8("Compiling message catalogs")
1327 try: 1395 try:
1328 projectPath = self.__projectPath() 1396 projectPath = self.__projectPath()
1329 except PyramidNoProjectSelectedException: 1397 except PyramidNoProjectSelectedException:
1330 E5MessageBox.warning(self.__ui, 1398 E5MessageBox.warning(
1399 self.__ui,
1331 title, 1400 title,
1332 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1401 self.trUtf8('No current Pyramid project selected or no Pyramid'
1333 ' created yet. Aborting...')) 1402 ' project created yet. Aborting...'))
1334 return 1403 return
1335 1404
1336 argsLists = [] 1405 argsLists = []
1337 1406
1338 for filename in self.__normalizeList(self.__projectFilteredList(filenames)): 1407 for filename in self.__normalizeList(
1408 self.__projectFilteredList(filenames)):
1339 locale = self.__getLocale(filename) 1409 locale = self.__getLocale(filename)
1340 if locale: 1410 if locale:
1341 args = [] 1411 args = []
1342 args.append(self.getPythonCommand()) 1412 args.append(self.getPythonCommand())
1343 args.append("setup.py") 1413 args.append("setup.py")
1345 args.append("-l") 1415 args.append("-l")
1346 args.append(locale) 1416 args.append(locale)
1347 argsLists.append(args) 1417 argsLists.append(args)
1348 1418
1349 if len(argsLists) == 0: 1419 if len(argsLists) == 0:
1350 E5MessageBox.warning(self.__ui, 1420 E5MessageBox.warning(
1421 self.__ui,
1351 title, 1422 title,
1352 self.trUtf8('No locales detected. Aborting...')) 1423 self.trUtf8('No locales detected. Aborting...'))
1353 return 1424 return
1354 1425
1355 dia = PyramidDialog(title, 1426 dia = PyramidDialog(
1356 msgSuccess=self.trUtf8("\nMessage catalogs compiled successfully.")) 1427 title,
1428 msgSuccess=self.trUtf8("\nMessage catalogs compiled"
1429 " successfully."))
1357 res = dia.startBatchProcesses(argsLists, projectPath) 1430 res = dia.startBatchProcesses(argsLists, projectPath)
1358 if res: 1431 if res:
1359 dia.exec_() 1432 dia.exec_()
1360 1433
1361 for entry in os.walk(self.__sitePath()): 1434 for entry in os.walk(self.__sitePath()):
1372 """ 1445 """
1373 title = self.trUtf8("Updating message catalogs") 1446 title = self.trUtf8("Updating message catalogs")
1374 try: 1447 try:
1375 projectPath = self.__projectPath() 1448 projectPath = self.__projectPath()
1376 except PyramidNoProjectSelectedException: 1449 except PyramidNoProjectSelectedException:
1377 E5MessageBox.warning(self.__ui, 1450 E5MessageBox.warning(
1451 self.__ui,
1378 title, 1452 title,
1379 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1453 self.trUtf8('No current Pyramid project selected or no Pyramid'
1380 ' created yet. Aborting...')) 1454 ' project created yet. Aborting...'))
1381 return 1455 return
1382 1456
1383 cmd = self.getPythonCommand() 1457 cmd = self.getPythonCommand()
1384 args = [] 1458 args = []
1385 args.append("setup.py") 1459 args.append("setup.py")
1386 args.append("update_catalog") 1460 args.append("update_catalog")
1387 1461
1388 dia = PyramidDialog(title, 1462 dia = PyramidDialog(
1463 title,
1389 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully.")) 1464 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully."))
1390 res = dia.startProcess(cmd, args, projectPath) 1465 res = dia.startProcess(cmd, args, projectPath)
1391 if res: 1466 if res:
1392 dia.exec_() 1467 dia.exec_()
1393 1468
1399 """ 1474 """
1400 title = self.trUtf8("Updating message catalogs") 1475 title = self.trUtf8("Updating message catalogs")
1401 try: 1476 try:
1402 projectPath = self.__projectPath() 1477 projectPath = self.__projectPath()
1403 except PyramidNoProjectSelectedException: 1478 except PyramidNoProjectSelectedException:
1404 E5MessageBox.warning(self.__ui, 1479 E5MessageBox.warning(
1480 self.__ui,
1405 title, 1481 title,
1406 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1482 self.trUtf8('No current Pyramid project selected or no Pyramid'
1407 ' created yet. Aborting...')) 1483 ' project created yet. Aborting...'))
1408 return 1484 return
1409 1485
1410 argsLists = [] 1486 argsLists = []
1411 1487
1412 for filename in self.__normalizeList(self.__projectFilteredList(filenames)): 1488 for filename in self.__normalizeList(
1489 self.__projectFilteredList(filenames)):
1413 locale = self.__getLocale(filename) 1490 locale = self.__getLocale(filename)
1414 if locale: 1491 if locale:
1415 args = [] 1492 args = []
1416 args.append(self.getPythonCommand()) 1493 args.append(self.getPythonCommand())
1417 args.append("setup.py") 1494 args.append("setup.py")
1419 args.append("-l") 1496 args.append("-l")
1420 args.append(locale) 1497 args.append(locale)
1421 argsLists.append(args) 1498 argsLists.append(args)
1422 1499
1423 if len(argsLists) == 0: 1500 if len(argsLists) == 0:
1424 E5MessageBox.warning(self.__ui, 1501 E5MessageBox.warning(
1502 self.__ui,
1425 title, 1503 title,
1426 self.trUtf8('No locales detected. Aborting...')) 1504 self.trUtf8('No locales detected. Aborting...'))
1427 return 1505 return
1428 1506
1429 dia = PyramidDialog(title, 1507 dia = PyramidDialog(
1508 title,
1430 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully.")) 1509 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully."))
1431 res = dia.startBatchProcesses(argsLists, projectPath) 1510 res = dia.startBatchProcesses(argsLists, projectPath)
1432 if res: 1511 if res:
1433 dia.exec_() 1512 dia.exec_()
1434 1513
1444 wd = self.__projectPath() 1523 wd = self.__projectPath()
1445 except PyramidNoProjectSelectedException: 1524 except PyramidNoProjectSelectedException:
1446 wd = "" 1525 wd = ""
1447 started, pid = QProcess.startDetached(editor, [poFile], wd) 1526 started, pid = QProcess.startDetached(editor, [poFile], wd)
1448 if not started: 1527 if not started:
1449 E5MessageBox.critical(None, 1528 E5MessageBox.critical(
1529 None,
1450 self.trUtf8('Process Generation Error'), 1530 self.trUtf8('Process Generation Error'),
1451 self.trUtf8('The translations editor process ({0}) could not' 1531 self.trUtf8('The translations editor process ({0}) could'
1452 ' be started.').format(os.path.basename(editor))) 1532 ' not be started.').format(
1533 os.path.basename(editor)))

eric ide

mercurial