PluginManager/PluginInstallDialog.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3345
071afe8be2a1
child 3532
86ac124f322c
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
59 else: 59 else:
60 self.__pluginManager = pluginManager 60 self.__pluginManager = pluginManager
61 self.__external = False 61 self.__external = False
62 62
63 self.__backButton = self.buttonBox.addButton( 63 self.__backButton = self.buttonBox.addButton(
64 self.trUtf8("< Back"), QDialogButtonBox.ActionRole) 64 self.tr("< Back"), QDialogButtonBox.ActionRole)
65 self.__nextButton = self.buttonBox.addButton( 65 self.__nextButton = self.buttonBox.addButton(
66 self.trUtf8("Next >"), QDialogButtonBox.ActionRole) 66 self.tr("Next >"), QDialogButtonBox.ActionRole)
67 self.__finishButton = self.buttonBox.addButton( 67 self.__finishButton = self.buttonBox.addButton(
68 self.trUtf8("Install"), QDialogButtonBox.ActionRole) 68 self.tr("Install"), QDialogButtonBox.ActionRole)
69 69
70 self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close) 70 self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close)
71 self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel) 71 self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel)
72 72
73 userDir = self.__pluginManager.getPluginDir("user") 73 userDir = self.__pluginManager.getPluginDir("user")
74 if userDir is not None: 74 if userDir is not None:
75 self.destinationCombo.addItem( 75 self.destinationCombo.addItem(
76 self.trUtf8("User plugins directory"), 76 self.tr("User plugins directory"),
77 userDir) 77 userDir)
78 78
79 globalDir = self.__pluginManager.getPluginDir("global") 79 globalDir = self.__pluginManager.getPluginDir("global")
80 if globalDir is not None and os.access(globalDir, os.W_OK): 80 if globalDir is not None and os.access(globalDir, os.W_OK):
81 self.destinationCombo.addItem( 81 self.destinationCombo.addItem(
82 self.trUtf8("Global plugins directory"), 82 self.tr("Global plugins directory"),
83 globalDir) 83 globalDir)
84 84
85 self.__installedDirs = [] 85 self.__installedDirs = []
86 self.__installedFiles = [] 86 self.__installedFiles = []
87 87
140 self.__nextButton.setEnabled(False) 140 self.__nextButton.setEnabled(False)
141 self.__finishButton.setEnabled(True) 141 self.__finishButton.setEnabled(True)
142 self.__closeButton.hide() 142 self.__closeButton.hide()
143 self.__cancelButton.show() 143 self.__cancelButton.show()
144 144
145 msg = self.trUtf8( 145 msg = self.tr(
146 "Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\ 146 "Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\
147 .format("\n".join(self.__createArchivesList()), 147 .format("\n".join(self.__createArchivesList()),
148 self.destinationCombo.currentText(), 148 self.destinationCombo.currentText(),
149 self.destinationCombo.itemData( 149 self.destinationCombo.itemData(
150 self.destinationCombo.currentIndex()) 150 self.destinationCombo.currentIndex())
157 Private slot to select plugin ZIP-archives via a file selection dialog. 157 Private slot to select plugin ZIP-archives via a file selection dialog.
158 """ 158 """
159 dn = Preferences.getPluginManager("DownloadPath") 159 dn = Preferences.getPluginManager("DownloadPath")
160 archives = E5FileDialog.getOpenFileNames( 160 archives = E5FileDialog.getOpenFileNames(
161 self, 161 self,
162 self.trUtf8("Select plugin ZIP-archives"), 162 self.tr("Select plugin ZIP-archives"),
163 dn, 163 dn,
164 self.trUtf8("Plugin archive (*.zip)")) 164 self.tr("Plugin archive (*.zip)"))
165 165
166 if archives: 166 if archives:
167 matchflags = Qt.MatchFixedString 167 matchflags = Qt.MatchFixedString
168 if not Utilities.isWindowsPlatform(): 168 if not Utilities.isWindowsPlatform():
169 matchflags |= Qt.MatchCaseSensitive 169 matchflags |= Qt.MatchCaseSensitive
222 """ 222 """
223 res = True 223 res = True
224 self.summaryEdit.clear() 224 self.summaryEdit.clear()
225 for archive in self.__createArchivesList(): 225 for archive in self.__createArchivesList():
226 self.summaryEdit.append( 226 self.summaryEdit.append(
227 self.trUtf8("Installing {0} ...").format(archive)) 227 self.tr("Installing {0} ...").format(archive))
228 ok, msg, restart = self.__installPlugin(archive) 228 ok, msg, restart = self.__installPlugin(archive)
229 res = res and ok 229 res = res and ok
230 if ok: 230 if ok:
231 self.summaryEdit.append(self.trUtf8(" ok")) 231 self.summaryEdit.append(self.tr(" ok"))
232 else: 232 else:
233 self.summaryEdit.append(msg) 233 self.summaryEdit.append(msg)
234 if restart: 234 if restart:
235 self.__restartNeeded = True 235 self.__restartNeeded = True
236 self.summaryEdit.append("\n") 236 self.summaryEdit.append("\n")
237 if res: 237 if res:
238 self.summaryEdit.append(self.trUtf8( 238 self.summaryEdit.append(self.tr(
239 """The plugins were installed successfully.""")) 239 """The plugins were installed successfully."""))
240 else: 240 else:
241 self.summaryEdit.append(self.trUtf8( 241 self.summaryEdit.append(self.tr(
242 """Some plugins could not be installed.""")) 242 """Some plugins could not be installed."""))
243 243
244 return res 244 return res
245 245
246 def __installPlugin(self, archiveFilename): 246 def __installPlugin(self, archiveFilename):
265 archive = url[2] 265 archive = url[2]
266 266
267 # check, if the archive exists 267 # check, if the archive exists
268 if not os.path.exists(archive): 268 if not os.path.exists(archive):
269 return False, \ 269 return False, \
270 self.trUtf8( 270 self.tr(
271 """<p>The archive file <b>{0}</b> does not exist. """ 271 """<p>The archive file <b>{0}</b> does not exist. """
272 """Aborting...</p>""").format(archive), \ 272 """Aborting...</p>""").format(archive), \
273 False 273 False
274 274
275 # check, if the archive is a valid zip file 275 # check, if the archive is a valid zip file
276 if not zipfile.is_zipfile(archive): 276 if not zipfile.is_zipfile(archive):
277 return False, \ 277 return False, \
278 self.trUtf8( 278 self.tr(
279 """<p>The file <b>{0}</b> is not a valid plugin """ 279 """<p>The file <b>{0}</b> is not a valid plugin """
280 """ZIP-archive. Aborting...</p>""").format(archive), \ 280 """ZIP-archive. Aborting...</p>""").format(archive), \
281 False 281 False
282 282
283 # check, if the destination is writeable 283 # check, if the destination is writeable
284 if not os.access(destination, os.W_OK): 284 if not os.access(destination, os.W_OK):
285 return False, \ 285 return False, \
286 self.trUtf8( 286 self.tr(
287 """<p>The destination directory <b>{0}</b> is not """ 287 """<p>The destination directory <b>{0}</b> is not """
288 """writeable. Aborting...</p>""").format(destination), \ 288 """writeable. Aborting...</p>""").format(destination), \
289 False 289 False
290 290
291 zip = zipfile.ZipFile(archive, "r") 291 zip = zipfile.ZipFile(archive, "r")
300 pluginFileName = name 300 pluginFileName = name
301 break 301 break
302 302
303 if not pluginFound: 303 if not pluginFound:
304 return False, \ 304 return False, \
305 self.trUtf8( 305 self.tr(
306 """<p>The file <b>{0}</b> is not a valid plugin """ 306 """<p>The file <b>{0}</b> is not a valid plugin """
307 """ZIP-archive. Aborting...</p>""").format(archive), \ 307 """ZIP-archive. Aborting...</p>""").format(archive), \
308 False 308 False
309 309
310 # parse the plugin module's plugin header 310 # parse the plugin module's plugin header
345 elif line.startswith("# End-Of-Header"): 345 elif line.startswith("# End-Of-Header"):
346 break 346 break
347 347
348 if not packageName: 348 if not packageName:
349 return False, \ 349 return False, \
350 self.trUtf8( 350 self.tr(
351 """<p>The plugin module <b>{0}</b> does not contain """ 351 """<p>The plugin module <b>{0}</b> does not contain """
352 """a 'packageName' attribute. Aborting...</p>""")\ 352 """a 'packageName' attribute. Aborting...</p>""")\
353 .format(pluginFileName), \ 353 .format(pluginFileName), \
354 False 354 False
355 355
356 if pyqtApi < 2: 356 if pyqtApi < 2:
357 return False, \ 357 return False, \
358 self.trUtf8( 358 self.tr(
359 """<p>The plugin module <b>{0}</b> does not conform""" 359 """<p>The plugin module <b>{0}</b> does not conform"""
360 """ with the PyQt v2 API. Aborting...</p>""")\ 360 """ with the PyQt v2 API. Aborting...</p>""")\
361 .format(pluginFileName), \ 361 .format(pluginFileName), \
362 False 362 False
363 363
364 # check, if it is a plugin, that collides with others 364 # check, if it is a plugin, that collides with others
365 if not os.path.exists(os.path.join(destination, pluginFileName)) and \ 365 if not os.path.exists(os.path.join(destination, pluginFileName)) and \
366 packageName != "None" and \ 366 packageName != "None" and \
367 os.path.exists(os.path.join(destination, packageName)): 367 os.path.exists(os.path.join(destination, packageName)):
368 return False, \ 368 return False, \
369 self.trUtf8("""<p>The plugin package <b>{0}</b> exists. """ 369 self.tr("""<p>The plugin package <b>{0}</b> exists. """
370 """Aborting...</p>""")\ 370 """Aborting...</p>""")\
371 .format(os.path.join(destination, packageName)), \ 371 .format(os.path.join(destination, packageName)), \
372 False 372 False
373 373
374 if os.path.exists(os.path.join(destination, pluginFileName)) and \ 374 if os.path.exists(os.path.join(destination, pluginFileName)) and \
375 packageName != "None" and \ 375 packageName != "None" and \
376 not os.path.exists(os.path.join(destination, packageName)): 376 not os.path.exists(os.path.join(destination, packageName)):
377 return False, \ 377 return False, \
378 self.trUtf8("""<p>The plugin module <b>{0}</b> exists. """ 378 self.tr("""<p>The plugin module <b>{0}</b> exists. """
379 """Aborting...</p>""")\ 379 """Aborting...</p>""")\
380 .format(os.path.join(destination, pluginFileName)), \ 380 .format(os.path.join(destination, pluginFileName)), \
381 False 381 False
382 382
383 activatePlugin = False 383 activatePlugin = False
384 if not self.__external: 384 if not self.__external:
440 f.close() 440 f.close()
441 self.__installedFiles.append(outname) 441 self.__installedFiles.append(outname)
442 except os.error as why: 442 except os.error as why:
443 self.__rollback() 443 self.__rollback()
444 return False, \ 444 return False, \
445 self.trUtf8( 445 self.tr(
446 "Error installing plugin. Reason: {0}").format(str(why)), \ 446 "Error installing plugin. Reason: {0}").format(str(why)), \
447 False 447 False
448 except IOError as why: 448 except IOError as why:
449 self.__rollback() 449 self.__rollback()
450 return False, \ 450 return False, \
451 self.trUtf8( 451 self.tr(
452 "Error installing plugin. Reason: {0}").format(str(why)), \ 452 "Error installing plugin. Reason: {0}").format(str(why)), \
453 False 453 False
454 except OSError as why: 454 except OSError as why:
455 self.__rollback() 455 self.__rollback()
456 return False, \ 456 return False, \
457 self.trUtf8( 457 self.tr(
458 "Error installing plugin. Reason: {0}").format(str(why)), \ 458 "Error installing plugin. Reason: {0}").format(str(why)), \
459 False 459 False
460 except: 460 except:
461 sys.stderr.write("Unspecific exception installing plugin.\n") 461 sys.stderr.write("Unspecific exception installing plugin.\n")
462 self.__rollback() 462 self.__rollback()
463 return False, \ 463 return False, \
464 self.trUtf8("Unspecific exception installing plugin."), \ 464 self.tr("Unspecific exception installing plugin."), \
465 False 465 False
466 466
467 # now compile the plugins 467 # now compile the plugins
468 if doCompile: 468 if doCompile:
469 compileall.compile_dir( 469 compileall.compile_dir(
581 581
582 self.cw = PluginInstallWidget(pluginManager, pluginFileNames, self) 582 self.cw = PluginInstallWidget(pluginManager, pluginFileNames, self)
583 size = self.cw.size() 583 size = self.cw.size()
584 self.__layout.addWidget(self.cw) 584 self.__layout.addWidget(self.cw)
585 self.resize(size) 585 self.resize(size)
586 586 self.setWindowTitle(self.cw.windowTitle())
587 self.cw.buttonBox.accepted[()].connect(self.accept) 587
588 self.cw.buttonBox.rejected[()].connect(self.reject) 588 self.cw.buttonBox.accepted.connect(self.accept)
589 self.cw.buttonBox.rejected.connect(self.reject)
589 590
590 def restartNeeded(self): 591 def restartNeeded(self):
591 """ 592 """
592 Public method to check, if a restart of the IDE is required. 593 Public method to check, if a restart of the IDE is required.
593 594
611 super(PluginInstallWindow, self).__init__(parent) 612 super(PluginInstallWindow, self).__init__(parent)
612 self.cw = PluginInstallWidget(None, pluginFileNames, self) 613 self.cw = PluginInstallWidget(None, pluginFileNames, self)
613 size = self.cw.size() 614 size = self.cw.size()
614 self.setCentralWidget(self.cw) 615 self.setCentralWidget(self.cw)
615 self.resize(size) 616 self.resize(size)
617 self.setWindowTitle(self.cw.windowTitle())
616 618
617 self.setStyle(Preferences.getUI("Style"), 619 self.setStyle(Preferences.getUI("Style"),
618 Preferences.getUI("StyleSheet")) 620 Preferences.getUI("StyleSheet"))
619 621
620 self.cw.buttonBox.accepted[()].connect(self.close) 622 self.cw.buttonBox.accepted.connect(self.close)
621 self.cw.buttonBox.rejected[()].connect(self.close) 623 self.cw.buttonBox.rejected.connect(self.close)

eric ide

mercurial