ProjectPyramid/Project.py

changeset 57
e654970c913e
parent 56
c7adc68350dd
parent 54
71c83a661c83
child 58
6acbfbba1e9d
equal deleted inserted replaced
56:c7adc68350dd 57:e654970c913e
18 import os 18 import os
19 import re 19 import re
20 import sys 20 import sys
21 21
22 from PyQt4.QtCore import QObject, QFileInfo, QTimer, QUrl 22 from PyQt4.QtCore import QObject, QFileInfo, QTimer, QUrl
23 from PyQt4.QtGui import QMenu, QDialog, QInputDialog, QDesktopServices, QLineEdit 23 from PyQt4.QtGui import QMenu, QDialog, QInputDialog, QDesktopServices, \
24 QLineEdit
24 from PyQt4.QtCore import QProcess as QProcessPyQt 25 from PyQt4.QtCore import QProcess as QProcessPyQt
25 26
26 from E5Gui.E5Application import e5App 27 from E5Gui.E5Application import e5App
27 from E5Gui import E5MessageBox, E5FileDialog 28 from E5Gui import E5MessageBox, E5FileDialog
28 from E5Gui.E5Action import E5Action 29 from E5Gui.E5Action import E5Action
105 """ 106 """
106 Public method to define the Pyramid actions. 107 Public method to define the Pyramid actions.
107 """ 108 """
108 self.actions = [] 109 self.actions = []
109 110
110 self.selectProjectAct = E5Action(self.trUtf8('Current Pyramid Project'), 111 self.selectProjectAct = E5Action(
111 "", 112 self.trUtf8('Current Pyramid Project'),
112 0, 0, 113 "",
113 self, 'pyramid_current_project') 114 0, 0,
115 self, 'pyramid_current_project')
114 self.selectProjectAct.setStatusTip(self.trUtf8( 116 self.selectProjectAct.setStatusTip(self.trUtf8(
115 'Selects the current Pyramid project')) 117 'Selects the current Pyramid project'))
116 self.selectProjectAct.setWhatsThis(self.trUtf8( 118 self.selectProjectAct.setWhatsThis(self.trUtf8(
117 """<b>Current Pyramid Project</b>""" 119 """<b>Current Pyramid Project</b>"""
118 """<p>Selects the Pyramid project. Used for multi-project """ 120 """<p>Selects the Pyramid project. Used for multi-project """
123 125
124 ############################### 126 ###############################
125 ## create actions below ## 127 ## create actions below ##
126 ############################### 128 ###############################
127 129
128 self.createProjectAct = E5Action(self.trUtf8('Create Pyramid Project'), 130 self.createProjectAct = E5Action(
129 self.trUtf8('Create Pyramid &Project'), 131 self.trUtf8('Create Pyramid Project'),
130 0, 0, 132 self.trUtf8('Create Pyramid &Project'),
131 self, 'pyramid_create_project') 133 0, 0,
134 self, 'pyramid_create_project')
132 self.createProjectAct.setStatusTip(self.trUtf8( 135 self.createProjectAct.setStatusTip(self.trUtf8(
133 'Creates a new Pyramid project')) 136 'Creates a new Pyramid project'))
134 self.createProjectAct.setWhatsThis(self.trUtf8( 137 self.createProjectAct.setWhatsThis(self.trUtf8(
135 """<b>Create Pyramid Project</b>""" 138 """<b>Create Pyramid Project</b>"""
136 """<p>Creates a new Pyramid project using "pcreate".</p>""" 139 """<p>Creates a new Pyramid project using "pcreate".</p>"""
140 143
141 ############################## 144 ##############################
142 ## run actions below ## 145 ## run actions below ##
143 ############################## 146 ##############################
144 147
145 self.runServerAct = E5Action(self.trUtf8('Run Server'), 148 self.runServerAct = E5Action(
146 self.trUtf8('Run &Server'), 149 self.trUtf8('Run Server'),
147 0, 0, 150 self.trUtf8('Run &Server'),
148 self, 'pyramid_run_server') 151 0, 0,
152 self, 'pyramid_run_server')
149 self.runServerAct.setStatusTip(self.trUtf8( 153 self.runServerAct.setStatusTip(self.trUtf8(
150 'Starts the Pyramid Web server')) 154 'Starts the Pyramid Web server'))
151 self.runServerAct.setWhatsThis(self.trUtf8( 155 self.runServerAct.setWhatsThis(self.trUtf8(
152 """<b>Run Server</b>""" 156 """<b>Run Server</b>"""
153 """<p>Starts the Pyramid Web server using""" 157 """<p>Starts the Pyramid Web server using"""
154 """ "pserve --reload development.ini".</p>""" 158 """ "pserve --reload development.ini".</p>"""
155 )) 159 ))
156 self.runServerAct.triggered[()].connect(self.__runServer) 160 self.runServerAct.triggered[()].connect(self.__runServer)
157 self.actions.append(self.runServerAct) 161 self.actions.append(self.runServerAct)
158 162
159 self.runLoggingServerAct = E5Action(self.trUtf8('Run Server with Logging'), 163 self.runLoggingServerAct = E5Action(
160 self.trUtf8('Run Server with &Logging'), 164 self.trUtf8('Run Server with Logging'),
161 0, 0, 165 self.trUtf8('Run Server with &Logging'),
162 self, 'pyramid_run_logging_server') 166 0, 0,
167 self, 'pyramid_run_logging_server')
163 self.runLoggingServerAct.setStatusTip(self.trUtf8( 168 self.runLoggingServerAct.setStatusTip(self.trUtf8(
164 'Starts the Pyramid Web server with logging')) 169 'Starts the Pyramid Web server with logging'))
165 self.runLoggingServerAct.setWhatsThis(self.trUtf8( 170 self.runLoggingServerAct.setWhatsThis(self.trUtf8(
166 """<b>Run Server with Logging</b>""" 171 """<b>Run Server with Logging</b>"""
167 """<p>Starts the Pyramid Web server with logging using""" 172 """<p>Starts the Pyramid Web server with logging using"""
168 """ "pserve --log-file=server.log --reload development.ini".</p>""" 173 """ "pserve --log-file=server.log --reload development.ini".</p>"""
169 )) 174 ))
170 self.runLoggingServerAct.triggered[()].connect(self.__runLoggingServer) 175 self.runLoggingServerAct.triggered[()].connect(self.__runLoggingServer)
171 self.actions.append(self.runLoggingServerAct) 176 self.actions.append(self.runLoggingServerAct)
172 177
173 self.runBrowserAct = E5Action(self.trUtf8('Run Web-Browser'), 178 self.runBrowserAct = E5Action(
174 self.trUtf8('Run &Web-Browser'), 179 self.trUtf8('Run Web-Browser'),
175 0, 0, 180 self.trUtf8('Run &Web-Browser'),
176 self, 'pyramid_run_browser') 181 0, 0,
182 self, 'pyramid_run_browser')
177 self.runBrowserAct.setStatusTip(self.trUtf8( 183 self.runBrowserAct.setStatusTip(self.trUtf8(
178 'Starts the default Web-Browser with the URL of the Pyramid Web server')) 184 'Starts the default Web-Browser with the URL of the Pyramid Web'
185 ' server'))
179 self.runBrowserAct.setWhatsThis(self.trUtf8( 186 self.runBrowserAct.setWhatsThis(self.trUtf8(
180 """<b>Run Web-Browser</b>""" 187 """<b>Run Web-Browser</b>"""
181 """<p>Starts the default Web-Browser with the URL of the """ 188 """<p>Starts the default Web-Browser with the URL of the """
182 """Pyramid Web server.</p>""" 189 """Pyramid Web server.</p>"""
183 )) 190 ))
184 self.runBrowserAct.triggered[()].connect(self.__runBrowser) 191 self.runBrowserAct.triggered[()].connect(self.__runBrowser)
185 self.actions.append(self.runBrowserAct) 192 self.actions.append(self.runBrowserAct)
186 193
187 self.runPythonShellAct = E5Action(self.trUtf8('Start Pyramid Python Console'), 194 self.runPythonShellAct = E5Action(
188 self.trUtf8('Start Pyramid &Python Console'), 195 self.trUtf8('Start Pyramid Python Console'),
189 0, 0, 196 self.trUtf8('Start Pyramid &Python Console'),
190 self, 'pyramid_python_console') 197 0, 0,
198 self, 'pyramid_python_console')
191 self.runPythonShellAct.setStatusTip(self.trUtf8( 199 self.runPythonShellAct.setStatusTip(self.trUtf8(
192 'Starts an interactive Python interpreter')) 200 'Starts an interactive Python interpreter'))
193 self.runPythonShellAct.setWhatsThis(self.trUtf8( 201 self.runPythonShellAct.setWhatsThis(self.trUtf8(
194 """<b>Start Pyramid Python Console</b>""" 202 """<b>Start Pyramid Python Console</b>"""
195 """<p>Starts an interactive Python interpreter.</p>""" 203 """<p>Starts an interactive Python interpreter.</p>"""
199 207
200 ############################## 208 ##############################
201 ## setup actions below ## 209 ## setup actions below ##
202 ############################## 210 ##############################
203 211
204 self.setupDevelopAct = E5Action(self.trUtf8('Setup Development Environment'), 212 self.setupDevelopAct = E5Action(
205 self.trUtf8('Setup &Development Environment'), 213 self.trUtf8('Setup Development Environment'),
206 0, 0, 214 self.trUtf8('Setup &Development Environment'),
207 self, 'pyramid_setup_development') 215 0, 0,
216 self, 'pyramid_setup_development')
208 self.setupDevelopAct.setStatusTip(self.trUtf8( 217 self.setupDevelopAct.setStatusTip(self.trUtf8(
209 'Setup the Pyramid project in development mode')) 218 'Setup the Pyramid project in development mode'))
210 self.setupDevelopAct.setWhatsThis(self.trUtf8( 219 self.setupDevelopAct.setWhatsThis(self.trUtf8(
211 """<b>Setup Development Environment</b>""" 220 """<b>Setup Development Environment</b>"""
212 """<p>Setup the Pyramid project in development mode using""" 221 """<p>Setup the Pyramid project in development mode using"""
217 226
218 ############################### 227 ###############################
219 ## database actions below ## 228 ## database actions below ##
220 ############################### 229 ###############################
221 230
222 self.initializeDbAct = E5Action(self.trUtf8('Initialize Database'), 231 self.initializeDbAct = E5Action(
223 self.trUtf8('Initialize &Database'), 232 self.trUtf8('Initialize Database'),
224 0, 0, 233 self.trUtf8('Initialize &Database'),
225 self, 'pyramid_initialize_database') 234 0, 0,
235 self, 'pyramid_initialize_database')
226 self.initializeDbAct.setStatusTip(self.trUtf8( 236 self.initializeDbAct.setStatusTip(self.trUtf8(
227 'Initializes (or re-initializes) the database of the current' 237 'Initializes (or re-initializes) the database of the current'
228 ' Pyramid project')) 238 ' Pyramid project'))
229 self.initializeDbAct.setWhatsThis(self.trUtf8( 239 self.initializeDbAct.setWhatsThis(self.trUtf8(
230 """<b>Initialize Database</b>""" 240 """<b>Initialize Database</b>"""
231 """<p>Initializes (or re-initializes) the database of the current""" 241 """<p>Initializes (or re-initializes) the database of the"""
232 """ Pyramid project.</p>""" 242 """ current Pyramid project.</p>"""
233 )) 243 ))
234 self.initializeDbAct.triggered[()].connect(self.__initializeDatabase) 244 self.initializeDbAct.triggered[()].connect(self.__initializeDatabase)
235 self.actions.append(self.initializeDbAct) 245 self.actions.append(self.initializeDbAct)
236 246
237 ############################### 247 ###############################
238 ## show actions below ## 248 ## show actions below ##
239 ############################### 249 ###############################
240 250
241 self.showViewsAct = E5Action(self.trUtf8('Show Matching Views'), 251 self.showViewsAct = E5Action(
242 self.trUtf8('Show Matching &Views'), 252 self.trUtf8('Show Matching Views'),
243 0, 0, 253 self.trUtf8('Show Matching &Views'),
244 self, 'pyramid_show_views') 254 0, 0,
255 self, 'pyramid_show_views')
245 self.showViewsAct.setStatusTip(self.trUtf8( 256 self.showViewsAct.setStatusTip(self.trUtf8(
246 'Show views matching a given URL')) 257 'Show views matching a given URL'))
247 self.showViewsAct.setWhatsThis(self.trUtf8( 258 self.showViewsAct.setWhatsThis(self.trUtf8(
248 """<b>Show Matching Views</b>""" 259 """<b>Show Matching Views</b>"""
249 """<p>Show views matching a given URL.</p>""" 260 """<p>Show views matching a given URL.</p>"""
250 )) 261 ))
251 self.showViewsAct.triggered[()].connect(self.__showMatchingViews) 262 self.showViewsAct.triggered[()].connect(self.__showMatchingViews)
252 self.actions.append(self.showViewsAct) 263 self.actions.append(self.showViewsAct)
253 264
254 self.showRoutesAct = E5Action(self.trUtf8('Show Routes'), 265 self.showRoutesAct = E5Action(
255 self.trUtf8('Show &Routes'), 266 self.trUtf8('Show Routes'),
256 0, 0, 267 self.trUtf8('Show &Routes'),
257 self, 'pyramid_show_routes') 268 0, 0,
269 self, 'pyramid_show_routes')
258 self.showRoutesAct.setStatusTip(self.trUtf8( 270 self.showRoutesAct.setStatusTip(self.trUtf8(
259 'Show all URL dispatch routes used by a Pyramid application')) 271 'Show all URL dispatch routes used by a Pyramid application'))
260 self.showRoutesAct.setWhatsThis(self.trUtf8( 272 self.showRoutesAct.setWhatsThis(self.trUtf8(
261 """<b>Show Routes</b>""" 273 """<b>Show Routes</b>"""
262 """<p>Show all URL dispatch routes used by a Pyramid application""" 274 """<p>Show all URL dispatch routes used by a Pyramid application"""
263 """ in the order in which they are evaluated.</p>""" 275 """ in the order in which they are evaluated.</p>"""
264 )) 276 ))
265 self.showRoutesAct.triggered[()].connect(self.__showRoutes) 277 self.showRoutesAct.triggered[()].connect(self.__showRoutes)
266 self.actions.append(self.showRoutesAct) 278 self.actions.append(self.showRoutesAct)
267 279
268 self.showTweensAct = E5Action(self.trUtf8('Show Tween Objects'), 280 self.showTweensAct = E5Action(
269 self.trUtf8('Show &Tween Objects'), 281 self.trUtf8('Show Tween Objects'),
270 0, 0, 282 self.trUtf8('Show &Tween Objects'),
271 self, 'pyramid_show_routes') 283 0, 0,
284 self, 'pyramid_show_routes')
272 self.showTweensAct.setStatusTip(self.trUtf8( 285 self.showTweensAct.setStatusTip(self.trUtf8(
273 'Show all implicit and explicit tween objects used by a Pyramid application')) 286 'Show all implicit and explicit tween objects used by a Pyramid'
287 ' application'))
274 self.showTweensAct.setWhatsThis(self.trUtf8( 288 self.showTweensAct.setWhatsThis(self.trUtf8(
275 """<b>Show Tween Objects</b>""" 289 """<b>Show Tween Objects</b>"""
276 """<p>Show all implicit and explicit tween objects used by a""" 290 """<p>Show all implicit and explicit tween objects used by a"""
277 """ Pyramid application.</p>""" 291 """ Pyramid application.</p>"""
278 )) 292 ))
281 295
282 ################################## 296 ##################################
283 ## distribution actions below ## 297 ## distribution actions below ##
284 ################################## 298 ##################################
285 299
286 self.buildDistroAct = E5Action(self.trUtf8('Build Distribution'), 300 self.buildDistroAct = E5Action(
287 self.trUtf8('Build &Distribution'), 301 self.trUtf8('Build Distribution'),
288 0, 0, 302 self.trUtf8('Build &Distribution'),
289 self, 'pyramid_build_distribution') 303 0, 0,
304 self, 'pyramid_build_distribution')
290 self.buildDistroAct.setStatusTip(self.trUtf8( 305 self.buildDistroAct.setStatusTip(self.trUtf8(
291 'Builds a distribution file for the Pyramid project')) 306 'Builds a distribution file for the Pyramid project'))
292 self.buildDistroAct.setWhatsThis(self.trUtf8( 307 self.buildDistroAct.setWhatsThis(self.trUtf8(
293 """<b>Build Distribution</b>""" 308 """<b>Build Distribution</b>"""
294 """<p>Builds a distribution file for the Pyramid project using""" 309 """<p>Builds a distribution file for the Pyramid project using"""
299 314
300 ################################## 315 ##################################
301 ## documentation action below ## 316 ## documentation action below ##
302 ################################## 317 ##################################
303 318
304 self.documentationAct = E5Action(self.trUtf8('Documentation'), 319 self.documentationAct = E5Action(
305 self.trUtf8('D&ocumentation'), 320 self.trUtf8('Documentation'),
306 0, 0, 321 self.trUtf8('D&ocumentation'),
307 self, 'pyramid_documentation') 322 0, 0,
323 self, 'pyramid_documentation')
308 self.documentationAct.setStatusTip(self.trUtf8( 324 self.documentationAct.setStatusTip(self.trUtf8(
309 'Shows the help viewer with the Pyramid documentation')) 325 'Shows the help viewer with the Pyramid documentation'))
310 self.documentationAct.setWhatsThis(self.trUtf8( 326 self.documentationAct.setWhatsThis(self.trUtf8(
311 """<b>Documentation</b>""" 327 """<b>Documentation</b>"""
312 """<p>Shows the help viewer with the Pyramid documentation.</p>""" 328 """<p>Shows the help viewer with the Pyramid documentation.</p>"""
316 332
317 ############################## 333 ##############################
318 ## about action below ## 334 ## about action below ##
319 ############################## 335 ##############################
320 336
321 self.aboutPyramidAct = E5Action(self.trUtf8('About Pyramid'), 337 self.aboutPyramidAct = E5Action(
322 self.trUtf8('About P&yramid'), 338 self.trUtf8('About Pyramid'),
323 0, 0, 339 self.trUtf8('About P&yramid'),
324 self, 'pyramid_about') 340 0, 0,
341 self, 'pyramid_about')
325 self.aboutPyramidAct.setStatusTip(self.trUtf8( 342 self.aboutPyramidAct.setStatusTip(self.trUtf8(
326 'Shows some information about Pyramid')) 343 'Shows some information about Pyramid'))
327 self.aboutPyramidAct.setWhatsThis(self.trUtf8( 344 self.aboutPyramidAct.setWhatsThis(self.trUtf8(
328 """<b>About Pyramid</b>""" 345 """<b>About Pyramid</b>"""
329 """<p>Shows some information about Pyramid.</p>""" 346 """<p>Shows some information about Pyramid.</p>"""
376 """ 393 """
377 if self.__hooksInstalled: 394 if self.__hooksInstalled:
378 editor = self.__plugin.getPreferences("TranslationsEditor") 395 editor = self.__plugin.getPreferences("TranslationsEditor")
379 try: 396 try:
380 if editor: 397 if editor:
381 self.__translationsBrowser.addHookMethodAndMenuEntry("open", 398 self.__translationsBrowser.addHookMethodAndMenuEntry(
382 self.openPOEditor, 399 "open", self.openPOEditor,
383 self.trUtf8("Open with {0}").format(os.path.basename(editor))) 400 self.trUtf8("Open with {0}").format(
401 os.path.basename(editor)))
384 else: 402 else:
385 self.__translationsBrowser.removeHookMethod("open") 403 self.__translationsBrowser.removeHookMethod("open")
386 except KeyError: 404 except KeyError:
387 # ignore for older eric5 versions 405 # ignore for older eric5 versions
388 pass 406 pass
392 Public method to add our hook methods. 410 Public method to add our hook methods.
393 """ 411 """
394 if self.__e5project.getProjectType() == "Pyramid": 412 if self.__e5project.getProjectType() == "Pyramid":
395 self.__formsBrowser = \ 413 self.__formsBrowser = \
396 e5App().getObject("ProjectBrowser").getProjectBrowser("forms") 414 e5App().getObject("ProjectBrowser").getProjectBrowser("forms")
397 self.__formsBrowser.addHookMethodAndMenuEntry("newForm", 415 self.__formsBrowser.addHookMethodAndMenuEntry(
398 self.newForm, self.trUtf8("New template...")) 416 "newForm", self.newForm, self.trUtf8("New template..."))
399 417
400 if self.__e5project.getProjectLanguage() == "Python2": 418 if self.__e5project.getProjectLanguage() == "Python2":
401 # Babel and lingua are not yet available for Python 3 419 # Babel and lingua are not yet available for Python 3
402 self.__e5project.projectLanguageAddedByCode.connect( 420 self.__e5project.projectLanguageAddedByCode.connect(
403 self.__projectLanguageAdded) 421 self.__projectLanguageAdded)
404 self.__translationsBrowser = \ 422 self.__translationsBrowser = \
405 e5App().getObject("ProjectBrowser").getProjectBrowser("translations") 423 e5App().getObject("ProjectBrowser")\
406 self.__translationsBrowser.addHookMethodAndMenuEntry("extractMessages", 424 .getProjectBrowser("translations")
407 self.extractMessages, self.trUtf8("Extract Messages")) 425 self.__translationsBrowser.addHookMethodAndMenuEntry(
408 self.__translationsBrowser.addHookMethodAndMenuEntry("releaseAll", 426 "extractMessages", self.extractMessages,
409 self.compileCatalogs, self.trUtf8("Compile All Catalogs")) 427 self.trUtf8("Extract Messages"))
410 self.__translationsBrowser.addHookMethodAndMenuEntry("releaseSelected", 428 self.__translationsBrowser.addHookMethodAndMenuEntry(
411 self.compileSelectedCatalogs, 429 "releaseAll", self.compileCatalogs,
430 self.trUtf8("Compile All Catalogs"))
431 self.__translationsBrowser.addHookMethodAndMenuEntry(
432 "releaseSelected", self.compileSelectedCatalogs,
412 self.trUtf8("Compile Selected Catalogs")) 433 self.trUtf8("Compile Selected Catalogs"))
413 self.__translationsBrowser.addHookMethodAndMenuEntry("generateAll", 434 self.__translationsBrowser.addHookMethodAndMenuEntry(
414 self.updateCatalogs, self.trUtf8("Update All Catalogs")) 435 "generateAll", self.updateCatalogs,
415 self.__translationsBrowser.addHookMethodAndMenuEntry("generateSelected", 436 self.trUtf8("Update All Catalogs"))
416 self.updateSelectedCatalogs, self.trUtf8("Update Selected Catalogs")) 437 self.__translationsBrowser.addHookMethodAndMenuEntry(
438 "generateSelected", self.updateSelectedCatalogs,
439 self.trUtf8("Update Selected Catalogs"))
417 440
418 self.__hooksInstalled = True 441 self.__hooksInstalled = True
419 442
420 self.registerOpenHook() 443 self.registerOpenHook()
421 444
476 ex = selectedFilter.split("(*")[1].split(")")[0] 499 ex = selectedFilter.split("(*")[1].split(")")[0]
477 if ex: 500 if ex:
478 fname += ex 501 fname += ex
479 502
480 if os.path.exists(fname): 503 if os.path.exists(fname):
481 res = E5MessageBox.yesNo(self.__ui, 504 res = E5MessageBox.yesNo(
505 self.__ui,
482 self.trUtf8("New Form"), 506 self.trUtf8("New Form"),
483 self.trUtf8("""The file already exists! Overwrite it?"""), 507 self.trUtf8("""The file already exists! Overwrite"""
508 """ it?"""),
484 icon=E5MessageBox.Warning) 509 icon=E5MessageBox.Warning)
485 if not res: 510 if not res:
486 # user selected to not overwrite 511 # user selected to not overwrite
487 return 512 return
488 513
489 try: 514 try:
490 f = open(fname, "w", encoding="utf-8") 515 f = open(fname, "w", encoding="utf-8")
491 f.write(template) 516 f.write(template)
492 f.close() 517 f.close()
493 except IOError as e: 518 except IOError as e:
494 E5MessageBox.critical(self, 519 E5MessageBox.critical(
520 self.__ui,
495 self.trUtf8("New Form"), 521 self.trUtf8("New Form"),
496 self.trUtf8("<p>The new form file <b>{0}</b> could not be" 522 self.trUtf8("<p>The new form file <b>{0}</b> could"
497 " created.<br/>" 523 " not be created.<br/> Problem: {1}</p>")
498 "Problem: {1}</p>").format(fname, e)) 524 .format(fname, e))
499 return 525 return
500 526
501 self.__e5project.appendFile(fname) 527 self.__e5project.appendFile(fname)
502 self.__formsBrowser.sourceFile.emit(fname) 528 self.__formsBrowser.sourceFile.emit(fname)
503 529
517 """ 543 """
518 Private method to build all full path of an executable file from 544 Private method to build all full path of an executable file from
519 the environment. 545 the environment.
520 546
521 @param file filename of the executable (string) 547 @param file filename of the executable (string)
522 @return list of full executable names, if the executable file is accessible 548 @return list of full executable names, if the executable file is
523 via the searchpath defined by the PATH environment variable, or an 549 accessible via the searchpath defined by the PATH environment
524 empty list otherwise. 550 variable, or an empty list otherwise.
525 """ 551 """
526 paths = [] 552 paths = []
527 553
528 if os.path.isabs(file): 554 if os.path.isabs(file):
529 if os.access(file, os.X_OK): 555 if os.access(file, os.X_OK):
581 f.close() 607 f.close()
582 except (IOError, OSError): 608 except (IOError, OSError):
583 l0 = "" 609 l0 = ""
584 if variant.lower() in l0.lower() or \ 610 if variant.lower() in l0.lower() or \
585 "{0}.".format(variant[-1]) in l0 or \ 611 "{0}.".format(variant[-1]) in l0 or \
586 (variant == "Python2" and \ 612 (variant == "Python2" and
587 "python3" not in l0.lower() and \ 613 "python3" not in l0.lower() and
588 "python" in l0.lower()): 614 "python" in l0.lower()):
589 variants.append(variant) 615 variants.append(variant)
590 break 616 break
591 617
592 return variants 618 return variants
695 Private slot to show some info about Pyramid. 721 Private slot to show some info about Pyramid.
696 """ 722 """
697 version = self.getPyramidVersion() 723 version = self.getPyramidVersion()
698 url = "http://www.pylonsproject.org/projects/pyramid/about" 724 url = "http://www.pylonsproject.org/projects/pyramid/about"
699 725
700 msgBox = E5MessageBox.E5MessageBox(E5MessageBox.Question, 726 msgBox = E5MessageBox.E5MessageBox(
727 E5MessageBox.Question,
701 self.trUtf8("About Pyramid"), 728 self.trUtf8("About Pyramid"),
702 self.trUtf8( 729 self.trUtf8(
703 "<p>Pyramid is a high-level Python Web framework that encourages rapid " 730 "<p>Pyramid is a high-level Python Web framework that"
704 "development and clean, pragmatic design.</p>" 731 " encourages rapid development and clean, pragmatic"
732 " design.</p>"
705 "<p><table>" 733 "<p><table>"
706 "<tr><td>Version:</td><td>{0}</td></tr>" 734 "<tr><td>Version:</td><td>{0}</td></tr>"
707 "<tr><td>URL:</td><td><a href=\"{1}\">" 735 "<tr><td>URL:</td><td><a href=\"{1}\">"
708 "{1}</a></td></tr>" 736 "{1}</a></td></tr>"
709 "</table></p>" 737 "</table></p>"
775 if simulate: 803 if simulate:
776 args.append("--simulate") 804 args.append("--simulate")
777 args.append("--scaffold={0}".format(scaffold)) 805 args.append("--scaffold={0}".format(scaffold))
778 args.append(project) 806 args.append(project)
779 dlg = PyramidDialog(self.trUtf8("Create Pyramid Project"), 807 dlg = PyramidDialog(self.trUtf8("Create Pyramid Project"),
780 linewrap=False, parent=self.__ui) 808 linewrap=False, parent=self.__ui)
781 if dlg.startProcess(cmd, args, self.__e5project.getProjectPath()): 809 if dlg.startProcess(cmd, args, self.__e5project.getProjectPath()):
782 dlg.exec_() 810 dlg.exec_()
783 if dlg.normalExit() and not simulate: 811 if dlg.normalExit() and not simulate:
784 # search for files created by pcreate and add them to the project 812 # search for files created by pcreate and add them to the
785 projectPath = os.path.join(self.__e5project.getProjectPath(), project) 813 # project
814 projectPath = os.path.join(
815 self.__e5project.getProjectPath(), project)
786 for entry in os.walk(projectPath): 816 for entry in os.walk(projectPath):
787 for fileName in entry[2]: 817 for fileName in entry[2]:
788 fullName = os.path.join(entry[0], fileName) 818 fullName = os.path.join(entry[0], fileName)
789 self.__e5project.appendFile(fullName) 819 self.__e5project.appendFile(fullName)
790 820
791 # create the base directory for translations 821 # create the base directory for translations
792 i18nPath = os.path.join(projectPath, project.lower(), "i18n") 822 i18nPath = os.path.join(
823 projectPath, project.lower(), "i18n")
793 if not os.path.exists(i18nPath): 824 if not os.path.exists(i18nPath):
794 os.makedirs(i18nPath) 825 os.makedirs(i18nPath)
795 self.__e5project.setDirty(True) 826 self.__e5project.setDirty(True)
796 827
797 self.__setCurrentProject(project) 828 self.__setCurrentProject(project)
816 return projects 847 return projects
817 848
818 def __selectProject(self): 849 def __selectProject(self):
819 """ 850 """
820 Private method to select a Pyramid project to work with. 851 Private method to select a Pyramid project to work with.
821
822 @return selected project (string)
823 """ 852 """
824 projects = self.__findProjects() 853 projects = self.__findProjects()
825 if len(projects) == 0: 854 if len(projects) == 0:
826 project = None 855 project = None
827 elif len(projects) == 1: 856 elif len(projects) == 1:
846 875
847 def __projectPath(self): 876 def __projectPath(self):
848 """ 877 """
849 Private method to calculate the full path of the Pyramid project. 878 Private method to calculate the full path of the Pyramid project.
850 879
851 @exception PyramidNoProjectSelectedException raised, if no project is selected 880 @exception PyramidNoProjectSelectedException raised, if no project is
881 selected
852 @return path of the project (string) 882 @return path of the project (string)
853 """ 883 """
854 if self.__currentProject is None: 884 if self.__currentProject is None:
855 self.__selectProject() 885 self.__selectProject()
856 886
892 domain = config.get("init_catalog", "domain") 922 domain = config.get("init_catalog", "domain")
893 except (configparser.NoOptionError, configparser.NoSectionError): 923 except (configparser.NoOptionError, configparser.NoSectionError):
894 domain = lowerProject 924 domain = lowerProject
895 self.__e5project.pdata["TRANSLATIONPATTERN"] = [ 925 self.__e5project.pdata["TRANSLATIONPATTERN"] = [
896 os.path.join(project, outputDir, "%language%", 926 os.path.join(project, outputDir, "%language%",
897 "LC_MESSAGES", "{0}.po".format(domain)) 927 "LC_MESSAGES", "{0}.po".format(domain))
898 ] 928 ]
899 929
900 if self.__currentProject is None: 930 if self.__currentProject is None:
901 self.initializeDbAct.setEnabled(False) 931 self.initializeDbAct.setEnabled(False)
902 else: 932 else:
905 935
906 def __project(self): 936 def __project(self):
907 """ 937 """
908 Private method to get the name of the current Pyramid project. 938 Private method to get the name of the current Pyramid project.
909 939
910 @exception PyramidNoProjectSelectedException raised, if no project is selected 940 @exception PyramidNoProjectSelectedException raised, if no project is
941 selected
911 @return name of the project (string) 942 @return name of the project (string)
912 """ 943 """
913 if self.__currentProject is None: 944 if self.__currentProject is None:
914 self.__selectProject() 945 self.__selectProject()
915 946
932 self.__plugin.getPreferences("ConsoleCommand"))[1] 963 self.__plugin.getPreferences("ConsoleCommand"))[1]
933 if consoleCmd: 964 if consoleCmd:
934 try: 965 try:
935 projectPath = self.__projectPath() 966 projectPath = self.__projectPath()
936 except PyramidNoProjectSelectedException: 967 except PyramidNoProjectSelectedException:
937 E5MessageBox.warning(self.__ui, 968 E5MessageBox.warning(
969 self.__ui,
938 self.trUtf8('Run Server'), 970 self.trUtf8('Run Server'),
939 self.trUtf8('No current Pyramid project selected or no Pyramid ' 971 self.trUtf8('No current Pyramid project selected or no'
940 'project created yet. Aborting...')) 972 ' Pyramid project created yet. Aborting...'))
941 return 973 return
942 974
943 args = Utilities.parseOptionString(consoleCmd) 975 args = Utilities.parseOptionString(consoleCmd)
944 args[0] = Utilities.getExecutablePath(args[0]) 976 args[0] = Utilities.getExecutablePath(args[0])
945 args.append(self.getPyramidCommand("pserve")) 977 args.append(self.getPyramidCommand("pserve"))
959 self.__serverProc.finished.connect(self.__serverProcFinished) 991 self.__serverProc.finished.connect(self.__serverProcFinished)
960 self.__serverProc.setWorkingDirectory(projectPath) 992 self.__serverProc.setWorkingDirectory(projectPath)
961 self.__serverProc.start(args[0], args[1:]) 993 self.__serverProc.start(args[0], args[1:])
962 serverProcStarted = self.__serverProc.waitForStarted() 994 serverProcStarted = self.__serverProc.waitForStarted()
963 if not serverProcStarted: 995 if not serverProcStarted:
964 E5MessageBox.critical(self.__ui, 996 E5MessageBox.critical(
997 self.__ui,
965 self.trUtf8('Process Generation Error'), 998 self.trUtf8('Process Generation Error'),
966 self.trUtf8('The Pyramid server could not be started.')) 999 self.trUtf8('The Pyramid server could not be started.'))
967 1000
968 def __runLoggingServer(self): 1001 def __runLoggingServer(self):
969 """ 1002 """
987 Private slot to start the default web browser with the server URL. 1020 Private slot to start the default web browser with the server URL.
988 """ 1021 """
989 try: 1022 try:
990 projectPath = self.__projectPath() 1023 projectPath = self.__projectPath()
991 except PyramidNoProjectSelectedException: 1024 except PyramidNoProjectSelectedException:
992 E5MessageBox.warning(self.__ui, 1025 E5MessageBox.warning(
1026 self.__ui,
993 self.trUtf8('Run Web-Browser'), 1027 self.trUtf8('Run Web-Browser'),
994 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1028 self.trUtf8('No current Pyramid project selected or no Pyramid'
995 ' created yet. Aborting...')) 1029 ' project created yet. Aborting...'))
996 return 1030 return
997 1031
998 config = configparser.ConfigParser() 1032 config = configparser.ConfigParser()
999 config.read(os.path.join(projectPath, "development.ini")) 1033 config.read(os.path.join(projectPath, "development.ini"))
1000 try: 1034 try:
1002 except (configparser.NoOptionError, configparser.NoSectionError): 1036 except (configparser.NoOptionError, configparser.NoSectionError):
1003 port = "8080" 1037 port = "8080"
1004 url = QUrl("http://localhost:{0}".format(port)) 1038 url = QUrl("http://localhost:{0}".format(port))
1005 res = QDesktopServices.openUrl(url) 1039 res = QDesktopServices.openUrl(url)
1006 if not res: 1040 if not res:
1007 E5MessageBox.critical(self.__ui, 1041 E5MessageBox.critical(
1042 self.__ui,
1008 self.trUtf8('Run Web-Browser'), 1043 self.trUtf8('Run Web-Browser'),
1009 self.trUtf8('Could not start the web-browser for the URL "{0}".')\ 1044 self.trUtf8('Could not start the web-browser for the URL'
1010 .format(url.toString())) 1045 ' "{0}".').format(url.toString()))
1011 1046
1012 def __runPythonShell(self): 1047 def __runPythonShell(self):
1013 """ 1048 """
1014 Private slot to start a Python console for a Pyramid project. 1049 Private slot to start a Python console for a Pyramid project.
1015 """ 1050 """
1017 self.__plugin.getPreferences("ConsoleCommand"))[1] 1052 self.__plugin.getPreferences("ConsoleCommand"))[1]
1018 if consoleCmd: 1053 if consoleCmd:
1019 try: 1054 try:
1020 projectPath = self.__projectPath() 1055 projectPath = self.__projectPath()
1021 except PyramidNoProjectSelectedException: 1056 except PyramidNoProjectSelectedException:
1022 E5MessageBox.warning(self.__ui, 1057 E5MessageBox.warning(
1058 self.__ui,
1023 self.trUtf8('Start Pyramid Python Console'), 1059 self.trUtf8('Start Pyramid Python Console'),
1024 self.trUtf8('No current Pyramid project selected or no Pyramid ' 1060 self.trUtf8('No current Pyramid project selected or no'
1025 'project created yet. Aborting...')) 1061 ' Pyramid project created yet. Aborting...'))
1026 return 1062 return
1027 1063
1028 args = Utilities.parseOptionString(consoleCmd) 1064 args = Utilities.parseOptionString(consoleCmd)
1029 args[0] = Utilities.getExecutablePath(args[0]) 1065 args[0] = Utilities.getExecutablePath(args[0])
1030 args.append(self.getPyramidCommand("pshell")) 1066 args.append(self.getPyramidCommand("pshell"))
1031 language = self.__e5project.getProjectLanguage() 1067 language = self.__e5project.getProjectLanguage()
1032 if language == "Python2": 1068 if language == "Python2":
1033 consoleType = self.__plugin.getPreferences("Python2ConsoleType") 1069 consoleType = self.__plugin.getPreferences(
1070 "Python2ConsoleType")
1034 else: 1071 else:
1035 consoleType = self.__plugin.getPreferences("Python3ConsoleType") 1072 consoleType = self.__plugin.getPreferences(
1073 "Python3ConsoleType")
1036 args.append("--python-shell={0}".format(consoleType)) 1074 args.append("--python-shell={0}".format(consoleType))
1037 args.append(os.path.join(projectPath, "development.ini")) 1075 args.append(os.path.join(projectPath, "development.ini"))
1038 1076
1039 started, pid = QProcess.startDetached(args[0], args[1:], projectPath) 1077 started, pid = QProcess.startDetached(
1078 args[0], args[1:], projectPath)
1040 if not started: 1079 if not started:
1041 E5MessageBox.critical(self.__ui, 1080 E5MessageBox.critical(
1081 self.__ui,
1042 self.trUtf8('Process Generation Error'), 1082 self.trUtf8('Process Generation Error'),
1043 self.trUtf8('The Pyramid Shell process could not be started.')) 1083 self.trUtf8('The Pyramid Shell process could not be'
1084 ' started.'))
1044 1085
1045 ################################################################## 1086 ##################################################################
1046 ## slots below implement setup functions 1087 ## slots below implement setup functions
1047 ################################################################## 1088 ##################################################################
1048 1089
1049 def __setupDevelop(self): 1090 def __setupDevelop(self):
1050 """ 1091 """
1051 Private slot to set up the development environment for the current project. 1092 Private slot to set up the development environment for the current
1093 project.
1052 """ 1094 """
1053 title = self.trUtf8("Setup Development Environment") 1095 title = self.trUtf8("Setup Development Environment")
1054 try: 1096 try:
1055 wd = self.__projectPath() 1097 wd = self.__projectPath()
1056 except PyramidNoProjectSelectedException: 1098 except PyramidNoProjectSelectedException:
1057 E5MessageBox.warning(self.__ui, 1099 E5MessageBox.warning(
1100 self.__ui,
1058 title, 1101 title,
1059 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1102 self.trUtf8('No current Pyramid project selected or no Pyramid'
1060 ' created yet. Aborting...')) 1103 ' project created yet. Aborting...'))
1061 return 1104 return
1062 1105
1063 cmd = self.getPythonCommand() 1106 cmd = self.getPythonCommand()
1064 args = [] 1107 args = []
1065 args.append("setup.py") 1108 args.append("setup.py")
1066 args.append("develop") 1109 args.append("develop")
1067 1110
1068 dia = PyramidDialog(title, 1111 dia = PyramidDialog(
1069 msgSuccess=self.trUtf8("Pyramid development environment setup successfully.")) 1112 title,
1113 msgSuccess=self.trUtf8("Pyramid development environment setup"
1114 " successfully."))
1070 res = dia.startProcess(cmd, args, wd) 1115 res = dia.startProcess(cmd, args, wd)
1071 if res: 1116 if res:
1072 dia.exec_() 1117 dia.exec_()
1073 initCmd = self.__getInitDbCommand() 1118 initCmd = self.__getInitDbCommand()
1074 self.initializeDbAct.setEnabled(os.path.exists(initCmd)) 1119 self.initializeDbAct.setEnabled(os.path.exists(initCmd))
1077 ## slots below implement distribution functions 1122 ## slots below implement distribution functions
1078 ################################################################## 1123 ##################################################################
1079 1124
1080 def __buildDistribution(self): 1125 def __buildDistribution(self):
1081 """ 1126 """
1082 Private slot to build a distribution file for the current Pyramid project. 1127 Private slot to build a distribution file for the current Pyramid
1128 project.
1083 """ 1129 """
1084 title = self.trUtf8("Build Distribution File") 1130 title = self.trUtf8("Build Distribution File")
1085 try: 1131 try:
1086 projectPath = self.__projectPath() 1132 projectPath = self.__projectPath()
1087 except PyramidNoProjectSelectedException: 1133 except PyramidNoProjectSelectedException:
1088 E5MessageBox.warning(self.__ui, 1134 E5MessageBox.warning(
1135 self.__ui,
1089 title, 1136 title,
1090 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1137 self.trUtf8('No current Pyramid project selected or no Pyramid'
1091 ' created yet. Aborting...')) 1138 ' project created yet. Aborting...'))
1092 return 1139 return
1093 1140
1094 from .DistributionTypeSelectionDialog import DistributionTypeSelectionDialog 1141 from .DistributionTypeSelectionDialog import \
1142 DistributionTypeSelectionDialog
1095 1143
1096 dlg = DistributionTypeSelectionDialog(self, projectPath, self.__ui) 1144 dlg = DistributionTypeSelectionDialog(self, projectPath, self.__ui)
1097 if dlg.exec_() == QDialog.Accepted: 1145 if dlg.exec_() == QDialog.Accepted:
1098 formats = dlg.getFormats() 1146 formats = dlg.getFormats()
1099 cmd = self.getPythonCommand() 1147 cmd = self.getPythonCommand()
1101 args.append("setup.py") 1149 args.append("setup.py")
1102 args.append("sdist") 1150 args.append("sdist")
1103 if formats: 1151 if formats:
1104 args.append("--formats={0}".format(','.join(formats))) 1152 args.append("--formats={0}".format(','.join(formats)))
1105 1153
1106 dia = PyramidDialog(title, 1154 dia = PyramidDialog(
1107 msgSuccess=self.trUtf8("Python distribution file built successfully.")) 1155 title,
1156 msgSuccess=self.trUtf8("Python distribution file built"
1157 " successfully."))
1108 res = dia.startProcess(cmd, args, projectPath) 1158 res = dia.startProcess(cmd, args, projectPath)
1109 if res: 1159 if res:
1110 dia.exec_() 1160 dia.exec_()
1111 1161
1112 ################################################################## 1162 ##################################################################
1121 """ 1171 """
1122 try: 1172 try:
1123 cmd = "initialize_{0}_db".format(self.__project()) 1173 cmd = "initialize_{0}_db".format(self.__project())
1124 return self.getPyramidCommand(cmd) 1174 return self.getPyramidCommand(cmd)
1125 except PyramidNoProjectSelectedException: 1175 except PyramidNoProjectSelectedException:
1126 E5MessageBox.warning(self.__ui, 1176 E5MessageBox.warning(
1177 self.__ui,
1127 self.trUtf8("Initialize Database"), 1178 self.trUtf8("Initialize Database"),
1128 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1179 self.trUtf8('No current Pyramid project selected or no Pyramid'
1129 ' created yet. Aborting...')) 1180 ' project created yet. Aborting...'))
1130 return "" 1181 return ""
1131 1182
1132 def __initializeDatabase(self): 1183 def __initializeDatabase(self):
1133 """ 1184 """
1134 Private slot to initialize the database of the Pyramid project. 1185 Private slot to initialize the database of the Pyramid project.
1135 """ 1186 """
1136 title = self.trUtf8("Initialize Database") 1187 title = self.trUtf8("Initialize Database")
1137 try: 1188 try:
1138 projectPath = self.__projectPath() 1189 projectPath = self.__projectPath()
1139 except PyramidNoProjectSelectedException: 1190 except PyramidNoProjectSelectedException:
1140 E5MessageBox.warning(self.__ui, 1191 E5MessageBox.warning(
1192 self.__ui,
1141 title, 1193 title,
1142 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1194 self.trUtf8('No current Pyramid project selected or no Pyramid'
1143 ' created yet. Aborting...')) 1195 ' project created yet. Aborting...'))
1144 return 1196 return
1145 1197
1146 cmd = self.__getInitDbCommand() 1198 cmd = self.__getInitDbCommand()
1147 args = [] 1199 args = []
1148 args.append("development.ini") 1200 args.append("development.ini")
1149 1201
1150 dia = PyramidDialog(title, 1202 dia = PyramidDialog(
1203 title,
1151 msgSuccess=self.trUtf8("Database initialized successfully.")) 1204 msgSuccess=self.trUtf8("Database initialized successfully."))
1152 res = dia.startProcess(cmd, args, projectPath) 1205 res = dia.startProcess(cmd, args, projectPath)
1153 if res: 1206 if res:
1154 dia.exec_() 1207 dia.exec_()
1155 1208
1163 """ 1216 """
1164 title = self.trUtf8("Show Matching Views") 1217 title = self.trUtf8("Show Matching Views")
1165 try: 1218 try:
1166 projectPath = self.__projectPath() 1219 projectPath = self.__projectPath()
1167 except PyramidNoProjectSelectedException: 1220 except PyramidNoProjectSelectedException:
1168 E5MessageBox.warning(self.__ui, 1221 E5MessageBox.warning(
1222 self.__ui,
1169 title, 1223 title,
1170 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1224 self.trUtf8('No current Pyramid project selected or no Pyramid'
1171 ' created yet. Aborting...')) 1225 ' project created yet. Aborting...'))
1172 return 1226 return
1173 1227
1174 url, ok = QInputDialog.getText( 1228 url, ok = QInputDialog.getText(
1175 self.__ui, 1229 self.__ui,
1176 self.trUtf8("Show Matching Views"), 1230 self.trUtf8("Show Matching Views"),
1196 """ 1250 """
1197 title = self.trUtf8("Show Routes") 1251 title = self.trUtf8("Show Routes")
1198 try: 1252 try:
1199 projectPath = self.__projectPath() 1253 projectPath = self.__projectPath()
1200 except PyramidNoProjectSelectedException: 1254 except PyramidNoProjectSelectedException:
1201 E5MessageBox.warning(self.__ui, 1255 E5MessageBox.warning(
1256 self.__ui,
1202 title, 1257 title,
1203 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1258 self.trUtf8('No current Pyramid project selected or no Pyramid'
1204 ' created yet. Aborting...')) 1259 ' project created yet. Aborting...'))
1205 return 1260 return
1206 1261
1207 from .PyramidRoutesDialog import PyramidRoutesDialog 1262 from .PyramidRoutesDialog import PyramidRoutesDialog
1208 1263
1209 dia = PyramidRoutesDialog(self) 1264 dia = PyramidRoutesDialog(self)
1217 """ 1272 """
1218 title = self.trUtf8("Show Tween Objects") 1273 title = self.trUtf8("Show Tween Objects")
1219 try: 1274 try:
1220 projectPath = self.__projectPath() 1275 projectPath = self.__projectPath()
1221 except PyramidNoProjectSelectedException: 1276 except PyramidNoProjectSelectedException:
1222 E5MessageBox.warning(self.__ui, 1277 E5MessageBox.warning(
1278 self.__ui,
1223 title, 1279 title,
1224 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1280 self.trUtf8('No current Pyramid project selected or no Pyramid'
1225 ' created yet. Aborting...')) 1281 ' project created yet. Aborting...'))
1226 return 1282 return
1227 1283
1228 cmd = self.getPyramidCommand("ptweens") 1284 cmd = self.getPyramidCommand("ptweens")
1229 args = [] 1285 args = []
1230 args.append("development.ini") 1286 args.append("development.ini")
1312 """ 1368 """
1313 title = self.trUtf8("Extract messages") 1369 title = self.trUtf8("Extract messages")
1314 try: 1370 try:
1315 projectPath = self.__projectPath() 1371 projectPath = self.__projectPath()
1316 except PyramidNoProjectSelectedException: 1372 except PyramidNoProjectSelectedException:
1317 E5MessageBox.warning(self.__ui, 1373 E5MessageBox.warning(
1374 self.__ui,
1318 title, 1375 title,
1319 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1376 self.trUtf8('No current Pyramid project selected or no Pyramid'
1320 ' created yet. Aborting...')) 1377 ' project created yet. Aborting...'))
1321 return 1378 return
1322 1379
1323 config = configparser.ConfigParser() 1380 config = configparser.ConfigParser()
1324 config.read(os.path.join(projectPath, "setup.cfg")) 1381 config.read(os.path.join(projectPath, "setup.cfg"))
1325 try: 1382 try:
1345 cmd = self.getPythonCommand() 1402 cmd = self.getPythonCommand()
1346 args = [] 1403 args = []
1347 args.append("setup.py") 1404 args.append("setup.py")
1348 args.append("extract_messages") 1405 args.append("extract_messages")
1349 1406
1350 dia = PyramidDialog(title, 1407 dia = PyramidDialog(
1408 title,
1351 msgSuccess=self.trUtf8("\nMessages extracted successfully.")) 1409 msgSuccess=self.trUtf8("\nMessages extracted successfully."))
1352 res = dia.startProcess(cmd, args, projectPath) 1410 res = dia.startProcess(cmd, args, projectPath)
1353 if res: 1411 if res:
1354 dia.exec_() 1412 dia.exec_()
1355 self.__e5project.appendFile(os.path.join(projectPath, potFile)) 1413 self.__e5project.appendFile(os.path.join(projectPath, potFile))
1358 """ 1416 """
1359 Private slot handling the addition of a new language. 1417 Private slot handling the addition of a new language.
1360 1418
1361 @param code language code of the new language (string) 1419 @param code language code of the new language (string)
1362 """ 1420 """
1363 title = self.trUtf8("Initializing message catalog for '{0}'").format(code) 1421 title = self.trUtf8("Initializing message catalog for '{0}'")\
1422 .format(code)
1364 try: 1423 try:
1365 projectPath = self.__projectPath() 1424 projectPath = self.__projectPath()
1366 except PyramidNoProjectSelectedException: 1425 except PyramidNoProjectSelectedException:
1367 E5MessageBox.warning(self.__ui, 1426 E5MessageBox.warning(
1427 self.__ui,
1368 title, 1428 title,
1369 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1429 self.trUtf8('No current Pyramid project selected or no Pyramid'
1370 ' created yet. Aborting...')) 1430 ' project created yet. Aborting...'))
1371 return 1431 return
1372 1432
1373 cmd = self.getPythonCommand() 1433 cmd = self.getPythonCommand()
1374 args = [] 1434 args = []
1375 args.append("setup.py") 1435 args.append("setup.py")
1376 args.append("init_catalog") 1436 args.append("init_catalog")
1377 args.append("-l") 1437 args.append("-l")
1378 args.append(code) 1438 args.append(code)
1379 1439
1380 dia = PyramidDialog(title, 1440 dia = PyramidDialog(
1381 msgSuccess=self.trUtf8("\nMessage catalog initialized successfully.")) 1441 title,
1442 msgSuccess=self.trUtf8("\nMessage catalog initialized"
1443 " successfully."))
1382 res = dia.startProcess(cmd, args, projectPath) 1444 res = dia.startProcess(cmd, args, projectPath)
1383 if res: 1445 if res:
1384 dia.exec_() 1446 dia.exec_()
1385 1447
1386 langFile = self.__e5project.pdata["TRANSLATIONPATTERN"][0]\ 1448 langFile = self.__e5project.pdata["TRANSLATIONPATTERN"][0]\
1395 """ 1457 """
1396 title = self.trUtf8("Compiling message catalogs") 1458 title = self.trUtf8("Compiling message catalogs")
1397 try: 1459 try:
1398 projectPath = self.__projectPath() 1460 projectPath = self.__projectPath()
1399 except PyramidNoProjectSelectedException: 1461 except PyramidNoProjectSelectedException:
1400 E5MessageBox.warning(self.__ui, 1462 E5MessageBox.warning(
1463 self.__ui,
1401 title, 1464 title,
1402 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1465 self.trUtf8('No current Pyramid project selected or no Pyramid'
1403 ' created yet. Aborting...')) 1466 ' project created yet. Aborting...'))
1404 return 1467 return
1405 1468
1406 cmd = self.getPythonCommand() 1469 cmd = self.getPythonCommand()
1407 args = [] 1470 args = []
1408 args.append("setup.py") 1471 args.append("setup.py")
1409 args.append("compile_catalog") 1472 args.append("compile_catalog")
1410 1473
1411 dia = PyramidDialog(title, 1474 dia = PyramidDialog(
1412 msgSuccess=self.trUtf8("\nMessage catalogs compiled successfully.")) 1475 title,
1476 msgSuccess=self.trUtf8("\nMessage catalogs compiled"
1477 " successfully."))
1413 res = dia.startProcess(cmd, args, projectPath) 1478 res = dia.startProcess(cmd, args, projectPath)
1414 if res: 1479 if res:
1415 dia.exec_() 1480 dia.exec_()
1416 1481
1417 for entry in os.walk(projectPath): 1482 for entry in os.walk(projectPath):
1428 """ 1493 """
1429 title = self.trUtf8("Compiling message catalogs") 1494 title = self.trUtf8("Compiling message catalogs")
1430 try: 1495 try:
1431 projectPath = self.__projectPath() 1496 projectPath = self.__projectPath()
1432 except PyramidNoProjectSelectedException: 1497 except PyramidNoProjectSelectedException:
1433 E5MessageBox.warning(self.__ui, 1498 E5MessageBox.warning(
1499 self.__ui,
1434 title, 1500 title,
1435 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1501 self.trUtf8('No current Pyramid project selected or no Pyramid'
1436 ' created yet. Aborting...')) 1502 ' project created yet. Aborting...'))
1437 return 1503 return
1438 1504
1439 argsLists = [] 1505 argsLists = []
1440 1506
1441 for filename in self.__normalizeList(self.__projectFilteredList(filenames)): 1507 for filename in self.__normalizeList(
1508 self.__projectFilteredList(filenames)):
1442 locale = self.__getLocale(filename) 1509 locale = self.__getLocale(filename)
1443 if locale: 1510 if locale:
1444 args = [] 1511 args = []
1445 args.append(self.getPythonCommand()) 1512 args.append(self.getPythonCommand())
1446 args.append("setup.py") 1513 args.append("setup.py")
1448 args.append("-l") 1515 args.append("-l")
1449 args.append(locale) 1516 args.append(locale)
1450 argsLists.append(args) 1517 argsLists.append(args)
1451 1518
1452 if len(argsLists) == 0: 1519 if len(argsLists) == 0:
1453 E5MessageBox.warning(self.__ui, 1520 E5MessageBox.warning(
1521 self.__ui,
1454 title, 1522 title,
1455 self.trUtf8('No locales detected. Aborting...')) 1523 self.trUtf8('No locales detected. Aborting...'))
1456 return 1524 return
1457 1525
1458 dia = PyramidDialog(title, 1526 dia = PyramidDialog(
1459 msgSuccess=self.trUtf8("\nMessage catalogs compiled successfully.")) 1527 title,
1528 msgSuccess=self.trUtf8("\nMessage catalogs compiled"
1529 " successfully."))
1460 res = dia.startBatchProcesses(argsLists, projectPath) 1530 res = dia.startBatchProcesses(argsLists, projectPath)
1461 if res: 1531 if res:
1462 dia.exec_() 1532 dia.exec_()
1463 1533
1464 for entry in os.walk(self.__sitePath()): 1534 for entry in os.walk(self.__sitePath()):
1475 """ 1545 """
1476 title = self.trUtf8("Updating message catalogs") 1546 title = self.trUtf8("Updating message catalogs")
1477 try: 1547 try:
1478 projectPath = self.__projectPath() 1548 projectPath = self.__projectPath()
1479 except PyramidNoProjectSelectedException: 1549 except PyramidNoProjectSelectedException:
1480 E5MessageBox.warning(self.__ui, 1550 E5MessageBox.warning(
1551 self.__ui,
1481 title, 1552 title,
1482 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1553 self.trUtf8('No current Pyramid project selected or no Pyramid'
1483 ' created yet. Aborting...')) 1554 ' project created yet. Aborting...'))
1484 return 1555 return
1485 1556
1486 cmd = self.getPythonCommand() 1557 cmd = self.getPythonCommand()
1487 args = [] 1558 args = []
1488 args.append("setup.py") 1559 args.append("setup.py")
1489 args.append("update_catalog") 1560 args.append("update_catalog")
1490 1561
1491 dia = PyramidDialog(title, 1562 dia = PyramidDialog(
1563 title,
1492 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully.")) 1564 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully."))
1493 res = dia.startProcess(cmd, args, projectPath) 1565 res = dia.startProcess(cmd, args, projectPath)
1494 if res: 1566 if res:
1495 dia.exec_() 1567 dia.exec_()
1496 1568
1502 """ 1574 """
1503 title = self.trUtf8("Updating message catalogs") 1575 title = self.trUtf8("Updating message catalogs")
1504 try: 1576 try:
1505 projectPath = self.__projectPath() 1577 projectPath = self.__projectPath()
1506 except PyramidNoProjectSelectedException: 1578 except PyramidNoProjectSelectedException:
1507 E5MessageBox.warning(self.__ui, 1579 E5MessageBox.warning(
1580 self.__ui,
1508 title, 1581 title,
1509 self.trUtf8('No current Pyramid project selected or no Pyramid project' 1582 self.trUtf8('No current Pyramid project selected or no Pyramid'
1510 ' created yet. Aborting...')) 1583 ' project created yet. Aborting...'))
1511 return 1584 return
1512 1585
1513 argsLists = [] 1586 argsLists = []
1514 1587
1515 for filename in self.__normalizeList(self.__projectFilteredList(filenames)): 1588 for filename in self.__normalizeList(
1589 self.__projectFilteredList(filenames)):
1516 locale = self.__getLocale(filename) 1590 locale = self.__getLocale(filename)
1517 if locale: 1591 if locale:
1518 args = [] 1592 args = []
1519 args.append(self.getPythonCommand()) 1593 args.append(self.getPythonCommand())
1520 args.append("setup.py") 1594 args.append("setup.py")
1522 args.append("-l") 1596 args.append("-l")
1523 args.append(locale) 1597 args.append(locale)
1524 argsLists.append(args) 1598 argsLists.append(args)
1525 1599
1526 if len(argsLists) == 0: 1600 if len(argsLists) == 0:
1527 E5MessageBox.warning(self.__ui, 1601 E5MessageBox.warning(
1602 self.__ui,
1528 title, 1603 title,
1529 self.trUtf8('No locales detected. Aborting...')) 1604 self.trUtf8('No locales detected. Aborting...'))
1530 return 1605 return
1531 1606
1532 dia = PyramidDialog(title, 1607 dia = PyramidDialog(
1608 title,
1533 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully.")) 1609 msgSuccess=self.trUtf8("\nMessage catalogs updated successfully."))
1534 res = dia.startBatchProcesses(argsLists, projectPath) 1610 res = dia.startBatchProcesses(argsLists, projectPath)
1535 if res: 1611 if res:
1536 dia.exec_() 1612 dia.exec_()
1537 1613
1547 wd = self.__projectPath() 1623 wd = self.__projectPath()
1548 except PyramidNoProjectSelectedException: 1624 except PyramidNoProjectSelectedException:
1549 wd = "" 1625 wd = ""
1550 started, pid = QProcess.startDetached(editor, [poFile], wd) 1626 started, pid = QProcess.startDetached(editor, [poFile], wd)
1551 if not started: 1627 if not started:
1552 E5MessageBox.critical(None, 1628 E5MessageBox.critical(
1629 None,
1553 self.trUtf8('Process Generation Error'), 1630 self.trUtf8('Process Generation Error'),
1554 self.trUtf8('The translations editor process ({0}) could not' 1631 self.trUtf8('The translations editor process ({0}) could'
1555 ' be started.').format(os.path.basename(editor))) 1632 ' not be started.').format(
1633 os.path.basename(editor)))

eric ide

mercurial