PluginManager/PluginManager.py

changeset 3670
f0cb7579c0b4
parent 3656
441956d8fce5
child 3676
2f62b060a931
equal deleted inserted replaced
3669:ac84ac3c0f05 3670:f0cb7579c0b4
36 import UI.PixmapCache 36 import UI.PixmapCache
37 37
38 import Utilities 38 import Utilities
39 import Preferences 39 import Preferences
40 40
41 from eric5config import getConfig 41 from eric6config import getConfig
42 42
43 43
44 class PluginManager(QObject): 44 class PluginManager(QObject):
45 """ 45 """
46 Class implementing the Plugin Manager. 46 Class implementing the Plugin Manager.
67 def __init__(self, parent=None, doLoadPlugins=True, develPlugin=None): 67 def __init__(self, parent=None, doLoadPlugins=True, develPlugin=None):
68 """ 68 """
69 Constructor 69 Constructor
70 70
71 The Plugin Manager deals with three different plugin directories. 71 The Plugin Manager deals with three different plugin directories.
72 The first is the one, that is part of eric5 (eric5/Plugins). The 72 The first is the one, that is part of eric6 (eric6/Plugins). The
73 second one is the global plugin directory called 'eric5plugins', 73 second one is the global plugin directory called 'eric6plugins',
74 which is located inside the site-packages directory. The last one 74 which is located inside the site-packages directory. The last one
75 is the user plugin directory located inside the .eric5 directory 75 is the user plugin directory located inside the .eric6 directory
76 of the users home directory. 76 of the users home directory.
77 77
78 @param parent reference to the parent object (QObject) 78 @param parent reference to the parent object (QObject)
79 @keyparam doLoadPlugins flag indicating, that plugins should 79 @keyparam doLoadPlugins flag indicating, that plugins should
80 be loaded (boolean) 80 be loaded (boolean)
89 self.__develPluginName = None 89 self.__develPluginName = None
90 90
91 self.__inactivePluginsKey = "PluginManager/InactivePlugins" 91 self.__inactivePluginsKey = "PluginManager/InactivePlugins"
92 92
93 self.pluginDirs = { 93 self.pluginDirs = {
94 "eric5": os.path.join(getConfig('ericDir'), "Plugins"), 94 "eric6": os.path.join(getConfig('ericDir'), "Plugins"),
95 "global": os.path.join(Utilities.getPythonModulesDirectory(), 95 "global": os.path.join(Utilities.getPythonModulesDirectory(),
96 "eric5plugins"), 96 "eric6plugins"),
97 "user": os.path.join(Utilities.getConfigDir(), "eric5plugins"), 97 "user": os.path.join(Utilities.getConfigDir(), "eric6plugins"),
98 } 98 }
99 self.__priorityOrder = ["eric5", "global", "user"] 99 self.__priorityOrder = ["eric6", "global", "user"]
100 100
101 self.__defaultDownloadDir = os.path.join( 101 self.__defaultDownloadDir = os.path.join(
102 Utilities.getConfigDir(), "Downloads") 102 Utilities.getConfigDir(), "Downloads")
103 103
104 self.__activePlugins = {} 104 self.__activePlugins = {}
216 del self.pluginDirs["global"] 216 del self.pluginDirs["global"]
217 else: 217 else:
218 del self.pluginDirs["user"] 218 del self.pluginDirs["user"]
219 del self.pluginDirs["global"] 219 del self.pluginDirs["global"]
220 220
221 if not os.path.exists(self.pluginDirs["eric5"]): 221 if not os.path.exists(self.pluginDirs["eric6"]):
222 return ( 222 return (
223 False, 223 False,
224 self.tr( 224 self.tr(
225 "The internal plugin directory <b>{0}</b>" 225 "The internal plugin directory <b>{0}</b>"
226 " does not exits.").format(self.pluginDirs["eric5"])) 226 " does not exits.").format(self.pluginDirs["eric6"]))
227 227
228 return (True, "") 228 return (True, "")
229 229
230 def __pluginModulesExist(self): 230 def __pluginModulesExist(self):
231 """ 231 """
236 if self.__develPluginFile and \ 236 if self.__develPluginFile and \
237 not os.path.exists(self.__develPluginFile): 237 not os.path.exists(self.__develPluginFile):
238 return False 238 return False
239 239
240 self.__foundCoreModules = self.getPluginModules( 240 self.__foundCoreModules = self.getPluginModules(
241 self.pluginDirs["eric5"]) 241 self.pluginDirs["eric6"])
242 if "global" in self.pluginDirs: 242 if "global" in self.pluginDirs:
243 self.__foundGlobalModules = \ 243 self.__foundGlobalModules = \
244 self.getPluginModules(self.pluginDirs["global"]) 244 self.getPluginModules(self.pluginDirs["global"])
245 if "user" in self.pluginDirs: 245 if "user" in self.pluginDirs:
246 self.__foundUserModules = \ 246 self.__foundUserModules = \
301 for pluginName in self.__foundCoreModules: 301 for pluginName in self.__foundCoreModules:
302 # global and user plugins have priority 302 # global and user plugins have priority
303 if pluginName not in self.__foundGlobalModules and \ 303 if pluginName not in self.__foundGlobalModules and \
304 pluginName not in self.__foundUserModules and \ 304 pluginName not in self.__foundUserModules and \
305 pluginName != develPluginName: 305 pluginName != develPluginName:
306 self.loadPlugin(pluginName, self.pluginDirs["eric5"]) 306 self.loadPlugin(pluginName, self.pluginDirs["eric6"])
307 307
308 for pluginName in self.__foundGlobalModules: 308 for pluginName in self.__foundGlobalModules:
309 # user plugins have priority 309 # user plugins have priority
310 if pluginName not in self.__foundUserModules and \ 310 if pluginName not in self.__foundUserModules and \
311 pluginName != develPluginName: 311 pluginName != develPluginName:
367 "and/or 'pluginTypename' attributes.") 367 "and/or 'pluginTypename' attributes.")
368 self.__failedModules[name] = module 368 self.__failedModules[name] = module
369 raise PluginLoadError(name) 369 raise PluginLoadError(name)
370 else: 370 else:
371 self.__onDemandInactiveModules[name] = module 371 self.__onDemandInactiveModules[name] = module
372 module.eric5PluginModuleName = name 372 module.eric6PluginModuleName = name
373 module.eric5PluginModuleFilename = fname 373 module.eric6PluginModuleFilename = fname
374 self.__modulesCount += 1 374 self.__modulesCount += 1
375 if reload_: 375 if reload_:
376 imp.reload(module) 376 imp.reload(module)
377 except PluginLoadError: 377 except PluginLoadError:
378 print("Error loading plug-in module:", name) 378 print("Error loading plug-in module:", name)
467 module = self.__onDemandInactiveModules[name] 467 module = self.__onDemandInactiveModules[name]
468 except KeyError: 468 except KeyError:
469 return 469 return
470 470
471 if not self.__canActivatePlugin(module): 471 if not self.__canActivatePlugin(module):
472 raise PluginActivationError(module.eric5PluginModuleName) 472 raise PluginActivationError(module.eric6PluginModuleName)
473 version = getattr(module, "version") 473 version = getattr(module, "version")
474 className = getattr(module, "className") 474 className = getattr(module, "className")
475 pluginClass = getattr(module, className) 475 pluginClass = getattr(module, className)
476 pluginObject = None 476 pluginObject = None
477 if name not in self.__onDemandInactivePlugins: 477 if name not in self.__onDemandInactivePlugins:
478 pluginObject = pluginClass(self.__ui) 478 pluginObject = pluginClass(self.__ui)
479 pluginObject.eric5PluginModule = module 479 pluginObject.eric6PluginModule = module
480 pluginObject.eric5PluginName = className 480 pluginObject.eric6PluginName = className
481 pluginObject.eric5PluginVersion = version 481 pluginObject.eric6PluginVersion = version
482 self.__onDemandInactivePlugins[name] = pluginObject 482 self.__onDemandInactivePlugins[name] = pluginObject
483 except PluginActivationError: 483 except PluginActivationError:
484 return 484 return
485 485
486 def activatePlugins(self): 486 def activatePlugins(self):
519 module = self.__inactiveModules[name] 519 module = self.__inactiveModules[name]
520 except KeyError: 520 except KeyError:
521 return None 521 return None
522 522
523 if not self.__canActivatePlugin(module): 523 if not self.__canActivatePlugin(module):
524 raise PluginActivationError(module.eric5PluginModuleName) 524 raise PluginActivationError(module.eric6PluginModuleName)
525 version = getattr(module, "version") 525 version = getattr(module, "version")
526 className = getattr(module, "className") 526 className = getattr(module, "className")
527 pluginClass = getattr(module, className) 527 pluginClass = getattr(module, className)
528 pluginObject = None 528 pluginObject = None
529 if onDemand and name in self.__onDemandInactivePlugins: 529 if onDemand and name in self.__onDemandInactivePlugins:
546 ok = False 546 ok = False
547 if not ok: 547 if not ok:
548 return None 548 return None
549 549
550 self.pluginActivated.emit(name, pluginObject) 550 self.pluginActivated.emit(name, pluginObject)
551 pluginObject.eric5PluginModule = module 551 pluginObject.eric6PluginModule = module
552 pluginObject.eric5PluginName = className 552 pluginObject.eric6PluginName = className
553 pluginObject.eric5PluginVersion = version 553 pluginObject.eric6PluginVersion = version
554 554
555 if onDemand: 555 if onDemand:
556 self.__onDemandInactiveModules.pop(name) 556 self.__onDemandInactiveModules.pop(name)
557 try: 557 try:
558 self.__onDemandInactivePlugins.pop(name) 558 self.__onDemandInactivePlugins.pop(name)
585 plug-in class format 585 plug-in class format
586 """ 586 """
587 try: 587 try:
588 if not hasattr(module, "version"): 588 if not hasattr(module, "version"):
589 raise PluginModuleFormatError( 589 raise PluginModuleFormatError(
590 module.eric5PluginModuleName, "version") 590 module.eric6PluginModuleName, "version")
591 if not hasattr(module, "className"): 591 if not hasattr(module, "className"):
592 raise PluginModuleFormatError( 592 raise PluginModuleFormatError(
593 module.eric5PluginModuleName, "className") 593 module.eric6PluginModuleName, "className")
594 className = getattr(module, "className") 594 className = getattr(module, "className")
595 if not hasattr(module, className): 595 if not hasattr(module, className):
596 raise PluginModuleFormatError( 596 raise PluginModuleFormatError(
597 module.eric5PluginModuleName, className) 597 module.eric6PluginModuleName, className)
598 pluginClass = getattr(module, className) 598 pluginClass = getattr(module, className)
599 if not hasattr(pluginClass, "__init__"): 599 if not hasattr(pluginClass, "__init__"):
600 raise PluginClassFormatError( 600 raise PluginClassFormatError(
601 module.eric5PluginModuleName, 601 module.eric6PluginModuleName,
602 className, "__init__") 602 className, "__init__")
603 if not hasattr(pluginClass, "activate"): 603 if not hasattr(pluginClass, "activate"):
604 raise PluginClassFormatError( 604 raise PluginClassFormatError(
605 module.eric5PluginModuleName, 605 module.eric6PluginModuleName,
606 className, "activate") 606 className, "activate")
607 if not hasattr(pluginClass, "deactivate"): 607 if not hasattr(pluginClass, "deactivate"):
608 raise PluginClassFormatError( 608 raise PluginClassFormatError(
609 module.eric5PluginModuleName, 609 module.eric6PluginModuleName,
610 className, "deactivate") 610 className, "deactivate")
611 return True 611 return True
612 except PluginModuleFormatError as e: 612 except PluginModuleFormatError as e:
613 print(repr(e)) 613 print(repr(e))
614 return False 614 return False
775 # should not happen 775 # should not happen
776 return None 776 return None
777 777
778 details["moduleName"] = name 778 details["moduleName"] = name
779 details["moduleFileName"] = getattr( 779 details["moduleFileName"] = getattr(
780 module, "eric5PluginModuleFilename", "") 780 module, "eric6PluginModuleFilename", "")
781 details["pluginName"] = getattr(module, "name", "") 781 details["pluginName"] = getattr(module, "name", "")
782 details["version"] = getattr(module, "version", "") 782 details["version"] = getattr(module, "version", "")
783 details["author"] = getattr(module, "author", "") 783 details["author"] = getattr(module, "author", "")
784 details["description"] = getattr(module, "longDescription", "") 784 details["description"] = getattr(module, "longDescription", "")
785 details["autoactivate"] = autoactivate 785 details["autoactivate"] = autoactivate

eric ide

mercurial