416 fname = "{0}.py".format(os.path.join(directory, name)) |
417 fname = "{0}.py".format(os.path.join(directory, name)) |
417 spec = importlib.util.spec_from_file_location(name, fname) |
418 spec = importlib.util.spec_from_file_location(name, fname) |
418 module = importlib.util.module_from_spec(spec) |
419 module = importlib.util.module_from_spec(spec) |
419 sys.modules[module.__name__] = module |
420 sys.modules[module.__name__] = module |
420 spec.loader.exec_module(module) |
421 spec.loader.exec_module(module) |
421 if not hasattr(module, "autoactivate"): |
422 if not hasPluginHeaderEntry(module, "autoactivate"): |
422 module.error = self.tr( |
423 module.error = self.tr( |
423 "Module is missing the 'autoactivate' attribute." |
424 "Module is missing the 'autoactivate' attribute." |
424 ) |
425 ) |
425 self.__failedModules[name] = module |
426 self.__failedModules[name] = module |
426 raise PluginLoadError(name) |
427 raise PluginLoadError(name) |
427 if getattr(module, "autoactivate", False): |
428 if getPluginHeaderEntry(module, "autoactivate", False): |
428 self.__inactiveModules[name] = module |
429 self.__inactiveModules[name] = module |
429 else: |
430 else: |
430 if not hasattr(module, "pluginType") or not hasattr( |
431 if not hasPluginHeaderEntry( |
431 module, "pluginTypename" |
432 module, "pluginType" |
432 ): |
433 ) or not hasPluginHeaderEntry(module, "pluginTypename"): |
433 module.error = self.tr( |
434 module.error = self.tr( |
434 "Module is missing the 'pluginType' " |
435 "Module is missing the 'pluginType' " |
435 "and/or 'pluginTypename' attributes." |
436 "and/or 'pluginTypename' attributes." |
436 ) |
437 ) |
437 self.__failedModules[name] = module |
438 self.__failedModules[name] = module |
544 except KeyError: |
545 except KeyError: |
545 return |
546 return |
546 |
547 |
547 if not self.__canActivatePlugin(module): |
548 if not self.__canActivatePlugin(module): |
548 raise PluginActivationError(module.eric7PluginModuleName) |
549 raise PluginActivationError(module.eric7PluginModuleName) |
549 version = getattr(module, "version", "0.0.0") |
550 version = getPluginHeaderEntry(module, "version", "0.0.0") |
550 className = getattr(module, "className", "") |
551 className = getPluginHeaderEntry(module, "className", "") |
551 pluginClass = getattr(module, className) |
552 pluginClass = getattr(module, className) |
552 pluginObject = None |
553 pluginObject = None |
553 if name not in self.__onDemandInactivePlugins: |
554 if name not in self.__onDemandInactivePlugins: |
554 pluginObject = pluginClass(self.__ui) |
555 pluginObject = pluginClass(self.__ui) |
555 pluginObject.eric7PluginModule = module |
556 pluginObject.eric7PluginModule = module |
617 except KeyError: |
618 except KeyError: |
618 return None, f"no such plugin module: {name}" |
619 return None, f"no such plugin module: {name}" |
619 |
620 |
620 if not self.__canActivatePlugin(module): |
621 if not self.__canActivatePlugin(module): |
621 raise PluginActivationError(module.eric7PluginModuleName) |
622 raise PluginActivationError(module.eric7PluginModuleName) |
622 version = getattr(module, "version", "0.0.0") |
623 version = getPluginHeaderEntry(module, "version", "0.0.0") |
623 className = getattr(module, "className", "") |
624 className = getPluginHeaderEntry(module, "className", "") |
624 pluginClass = getattr(module, className) |
625 pluginClass = getattr(module, className) |
625 pluginObject = None |
626 pluginObject = None |
626 if onDemand and name in self.__onDemandInactivePlugins: |
627 if onDemand and name in self.__onDemandInactivePlugins: |
627 pluginObject = self.__onDemandInactivePlugins[name] |
628 pluginObject = self.__onDemandInactivePlugins[name] |
628 elif not onDemand and name in self.__inactivePlugins: |
629 elif not onDemand and name in self.__inactivePlugins: |
675 plug-in module format |
676 plug-in module format |
676 @exception PluginClassFormatError raised to indicate an invalid |
677 @exception PluginClassFormatError raised to indicate an invalid |
677 plug-in class format |
678 plug-in class format |
678 """ |
679 """ |
679 try: |
680 try: |
680 if not hasattr(module, "version"): |
681 if not hasPluginHeaderEntry(module, "version"): |
681 raise PluginModuleFormatError(module.eric7PluginModuleName, "version") |
682 raise PluginModuleFormatError(module.eric7PluginModuleName, "version") |
682 if not hasattr(module, "className"): |
683 if not hasPluginHeaderEntry(module, "className"): |
683 raise PluginModuleFormatError(module.eric7PluginModuleName, "className") |
684 raise PluginModuleFormatError(module.eric7PluginModuleName, "className") |
684 className = getattr(module, "className", "") |
685 className = getPluginHeaderEntry(module, "className", "") |
685 if not className or not hasattr(module, className): |
686 if not className or not hasattr(module, className): |
686 raise PluginModuleFormatError(module.eric7PluginModuleName, className) |
687 raise PluginModuleFormatError(module.eric7PluginModuleName, className) |
687 pluginClass = getattr(module, className) |
688 pluginClass = getattr(module, className) |
688 if not hasattr(pluginClass, "__init__"): |
689 if not hasattr(pluginClass, "__init__"): |
689 raise PluginClassFormatError( |
690 raise PluginClassFormatError( |
751 |
752 |
752 @param module reference to the module to be deactivated |
753 @param module reference to the module to be deactivated |
753 @return flag indicating, if the module satisfies all requirements |
754 @return flag indicating, if the module satisfies all requirements |
754 for being deactivated (boolean) |
755 for being deactivated (boolean) |
755 """ |
756 """ |
756 return getattr(module, "deactivateable", True) |
757 return getPluginHeaderEntry(module, "deactivateable", True) |
757 |
758 |
758 def getPluginObject(self, type_, typename, maybeActive=False): |
759 def getPluginObject(self, type_, typename, maybeActive=False): |
759 """ |
760 """ |
760 Public method to activate an ondemand plugin given by type and |
761 Public method to activate an ondemand plugin given by type and |
761 typename. |
762 typename. |
770 @return reference to the initialized plugin object and an error string |
771 @return reference to the initialized plugin object and an error string |
771 @rtype tuple of (QObject, str) |
772 @rtype tuple of (QObject, str) |
772 """ |
773 """ |
773 for name, module in list(self.__onDemandInactiveModules.items()): |
774 for name, module in list(self.__onDemandInactiveModules.items()): |
774 if ( |
775 if ( |
775 getattr(module, "pluginType", "") == type_ |
776 getPluginHeaderEntry(module, "pluginType", "") == type_ |
776 and getattr(module, "pluginTypename", "") == typename |
777 and getPluginHeaderEntry(module, "pluginTypename", "") == typename |
777 ): |
778 ): |
778 return self.activatePlugin(name, onDemand=True) |
779 return self.activatePlugin(name, onDemand=True) |
779 |
780 |
780 if maybeActive: |
781 if maybeActive: |
781 for name, module in list(self.__onDemandActiveModules.items()): |
782 for name, module in list(self.__onDemandActiveModules.items()): |
782 if ( |
783 if ( |
783 getattr(module, "pluginType", "") == type_ |
784 getPluginHeaderEntry(module, "pluginType", "") == type_ |
784 and getattr(module, "pluginTypename", "") == typename |
785 and getPluginHeaderEntry(module, "pluginTypename", "") == typename |
785 ): |
786 ): |
786 self.deactivatePlugin(name, onDemand=True) |
787 self.deactivatePlugin(name, onDemand=True) |
787 return self.activatePlugin(name, onDemand=True) |
788 return self.activatePlugin(name, onDemand=True) |
788 |
789 |
789 return None, f"no plugin module of type {type_}: {typename}" |
790 return None, f"no plugin module of type {type_}: {typename}" |
870 @return dictionay containing plug-in data |
871 @return dictionay containing plug-in data |
871 @rtype dict ("plugin_name": str, "version": str, "short_desc": str, |
872 @rtype dict ("plugin_name": str, "version": str, "short_desc": str, |
872 "error": bool) |
873 "error": bool) |
873 """ |
874 """ |
874 return { |
875 return { |
875 "plugin_name": getattr(module, "name", ""), |
876 "plugin_name": getPluginHeaderEntry(module, "name", ""), |
876 "version": getattr(module, "version", ""), |
877 "version": getPluginHeaderEntry(module, "version", ""), |
877 "short_desc": getattr(module, "shortDescription", ""), |
878 "short_desc": getPluginHeaderEntry(module, "shortDescription", ""), |
878 "error": bool(getattr(module, "error", "")), |
879 "error": bool(getPluginHeaderEntry(module, "error", "")), |
879 } |
880 } |
880 |
881 |
881 def getPluginDetails(self, name): |
882 def getPluginDetails(self, name): |
882 """ |
883 """ |
883 Public method to get detailed information about a plugin. |
884 Public method to get detailed information about a plugin. |
912 else: |
913 else: |
913 # should not happen |
914 # should not happen |
914 return None |
915 return None |
915 |
916 |
916 details["moduleName"] = name |
917 details["moduleName"] = name |
917 details["moduleFileName"] = getattr(module, "eric7PluginModuleFilename", "") |
918 details["moduleFileName"] = getPluginHeaderEntry( |
918 details["pluginName"] = getattr(module, "name", "") |
919 module, "eric7PluginModuleFilename", "" |
919 details["version"] = getattr(module, "version", "") |
920 ) |
920 details["author"] = getattr(module, "author", "") |
921 details["pluginName"] = getPluginHeaderEntry(module, "name", "") |
921 details["description"] = getattr(module, "longDescription", "") |
922 details["version"] = getPluginHeaderEntry(module, "version", "") |
|
923 details["author"] = getPluginHeaderEntry(module, "author", "") |
|
924 details["description"] = getPluginHeaderEntry(module, "longDescription", "") |
922 details["autoactivate"] = autoactivate |
925 details["autoactivate"] = autoactivate |
923 details["active"] = active |
926 details["active"] = active |
924 details["error"] = getattr(module, "error", "") |
927 details["error"] = getPluginHeaderEntry(module, "error", "") |
925 |
928 |
926 return details |
929 return details |
927 |
930 |
928 def doShutdown(self): |
931 def doShutdown(self): |
929 """ |
932 """ |
949 |
952 |
950 for module in list(self.__onDemandActiveModules.values()) + list( |
953 for module in list(self.__onDemandActiveModules.values()) + list( |
951 self.__onDemandInactiveModules.values() |
954 self.__onDemandInactiveModules.values() |
952 ): |
955 ): |
953 if ( |
956 if ( |
954 getattr(module, "pluginType", "") == type_ |
957 getPluginHeaderEntry(module, "pluginType", "") == type_ |
955 and getattr(module, "error", "") == "" |
958 and getPluginHeaderEntry(module, "error", "") == "" |
956 ): |
959 ): |
957 plugin_name = getattr(module, "pluginTypename", "") |
960 plugin_name = getPluginHeaderEntry(module, "pluginTypename", "") |
958 if plugin_name: |
961 if plugin_name: |
959 if hasattr(module, "displayString"): |
962 if hasattr(module, "displayString"): |
960 try: |
963 try: |
961 disp = module.displayString() |
964 disp = module.displayString() |
962 except TypeError: |
965 except TypeError: |
963 disp = getattr(module, "displayString", "") |
966 disp = getPluginHeaderEntry(module, "displayString", "") |
964 if disp != "": |
967 if disp != "": |
965 pluginDict[plugin_name] = disp |
968 pluginDict[plugin_name] = disp |
966 else: |
969 else: |
967 pluginDict[plugin_name] = plugin_name |
970 pluginDict[plugin_name] = plugin_name |
968 |
971 |
978 """ |
981 """ |
979 for module in list(self.__onDemandActiveModules.values()) + list( |
982 for module in list(self.__onDemandActiveModules.values()) + list( |
980 self.__onDemandInactiveModules.values() |
983 self.__onDemandInactiveModules.values() |
981 ): |
984 ): |
982 if ( |
985 if ( |
983 getattr(module, "pluginType", "") == type_ |
986 getPluginHeaderEntry(module, "pluginType", "") == type_ |
984 and getattr(module, "pluginTypename", "") == name |
987 and getPluginHeaderEntry(module, "pluginTypename", "") == name |
985 ): |
988 ): |
986 if hasattr(module, "previewPix"): |
989 if hasattr(module, "previewPix"): |
987 return module.previewPix() |
990 return module.previewPix() |
988 else: |
991 else: |
989 return QPixmap() |
992 return QPixmap() |
1169 vcsDict = {} |
1172 vcsDict = {} |
1170 |
1173 |
1171 for module in list(self.__onDemandActiveModules.values()) + list( |
1174 for module in list(self.__onDemandActiveModules.values()) + list( |
1172 self.__onDemandInactiveModules.values() |
1175 self.__onDemandInactiveModules.values() |
1173 ): |
1176 ): |
1174 if getattr(module, "pluginType", "") == "version_control" and hasattr( |
1177 if getPluginHeaderEntry( |
1175 module, "getVcsSystemIndicator" |
1178 module, "pluginType", "" |
1176 ): |
1179 ) == "version_control" and hasattr(module, "getVcsSystemIndicator"): |
1177 res = module.getVcsSystemIndicator() |
1180 res = module.getVcsSystemIndicator() |
1178 for indicator, vcsData in list(res.items()): |
1181 for indicator, vcsData in list(res.items()): |
1179 if indicator in vcsDict: |
1182 if indicator in vcsDict: |
1180 vcsDict[indicator].append(vcsData) |
1183 vcsDict[indicator].append(vcsData) |
1181 else: |
1184 else: |
1186 def deactivateVcsPlugins(self): |
1189 def deactivateVcsPlugins(self): |
1187 """ |
1190 """ |
1188 Public method to deactivated all activated VCS plugins. |
1191 Public method to deactivated all activated VCS plugins. |
1189 """ |
1192 """ |
1190 for name, module in list(self.__onDemandActiveModules.items()): |
1193 for name, module in list(self.__onDemandActiveModules.items()): |
1191 if getattr(module, "pluginType", "") == "version_control": |
1194 if getPluginHeaderEntry(module, "pluginType", "") == "version_control": |
1192 self.deactivatePlugin(name, True) |
1195 self.deactivatePlugin(name, True) |
1193 |
1196 |
1194 ######################################################################## |
1197 ######################################################################## |
1195 ## Methods for the creation of the plug-ins download directory |
1198 ## Methods for the creation of the plug-ins download directory |
1196 ######################################################################## |
1199 ######################################################################## |
1433 list(self.__onDemandActiveModules.values()) |
1436 list(self.__onDemandActiveModules.values()) |
1434 + list(self.__onDemandInactiveModules.values()) |
1437 + list(self.__onDemandInactiveModules.values()) |
1435 + list(self.__activeModules.values()) |
1438 + list(self.__activeModules.values()) |
1436 + list(self.__inactiveModules.values()) |
1439 + list(self.__inactiveModules.values()) |
1437 ): |
1440 ): |
1438 if getattr(module, "pluginType", "") == type_ and hasattr( |
1441 if getPluginHeaderEntry(module, "pluginType", "") == type_ and hasattr( |
1439 module, "clearPrivateData" |
1442 module, "clearPrivateData" |
1440 ): |
1443 ): |
1441 module.clearPrivateData() |
1444 module.clearPrivateData() |
1442 |
1445 |
1443 ######################################################################## |
1446 ######################################################################## |