PluginManager/PluginUninstallDialog.py

changeset 2992
dbdf27746da5
parent 2889
3737e9f17f44
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
2991:226481ff40d1 2992:dbdf27746da5
49 self.__external = True 49 self.__external = True
50 else: 50 else:
51 self.__pluginManager = pluginManager 51 self.__pluginManager = pluginManager
52 self.__external = False 52 self.__external = False
53 53
54 self.pluginDirectoryCombo.addItem(self.trUtf8("User plugins directory"), 54 self.pluginDirectoryCombo.addItem(
55 self.trUtf8("User plugins directory"),
55 self.__pluginManager.getPluginDir("user")) 56 self.__pluginManager.getPluginDir("user"))
56 57
57 globalDir = self.__pluginManager.getPluginDir("global") 58 globalDir = self.__pluginManager.getPluginDir("global")
58 if globalDir is not None and os.access(globalDir, os.W_OK): 59 if globalDir is not None and os.access(globalDir, os.W_OK):
59 self.pluginDirectoryCombo.addItem(self.trUtf8("Global plugins directory"), 60 self.pluginDirectoryCombo.addItem(
61 self.trUtf8("Global plugins directory"),
60 globalDir) 62 globalDir)
61 63
62 @pyqtSlot(int) 64 @pyqtSlot(int)
63 def on_pluginDirectoryCombo_currentIndexChanged(self, index): 65 def on_pluginDirectoryCombo_currentIndexChanged(self, index):
64 """ 66 """
67 69
68 @param index index of the selected item (integer) 70 @param index index of the selected item (integer)
69 """ 71 """
70 pluginDirectory = self.pluginDirectoryCombo\ 72 pluginDirectory = self.pluginDirectoryCombo\
71 .itemData(index) 73 .itemData(index)
72 pluginNames = sorted(self.__pluginManager.getPluginModules(pluginDirectory)) 74 pluginNames = sorted(self.__pluginManager.getPluginModules(
75 pluginDirectory))
73 self.pluginNameCombo.clear() 76 self.pluginNameCombo.clear()
74 for pluginName in pluginNames: 77 for pluginName in pluginNames:
75 fname = "{0}.py".format(os.path.join(pluginDirectory, pluginName)) 78 fname = "{0}.py".format(os.path.join(pluginDirectory, pluginName))
76 self.pluginNameCombo.addItem(pluginName, fname) 79 self.pluginNameCombo.addItem(pluginName, fname)
77 self.buttonBox.button(QDialogButtonBox.Ok)\ 80 self.buttonBox.button(QDialogButtonBox.Ok)\
98 .itemData(self.pluginNameCombo.currentIndex()) 101 .itemData(self.pluginNameCombo.currentIndex())
99 102
100 if not self.__pluginManager.unloadPlugin(pluginName): 103 if not self.__pluginManager.unloadPlugin(pluginName):
101 E5MessageBox.critical(self, 104 E5MessageBox.critical(self,
102 self.trUtf8("Plugin Uninstallation"), 105 self.trUtf8("Plugin Uninstallation"),
103 self.trUtf8("""<p>The plugin <b>{0}</b> could not be unloaded.""" 106 self.trUtf8(
104 """ Aborting...</p>""").format(pluginName)) 107 """<p>The plugin <b>{0}</b> could not be unloaded."""
108 """ Aborting...</p>""").format(pluginName))
105 return False 109 return False
106 110
107 if not pluginDirectory in sys.path: 111 if not pluginDirectory in sys.path:
108 sys.path.insert(2, pluginDirectory) 112 sys.path.insert(2, pluginDirectory)
109 module = imp.load_source(pluginName, pluginFile) 113 module = imp.load_source(pluginName, pluginFile)
110 if not hasattr(module, "packageName"): 114 if not hasattr(module, "packageName"):
111 E5MessageBox.critical(self, 115 E5MessageBox.critical(self,
112 self.trUtf8("Plugin Uninstallation"), 116 self.trUtf8("Plugin Uninstallation"),
113 self.trUtf8("""<p>The plugin <b>{0}</b> has no 'packageName' attribute.""" 117 self.trUtf8(
114 """ Aborting...</p>""").format(pluginName)) 118 """<p>The plugin <b>{0}</b> has no 'packageName'"""
119 """ attribute. Aborting...</p>""").format(pluginName))
115 return False 120 return False
116 121
117 package = getattr(module, "packageName") 122 package = getattr(module, "packageName")
118 if package is None: 123 if package is None:
119 package = "None" 124 package = "None"
123 if hasattr(module, "prepareUninstall"): 128 if hasattr(module, "prepareUninstall"):
124 module.prepareUninstall() 129 module.prepareUninstall()
125 internalPackages = [] 130 internalPackages = []
126 if hasattr(module, "internalPackages"): 131 if hasattr(module, "internalPackages"):
127 # it is a comma separated string 132 # it is a comma separated string
128 internalPackages = [p.strip() for p in module.internalPackages.split(",")] 133 internalPackages = [p.strip() for p in
134 module.internalPackages.split(",")]
129 del module 135 del module
130 136
131 # clean sys.modules 137 # clean sys.modules
132 self.__pluginManager.removePluginFromSysModules( 138 self.__pluginManager.removePluginFromSysModules(
133 pluginName, package, internalPackages) 139 pluginName, package, internalPackages)
142 148
143 fnamec = "{0}c".format(pluginFile) 149 fnamec = "{0}c".format(pluginFile)
144 if os.path.exists(fnamec): 150 if os.path.exists(fnamec):
145 os.remove(fnamec) 151 os.remove(fnamec)
146 152
147 pluginDirCache = os.path.join(os.path.dirname(pluginFile), "__pycache__") 153 pluginDirCache = os.path.join(
154 os.path.dirname(pluginFile), "__pycache__")
148 if os.path.exists(pluginDirCache): 155 if os.path.exists(pluginDirCache):
149 pluginFileName = os.path.splitext(os.path.basename(pluginFile))[0] 156 pluginFileName = os.path.splitext(
150 for fnameo in glob.glob( 157 os.path.basename(pluginFile))[0]
151 os.path.join(pluginDirCache, "{0}*.pyo".format(pluginFileName))): 158 for fnameo in glob.glob(os.path.join(
159 pluginDirCache, "{0}*.pyo".format(pluginFileName))):
152 os.remove(fnameo) 160 os.remove(fnameo)
153 for fnamec in glob.glob( 161 for fnamec in glob.glob(os.path.join(
154 os.path.join(pluginDirCache, "{0}*.pyc".format(pluginFileName))): 162 pluginDirCache, "{0}*.pyc".format(pluginFileName))):
155 os.remove(fnamec) 163 os.remove(fnamec)
156 164
157 os.remove(pluginFile) 165 os.remove(pluginFile)
158 except OSError as err: 166 except OSError as err:
159 E5MessageBox.critical(self, 167 E5MessageBox.critical(self,
160 self.trUtf8("Plugin Uninstallation"), 168 self.trUtf8("Plugin Uninstallation"),
161 self.trUtf8("""<p>The plugin package <b>{0}</b> could not be""" 169 self.trUtf8(
162 """ removed. Aborting...</p>""" 170 """<p>The plugin package <b>{0}</b> could not be"""
163 """<p>Reason: {1}</p>""").format(packageDir, str(err))) 171 """ removed. Aborting...</p>"""
172 """<p>Reason: {1}</p>""").format(packageDir, str(err)))
164 return False 173 return False
165 174
166 if not self.__external: 175 if not self.__external:
167 ui = e5App().getObject("UserInterface") 176 ui = e5App().getObject("UserInterface")
168 if ui.notificationsEnabled(): 177 if ui.notificationsEnabled():
169 ui.showNotification(UI.PixmapCache.getPixmap("plugin48.png"), 178 ui.showNotification(UI.PixmapCache.getPixmap("plugin48.png"),
170 self.trUtf8("Plugin Uninstallation"), 179 self.trUtf8("Plugin Uninstallation"),
171 self.trUtf8("""<p>The plugin <b>{0}</b> was uninstalled successfully""" 180 self.trUtf8(
172 """ from {1}.</p>""")\ 181 """<p>The plugin <b>{0}</b> was uninstalled successfully"""
182 """ from {1}.</p>""")\
173 .format(pluginName, pluginDirectory)) 183 .format(pluginName, pluginDirectory))
174 return True 184 return True
175 185
176 E5MessageBox.information(self, 186 E5MessageBox.information(self,
177 self.trUtf8("Plugin Uninstallation"), 187 self.trUtf8("Plugin Uninstallation"),
178 self.trUtf8("""<p>The plugin <b>{0}</b> was uninstalled successfully""" 188 self.trUtf8(
179 """ from {1}.</p>""")\ 189 """<p>The plugin <b>{0}</b> was uninstalled successfully"""
190 """ from {1}.</p>""")\
180 .format(pluginName, pluginDirectory)) 191 .format(pluginName, pluginDirectory))
181 return True 192 return True
182 193
183 194
184 class PluginUninstallDialog(QDialog): 195 class PluginUninstallDialog(QDialog):
222 self.cw = PluginUninstallWidget(None, self) 233 self.cw = PluginUninstallWidget(None, self)
223 size = self.cw.size() 234 size = self.cw.size()
224 self.setCentralWidget(self.cw) 235 self.setCentralWidget(self.cw)
225 self.resize(size) 236 self.resize(size)
226 237
227 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) 238 self.setStyle(Preferences.getUI("Style"),
239 Preferences.getUI("StyleSheet"))
228 240
229 self.cw.buttonBox.accepted[()].connect(self.close) 241 self.cw.buttonBox.accepted[()].connect(self.close)
230 self.cw.buttonBox.rejected[()].connect(self.close) 242 self.cw.buttonBox.rejected[()].connect(self.close)

eric ide

mercurial