PluginManager/PluginManager.py

changeset 3190
a9a94491c4fd
parent 3171
2c37b9a37b2d
child 3200
83bde5e6f146
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
182 f = open(fname, "w") 182 f = open(fname, "w")
183 f.close() 183 f.close()
184 except IOError: 184 except IOError:
185 return ( 185 return (
186 False, 186 False,
187 self.trUtf8("Could not create a package for {0}.") 187 self.tr("Could not create a package for {0}.")
188 .format(self.__develPluginFile)) 188 .format(self.__develPluginFile))
189 189
190 if Preferences.getPluginManager("ActivateExternal"): 190 if Preferences.getPluginManager("ActivateExternal"):
191 fname = os.path.join(self.pluginDirs["user"], "__init__.py") 191 fname = os.path.join(self.pluginDirs["user"], "__init__.py")
192 if not os.path.exists(fname): 192 if not os.path.exists(fname):
217 del self.pluginDirs["global"] 217 del self.pluginDirs["global"]
218 218
219 if not os.path.exists(self.pluginDirs["eric5"]): 219 if not os.path.exists(self.pluginDirs["eric5"]):
220 return ( 220 return (
221 False, 221 False,
222 self.trUtf8( 222 self.tr(
223 "The internal plugin directory <b>{0}</b>" 223 "The internal plugin directory <b>{0}</b>"
224 " does not exits.").format(self.pluginDirs["eric5"])) 224 " does not exits.").format(self.pluginDirs["eric5"]))
225 225
226 return (True, "") 226 return (True, "")
227 227
334 """ 334 """
335 try: 335 try:
336 fname = "{0}.py".format(os.path.join(directory, name)) 336 fname = "{0}.py".format(os.path.join(directory, name))
337 module = imp.load_source(name, fname) 337 module = imp.load_source(name, fname)
338 if not hasattr(module, "autoactivate"): 338 if not hasattr(module, "autoactivate"):
339 module.error = self.trUtf8( 339 module.error = self.tr(
340 "Module is missing the 'autoactivate' attribute.") 340 "Module is missing the 'autoactivate' attribute.")
341 self.__failedModules[name] = module 341 self.__failedModules[name] = module
342 raise PluginLoadError(name) 342 raise PluginLoadError(name)
343 if getattr(module, "autoactivate"): 343 if getattr(module, "autoactivate"):
344 self.__inactiveModules[name] = module 344 self.__inactiveModules[name] = module
345 else: 345 else:
346 if not hasattr(module, "pluginType") or \ 346 if not hasattr(module, "pluginType") or \
347 not hasattr(module, "pluginTypename"): 347 not hasattr(module, "pluginTypename"):
348 module.error = \ 348 module.error = \
349 self.trUtf8("Module is missing the 'pluginType' " 349 self.tr("Module is missing the 'pluginType' "
350 "and/or 'pluginTypename' attributes.") 350 "and/or 'pluginTypename' attributes.")
351 self.__failedModules[name] = module 351 self.__failedModules[name] = module
352 raise PluginLoadError(name) 352 raise PluginLoadError(name)
353 else: 353 else:
354 self.__onDemandInactiveModules[name] = module 354 self.__onDemandInactiveModules[name] = module
355 module.eric5PluginModuleName = name 355 module.eric5PluginModuleName = name
359 imp.reload(module) 359 imp.reload(module)
360 except PluginLoadError: 360 except PluginLoadError:
361 print("Error loading plugin module:", name) 361 print("Error loading plugin module:", name)
362 except Exception as err: 362 except Exception as err:
363 module = imp.new_module(name) 363 module = imp.new_module(name)
364 module.error = self.trUtf8( 364 module.error = self.tr(
365 "Module failed to load. Error: {0}").format(str(err)) 365 "Module failed to load. Error: {0}").format(str(err))
366 self.__failedModules[name] = module 366 self.__failedModules[name] = module
367 print("Error loading plugin module:", name) 367 print("Error loading plugin module:", name)
368 print(str(err)) 368 print(str(err))
369 369
514 pluginObject = pluginClass(self.__ui) 514 pluginObject = pluginClass(self.__ui)
515 self.pluginAboutToBeActivated.emit(name, pluginObject) 515 self.pluginAboutToBeActivated.emit(name, pluginObject)
516 try: 516 try:
517 obj, ok = pluginObject.activate() 517 obj, ok = pluginObject.activate()
518 except TypeError: 518 except TypeError:
519 module.error = self.trUtf8( 519 module.error = self.tr(
520 "Incompatible plugin activation method.") 520 "Incompatible plugin activation method.")
521 obj = None 521 obj = None
522 ok = True 522 ok = True
523 except Exception as err: 523 except Exception as err:
524 module.error = str(err) 524 module.error = str(err)
1020 try: 1020 try:
1021 os.mkdir(downloadDir, 0o755) 1021 os.mkdir(downloadDir, 0o755)
1022 except (OSError, IOError) as err: 1022 except (OSError, IOError) as err:
1023 E5MessageBox.critical( 1023 E5MessageBox.critical(
1024 self.__ui, 1024 self.__ui,
1025 self.trUtf8("Plugin Manager Error"), 1025 self.tr("Plugin Manager Error"),
1026 self.trUtf8( 1026 self.tr(
1027 """<p>The plugin download directory""" 1027 """<p>The plugin download directory"""
1028 """ <b>{0}</b> could not be created. Please""" 1028 """ <b>{0}</b> could not be created. Please"""
1029 """ configure it via the configuration""" 1029 """ configure it via the configuration"""
1030 """ dialog.</p><p>Reason: {1}</p>""") 1030 """ dialog.</p><p>Reason: {1}</p>""")
1031 .format(downloadDir, str(err))) 1031 .format(downloadDir, str(err)))
1083 if reply in self.__replies: 1083 if reply in self.__replies:
1084 self.__replies.remove(reply) 1084 self.__replies.remove(reply)
1085 if reply.error() != QNetworkReply.NoError: 1085 if reply.error() != QNetworkReply.NoError:
1086 E5MessageBox.warning( 1086 E5MessageBox.warning(
1087 None, 1087 None,
1088 self.trUtf8("Error downloading file"), 1088 self.tr("Error downloading file"),
1089 self.trUtf8( 1089 self.tr(
1090 """<p>Could not download the requested file""" 1090 """<p>Could not download the requested file"""
1091 """ from {0}.</p><p>Error: {1}</p>""" 1091 """ from {0}.</p><p>Error: {1}</p>"""
1092 ).format(Preferences.getUI("PluginRepositoryUrl5"), 1092 ).format(Preferences.getUI("PluginRepositoryUrl5"),
1093 reply.errorString()) 1093 reply.errorString())
1094 ) 1094 )
1118 return 1118 return
1119 1119
1120 if self.__updateAvailable: 1120 if self.__updateAvailable:
1121 res = E5MessageBox.information( 1121 res = E5MessageBox.information(
1122 None, 1122 None,
1123 self.trUtf8("New plugin versions available"), 1123 self.tr("New plugin versions available"),
1124 self.trUtf8("<p>There are new plug-ins or plug-in" 1124 self.tr("<p>There are new plug-ins or plug-in"
1125 " updates available. Use the plug-in" 1125 " updates available. Use the plug-in"
1126 " repository dialog to get them.</p>"), 1126 " repository dialog to get them.</p>"),
1127 E5MessageBox.StandardButtons( 1127 E5MessageBox.StandardButtons(
1128 E5MessageBox.Ignore | 1128 E5MessageBox.Ignore |
1129 E5MessageBox.Open), 1129 E5MessageBox.Open),
1130 E5MessageBox.Open) 1130 E5MessageBox.Open)
1131 if res == E5MessageBox.Open: 1131 if res == E5MessageBox.Open:

eric ide

mercurial