PluginManager/PluginInstallDialog.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
25 import Utilities 25 import Utilities
26 import Preferences 26 import Preferences
27 27
28 from Utilities.uic import compileUiFiles 28 from Utilities.uic import compileUiFiles
29 29
30
30 class PluginInstallWidget(QWidget, Ui_PluginInstallDialog): 31 class PluginInstallWidget(QWidget, Ui_PluginInstallDialog):
31 """ 32 """
32 Class implementing the Plugin installation dialog. 33 Class implementing the Plugin installation dialog.
33 """ 34 """
34 def __init__(self, pluginManager, pluginFileNames, parent = None): 35 def __init__(self, pluginManager, pluginFileNames, parent=None):
35 """ 36 """
36 Constructor 37 Constructor
37 38
38 @param pluginManager reference to the plugin manager object 39 @param pluginManager reference to the plugin manager object
39 @param pluginFileNames list of plugin files suggested for 40 @param pluginFileNames list of plugin files suggested for
40 installation (list of strings) 41 installation (list of strings)
41 @param parent parent of this dialog (QWidget) 42 @param parent parent of this dialog (QWidget)
42 """ 43 """
43 QWidget.__init__(self, parent) 44 QWidget.__init__(self, parent)
44 self.setupUi(self) 45 self.setupUi(self)
45 46
46 if pluginManager is None: 47 if pluginManager is None:
47 # started as external plugin installer 48 # started as external plugin installer
48 self.__pluginManager = PluginManager(doLoadPlugins = False) 49 self.__pluginManager = PluginManager(doLoadPlugins=False)
49 self.__external = True 50 self.__external = True
50 else: 51 else:
51 self.__pluginManager = pluginManager 52 self.__pluginManager = pluginManager
52 self.__external = False 53 self.__external = False
53 54
61 self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close) 62 self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close)
62 self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel) 63 self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel)
63 64
64 userDir = self.__pluginManager.getPluginDir("user") 65 userDir = self.__pluginManager.getPluginDir("user")
65 if userDir is not None: 66 if userDir is not None:
66 self.destinationCombo.addItem(self.trUtf8("User plugins directory"), 67 self.destinationCombo.addItem(self.trUtf8("User plugins directory"),
67 userDir) 68 userDir)
68 69
69 globalDir = self.__pluginManager.getPluginDir("global") 70 globalDir = self.__pluginManager.getPluginDir("global")
70 if globalDir is not None and os.access(globalDir, os.W_OK): 71 if globalDir is not None and os.access(globalDir, os.W_OK):
71 self.destinationCombo.addItem(self.trUtf8("Global plugins directory"), 72 self.destinationCombo.addItem(self.trUtf8("Global plugins directory"),
72 globalDir) 73 globalDir)
73 74
74 self.__installedDirs = [] 75 self.__installedDirs = []
75 self.__installedFiles = [] 76 self.__installedFiles = []
76 77
129 self.__finishButton.setEnabled(True) 130 self.__finishButton.setEnabled(True)
130 self.__closeButton.hide() 131 self.__closeButton.hide()
131 self.__cancelButton.show() 132 self.__cancelButton.show()
132 133
133 msg = self.trUtf8("Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\ 134 msg = self.trUtf8("Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\
134 .format("\n".join(self.__createArchivesList()), 135 .format("\n".join(self.__createArchivesList()),
135 self.destinationCombo.currentText(), 136 self.destinationCombo.currentText(),
136 self.destinationCombo.itemData( 137 self.destinationCombo.itemData(
137 self.destinationCombo.currentIndex()) 138 self.destinationCombo.currentIndex())
138 ) 139 )
139 self.summaryEdit.setPlainText(msg) 140 self.summaryEdit.setPlainText(msg)
140 141
227 228
228 def __installPlugin(self, archiveFilename): 229 def __installPlugin(self, archiveFilename):
229 """ 230 """
230 Private slot to install the selected plugin. 231 Private slot to install the selected plugin.
231 232
232 @param archiveFilename name of the plugin archive 233 @param archiveFilename name of the plugin archive
233 file (string) 234 file (string)
234 @return flag indicating success (boolean), error message 235 @return flag indicating success (boolean), error message
235 upon failure (string) and flag indicating a restart 236 upon failure (string) and flag indicating a restart
236 of the IDE is required (boolean) 237 of the IDE is required (boolean)
237 """ 238 """
402 self.progress.setValue(tot) 403 self.progress.setValue(tot)
403 # now compile user interface files 404 # now compile user interface files
404 compileUiFiles(os.path.join(destination, packageName), True) 405 compileUiFiles(os.path.join(destination, packageName), True)
405 else: 406 else:
406 outname = os.path.join(destination, pluginFileName) 407 outname = os.path.join(destination, pluginFileName)
407 f = open(outname, "w", encoding = "utf-8") 408 f = open(outname, "w", encoding="utf-8")
408 f.write(pluginSource) 409 f.write(pluginSource)
409 f.close() 410 f.close()
410 self.__installedFiles.append(outname) 411 self.__installedFiles.append(outname)
411 except os.error as why: 412 except os.error as why:
412 self.__rollback() 413 self.__rollback()
429 return False, \ 430 return False, \
430 self.trUtf8("Unspecific exception installing plugin."), \ 431 self.trUtf8("Unspecific exception installing plugin."), \
431 False 432 False
432 433
433 # now compile the plugins 434 # now compile the plugins
434 compileall.compile_dir(destination, quiet = True) 435 compileall.compile_dir(destination, quiet=True)
435 436
436 if not self.__external: 437 if not self.__external:
437 # now load and activate the plugin 438 # now load and activate the plugin
438 self.__pluginManager.loadPlugin(installedPluginName, destination, reload_) 439 self.__pluginManager.loadPlugin(installedPluginName, destination, reload_)
439 if activatePlugin: 440 if activatePlugin:
450 os.remove(fname) 451 os.remove(fname)
451 for dname in self.__installedDirs: 452 for dname in self.__installedDirs:
452 if os.path.exists(dname): 453 if os.path.exists(dname):
453 shutil.rmtree(dname) 454 shutil.rmtree(dname)
454 455
455 def __makedirs(self, name, mode = 0o777): 456 def __makedirs(self, name, mode=0o777):
456 """ 457 """
457 Private method to create a directory and all intermediate ones. 458 Private method to create a directory and all intermediate ones.
458 459
459 This is an extended version of the Python one in order to 460 This is an extended version of the Python one in order to
460 record the created directories. 461 record the created directories.
502 os.remove(pluginFile) 503 os.remove(pluginFile)
503 except (IOError, OSError, os.error): 504 except (IOError, OSError, os.error):
504 # ignore some exceptions 505 # ignore some exceptions
505 pass 506 pass
506 507
508
507 class PluginInstallDialog(QDialog): 509 class PluginInstallDialog(QDialog):
508 """ 510 """
509 Class for the dialog variant. 511 Class for the dialog variant.
510 """ 512 """
511 def __init__(self, pluginManager, pluginFileNames, parent = None): 513 def __init__(self, pluginManager, pluginFileNames, parent=None):
512 """ 514 """
513 Constructor 515 Constructor
514 516
515 @param pluginManager reference to the plugin manager object 517 @param pluginManager reference to the plugin manager object
516 @param pluginFileNames list of plugin files suggested for 518 @param pluginFileNames list of plugin files suggested for
517 installation (list of strings) 519 installation (list of strings)
518 @param parent reference to the parent widget (QWidget) 520 @param parent reference to the parent widget (QWidget)
519 """ 521 """
520 QDialog.__init__(self, parent) 522 QDialog.__init__(self, parent)
521 self.setSizeGripEnabled(True) 523 self.setSizeGripEnabled(True)
538 540
539 @return flag indicating a restart is required (boolean) 541 @return flag indicating a restart is required (boolean)
540 """ 542 """
541 return self.cw.restartNeeded() 543 return self.cw.restartNeeded()
542 544
545
543 class PluginInstallWindow(QMainWindow): 546 class PluginInstallWindow(QMainWindow):
544 """ 547 """
545 Main window class for the standalone dialog. 548 Main window class for the standalone dialog.
546 """ 549 """
547 def __init__(self, pluginFileNames, parent = None): 550 def __init__(self, pluginFileNames, parent=None):
548 """ 551 """
549 Constructor 552 Constructor
550 553
551 @param pluginFileNames list of plugin files suggested for 554 @param pluginFileNames list of plugin files suggested for
552 installation (list of strings) 555 installation (list of strings)
553 @param parent reference to the parent widget (QWidget) 556 @param parent reference to the parent widget (QWidget)
554 """ 557 """
555 QMainWindow.__init__(self, parent) 558 QMainWindow.__init__(self, parent)
556 self.cw = PluginInstallWidget(None, pluginFileNames, self) 559 self.cw = PluginInstallWidget(None, pluginFileNames, self)

eric ide

mercurial