PluginManager/PluginInstallDialog.py

changeset 3190
a9a94491c4fd
parent 3189
9a21c547de5f
child 3345
071afe8be2a1
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
54 else: 54 else:
55 self.__pluginManager = pluginManager 55 self.__pluginManager = pluginManager
56 self.__external = False 56 self.__external = False
57 57
58 self.__backButton = self.buttonBox.addButton( 58 self.__backButton = self.buttonBox.addButton(
59 self.trUtf8("< Back"), QDialogButtonBox.ActionRole) 59 self.tr("< Back"), QDialogButtonBox.ActionRole)
60 self.__nextButton = self.buttonBox.addButton( 60 self.__nextButton = self.buttonBox.addButton(
61 self.trUtf8("Next >"), QDialogButtonBox.ActionRole) 61 self.tr("Next >"), QDialogButtonBox.ActionRole)
62 self.__finishButton = self.buttonBox.addButton( 62 self.__finishButton = self.buttonBox.addButton(
63 self.trUtf8("Install"), QDialogButtonBox.ActionRole) 63 self.tr("Install"), QDialogButtonBox.ActionRole)
64 64
65 self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close) 65 self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close)
66 self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel) 66 self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel)
67 67
68 userDir = self.__pluginManager.getPluginDir("user") 68 userDir = self.__pluginManager.getPluginDir("user")
69 if userDir is not None: 69 if userDir is not None:
70 self.destinationCombo.addItem( 70 self.destinationCombo.addItem(
71 self.trUtf8("User plugins directory"), 71 self.tr("User plugins directory"),
72 userDir) 72 userDir)
73 73
74 globalDir = self.__pluginManager.getPluginDir("global") 74 globalDir = self.__pluginManager.getPluginDir("global")
75 if globalDir is not None and os.access(globalDir, os.W_OK): 75 if globalDir is not None and os.access(globalDir, os.W_OK):
76 self.destinationCombo.addItem( 76 self.destinationCombo.addItem(
77 self.trUtf8("Global plugins directory"), 77 self.tr("Global plugins directory"),
78 globalDir) 78 globalDir)
79 79
80 self.__installedDirs = [] 80 self.__installedDirs = []
81 self.__installedFiles = [] 81 self.__installedFiles = []
82 82
135 self.__nextButton.setEnabled(False) 135 self.__nextButton.setEnabled(False)
136 self.__finishButton.setEnabled(True) 136 self.__finishButton.setEnabled(True)
137 self.__closeButton.hide() 137 self.__closeButton.hide()
138 self.__cancelButton.show() 138 self.__cancelButton.show()
139 139
140 msg = self.trUtf8( 140 msg = self.tr(
141 "Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\ 141 "Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\
142 .format("\n".join(self.__createArchivesList()), 142 .format("\n".join(self.__createArchivesList()),
143 self.destinationCombo.currentText(), 143 self.destinationCombo.currentText(),
144 self.destinationCombo.itemData( 144 self.destinationCombo.itemData(
145 self.destinationCombo.currentIndex()) 145 self.destinationCombo.currentIndex())
152 Private slot to select plugin ZIP-archives via a file selection dialog. 152 Private slot to select plugin ZIP-archives via a file selection dialog.
153 """ 153 """
154 dn = Preferences.getPluginManager("DownloadPath") 154 dn = Preferences.getPluginManager("DownloadPath")
155 archives = E5FileDialog.getOpenFileNames( 155 archives = E5FileDialog.getOpenFileNames(
156 self, 156 self,
157 self.trUtf8("Select plugin ZIP-archives"), 157 self.tr("Select plugin ZIP-archives"),
158 dn, 158 dn,
159 self.trUtf8("Plugin archive (*.zip)")) 159 self.tr("Plugin archive (*.zip)"))
160 160
161 if archives: 161 if archives:
162 matchflags = Qt.MatchFixedString 162 matchflags = Qt.MatchFixedString
163 if not Utilities.isWindowsPlatform(): 163 if not Utilities.isWindowsPlatform():
164 matchflags |= Qt.MatchCaseSensitive 164 matchflags |= Qt.MatchCaseSensitive
217 """ 217 """
218 res = True 218 res = True
219 self.summaryEdit.clear() 219 self.summaryEdit.clear()
220 for archive in self.__createArchivesList(): 220 for archive in self.__createArchivesList():
221 self.summaryEdit.append( 221 self.summaryEdit.append(
222 self.trUtf8("Installing {0} ...").format(archive)) 222 self.tr("Installing {0} ...").format(archive))
223 ok, msg, restart = self.__installPlugin(archive) 223 ok, msg, restart = self.__installPlugin(archive)
224 res = res and ok 224 res = res and ok
225 if ok: 225 if ok:
226 self.summaryEdit.append(self.trUtf8(" ok")) 226 self.summaryEdit.append(self.tr(" ok"))
227 else: 227 else:
228 self.summaryEdit.append(msg) 228 self.summaryEdit.append(msg)
229 if restart: 229 if restart:
230 self.__restartNeeded = True 230 self.__restartNeeded = True
231 self.summaryEdit.append("\n") 231 self.summaryEdit.append("\n")
232 if res: 232 if res:
233 self.summaryEdit.append(self.trUtf8( 233 self.summaryEdit.append(self.tr(
234 """The plugins were installed successfully.""")) 234 """The plugins were installed successfully."""))
235 else: 235 else:
236 self.summaryEdit.append(self.trUtf8( 236 self.summaryEdit.append(self.tr(
237 """Some plugins could not be installed.""")) 237 """Some plugins could not be installed."""))
238 238
239 return res 239 return res
240 240
241 def __installPlugin(self, archiveFilename): 241 def __installPlugin(self, archiveFilename):
260 archive = url[2] 260 archive = url[2]
261 261
262 # check, if the archive exists 262 # check, if the archive exists
263 if not os.path.exists(archive): 263 if not os.path.exists(archive):
264 return False, \ 264 return False, \
265 self.trUtf8( 265 self.tr(
266 """<p>The archive file <b>{0}</b> does not exist. """ 266 """<p>The archive file <b>{0}</b> does not exist. """
267 """Aborting...</p>""").format(archive), \ 267 """Aborting...</p>""").format(archive), \
268 False 268 False
269 269
270 # check, if the archive is a valid zip file 270 # check, if the archive is a valid zip file
271 if not zipfile.is_zipfile(archive): 271 if not zipfile.is_zipfile(archive):
272 return False, \ 272 return False, \
273 self.trUtf8( 273 self.tr(
274 """<p>The file <b>{0}</b> is not a valid plugin """ 274 """<p>The file <b>{0}</b> is not a valid plugin """
275 """ZIP-archive. Aborting...</p>""").format(archive), \ 275 """ZIP-archive. Aborting...</p>""").format(archive), \
276 False 276 False
277 277
278 # check, if the destination is writeable 278 # check, if the destination is writeable
279 if not os.access(destination, os.W_OK): 279 if not os.access(destination, os.W_OK):
280 return False, \ 280 return False, \
281 self.trUtf8( 281 self.tr(
282 """<p>The destination directory <b>{0}</b> is not """ 282 """<p>The destination directory <b>{0}</b> is not """
283 """writeable. Aborting...</p>""").format(destination), \ 283 """writeable. Aborting...</p>""").format(destination), \
284 False 284 False
285 285
286 zip = zipfile.ZipFile(archive, "r") 286 zip = zipfile.ZipFile(archive, "r")
295 pluginFileName = name 295 pluginFileName = name
296 break 296 break
297 297
298 if not pluginFound: 298 if not pluginFound:
299 return False, \ 299 return False, \
300 self.trUtf8( 300 self.tr(
301 """<p>The file <b>{0}</b> is not a valid plugin """ 301 """<p>The file <b>{0}</b> is not a valid plugin """
302 """ZIP-archive. Aborting...</p>""").format(archive), \ 302 """ZIP-archive. Aborting...</p>""").format(archive), \
303 False 303 False
304 304
305 # parse the plugin module's plugin header 305 # parse the plugin module's plugin header
340 elif line.startswith("# End-Of-Header"): 340 elif line.startswith("# End-Of-Header"):
341 break 341 break
342 342
343 if not packageName: 343 if not packageName:
344 return False, \ 344 return False, \
345 self.trUtf8( 345 self.tr(
346 """<p>The plugin module <b>{0}</b> does not contain """ 346 """<p>The plugin module <b>{0}</b> does not contain """
347 """a 'packageName' attribute. Aborting...</p>""")\ 347 """a 'packageName' attribute. Aborting...</p>""")\
348 .format(pluginFileName), \ 348 .format(pluginFileName), \
349 False 349 False
350 350
351 if pyqtApi < 2: 351 if pyqtApi < 2:
352 return False, \ 352 return False, \
353 self.trUtf8( 353 self.tr(
354 """<p>The plugin module <b>{0}</b> does not conform""" 354 """<p>The plugin module <b>{0}</b> does not conform"""
355 """ with the PyQt v2 API. Aborting...</p>""")\ 355 """ with the PyQt v2 API. Aborting...</p>""")\
356 .format(pluginFileName), \ 356 .format(pluginFileName), \
357 False 357 False
358 358
359 # check, if it is a plugin, that collides with others 359 # check, if it is a plugin, that collides with others
360 if not os.path.exists(os.path.join(destination, pluginFileName)) and \ 360 if not os.path.exists(os.path.join(destination, pluginFileName)) and \
361 packageName != "None" and \ 361 packageName != "None" and \
362 os.path.exists(os.path.join(destination, packageName)): 362 os.path.exists(os.path.join(destination, packageName)):
363 return False, \ 363 return False, \
364 self.trUtf8("""<p>The plugin package <b>{0}</b> exists. """ 364 self.tr("""<p>The plugin package <b>{0}</b> exists. """
365 """Aborting...</p>""")\ 365 """Aborting...</p>""")\
366 .format(os.path.join(destination, packageName)), \ 366 .format(os.path.join(destination, packageName)), \
367 False 367 False
368 368
369 if os.path.exists(os.path.join(destination, pluginFileName)) and \ 369 if os.path.exists(os.path.join(destination, pluginFileName)) and \
370 packageName != "None" and \ 370 packageName != "None" and \
371 not os.path.exists(os.path.join(destination, packageName)): 371 not os.path.exists(os.path.join(destination, packageName)):
372 return False, \ 372 return False, \
373 self.trUtf8("""<p>The plugin module <b>{0}</b> exists. """ 373 self.tr("""<p>The plugin module <b>{0}</b> exists. """
374 """Aborting...</p>""")\ 374 """Aborting...</p>""")\
375 .format(os.path.join(destination, pluginFileName)), \ 375 .format(os.path.join(destination, pluginFileName)), \
376 False 376 False
377 377
378 activatePlugin = False 378 activatePlugin = False
379 if not self.__external: 379 if not self.__external:
435 f.close() 435 f.close()
436 self.__installedFiles.append(outname) 436 self.__installedFiles.append(outname)
437 except os.error as why: 437 except os.error as why:
438 self.__rollback() 438 self.__rollback()
439 return False, \ 439 return False, \
440 self.trUtf8( 440 self.tr(
441 "Error installing plugin. Reason: {0}").format(str(why)), \ 441 "Error installing plugin. Reason: {0}").format(str(why)), \
442 False 442 False
443 except IOError as why: 443 except IOError as why:
444 self.__rollback() 444 self.__rollback()
445 return False, \ 445 return False, \
446 self.trUtf8( 446 self.tr(
447 "Error installing plugin. Reason: {0}").format(str(why)), \ 447 "Error installing plugin. Reason: {0}").format(str(why)), \
448 False 448 False
449 except OSError as why: 449 except OSError as why:
450 self.__rollback() 450 self.__rollback()
451 return False, \ 451 return False, \
452 self.trUtf8( 452 self.tr(
453 "Error installing plugin. Reason: {0}").format(str(why)), \ 453 "Error installing plugin. Reason: {0}").format(str(why)), \
454 False 454 False
455 except: 455 except:
456 print("Unspecific exception installing plugin.", file=sys.stderr) 456 print("Unspecific exception installing plugin.", file=sys.stderr)
457 self.__rollback() 457 self.__rollback()
458 return False, \ 458 return False, \
459 self.trUtf8("Unspecific exception installing plugin."), \ 459 self.tr("Unspecific exception installing plugin."), \
460 False 460 False
461 461
462 # now compile the plugins 462 # now compile the plugins
463 if doCompile: 463 if doCompile:
464 compileall.compile_dir( 464 compileall.compile_dir(

eric ide

mercurial