src/eric7/PluginManager/PluginManager.py

branch
eric7
changeset 10314
1f7d52f024b1
parent 10213
0d0683edaf24
child 10372
1444b4bee64b
equal deleted inserted replaced
10313:8f69edb4ad73 10314:1f7d52f024b1
184 184
185 def getPluginDir(self, key): 185 def getPluginDir(self, key):
186 """ 186 """
187 Public method to get the path of a plugin directory. 187 Public method to get the path of a plugin directory.
188 188
189 @param key key of the plug-in directory (string) 189 @param key key of the plug-in directory
190 @return path of the requested plugin directory (string) 190 @type str
191 @return path of the requested plugin directory
192 @rtype str
191 """ 193 """
192 if key not in ["global", "user"]: 194 if key not in ["global", "user"]:
193 return None 195 return None
194 else: 196 else:
195 try: 197 try:
202 Private method to check, if the plugin folders exist. 204 Private method to check, if the plugin folders exist.
203 205
204 If the plugin folders don't exist, they are created (if possible). 206 If the plugin folders don't exist, they are created (if possible).
205 207
206 @return tuple of a flag indicating existence of any of the plugin 208 @return tuple of a flag indicating existence of any of the plugin
207 directories (boolean) and a message (string) 209 directories and a message
210 @rtype tuple of (bool, str)
208 """ 211 """
209 if self.__develPluginFile: 212 if self.__develPluginFile:
210 path = FileSystemUtilities.splitPath(self.__develPluginFile)[0] 213 path = FileSystemUtilities.splitPath(self.__develPluginFile)[0]
211 fname = os.path.join(path, "__init__.py") 214 fname = os.path.join(path, "__init__.py")
212 if not os.path.exists(fname): 215 if not os.path.exists(fname):
257 260
258 def __pluginModulesExist(self): 261 def __pluginModulesExist(self):
259 """ 262 """
260 Private method to check, if there are plugins available. 263 Private method to check, if there are plugins available.
261 264
262 @return flag indicating the availability of plugins (boolean) 265 @return flag indicating the availability of plugins
266 @rtype bool
263 """ 267 """
264 if self.__develPluginFile and not os.path.exists(self.__develPluginFile): 268 if self.__develPluginFile and not os.path.exists(self.__develPluginFile):
265 return False 269 return False
266 270
267 self.__foundCoreModules = self.getPluginModules(self.pluginDirs["eric7"]) 271 self.__foundCoreModules = self.getPluginModules(self.pluginDirs["eric7"])
284 288
285 def getPluginModules(self, pluginPath): 289 def getPluginModules(self, pluginPath):
286 """ 290 """
287 Public method to get a list of plugin modules. 291 Public method to get a list of plugin modules.
288 292
289 @param pluginPath name of the path to search (string) 293 @param pluginPath name of the path to search
290 @return list of plugin module names (list of string) 294 @type str
295 @return list of plugin module names
296 @rtype list of str
291 """ 297 """
292 pluginFiles = [ 298 pluginFiles = [
293 f[:-3] for f in os.listdir(pluginPath) if self.isValidPluginName(f) 299 f[:-3] for f in os.listdir(pluginPath) if self.isValidPluginName(f)
294 ] 300 ]
295 return pluginFiles[:] 301 return pluginFiles[:]
298 """ 304 """
299 Public method to check, if a file name is a valid plugin name. 305 Public method to check, if a file name is a valid plugin name.
300 306
301 Plugin modules must start with "Plugin" and have the extension ".py". 307 Plugin modules must start with "Plugin" and have the extension ".py".
302 308
303 @param pluginName name of the file to be checked (string) 309 @param pluginName name of the file to be checked
304 @return flag indicating a valid plugin name (boolean) 310 @type str
311 @return flag indicating a valid plugin name
312 @rtype bool
305 """ 313 """
306 return pluginName.startswith("Plugin") and pluginName.endswith(".py") 314 return pluginName.startswith("Plugin") and pluginName.endswith(".py")
307 315
308 def __insertPluginsPaths(self): 316 def __insertPluginsPaths(self):
309 """ 317 """
310 Private method to insert the valid plugin paths intos the search path. 318 Private method to insert the valid plugin paths into the search path.
311 """ 319 """
312 for key in self.__priorityOrder: 320 for key in self.__priorityOrder:
313 if key in self.pluginDirs: 321 if key in self.pluginDirs:
314 if self.pluginDirs[key] not in sys.path: 322 if self.pluginDirs[key] not in sys.path:
315 sys.path.insert(2, self.pluginDirs[key]) 323 sys.path.insert(2, self.pluginDirs[key])
466 474
467 def unloadPlugin(self, name): 475 def unloadPlugin(self, name):
468 """ 476 """
469 Public method to unload a plugin module. 477 Public method to unload a plugin module.
470 478
471 @param name name of the module to be unloaded (string) 479 @param name name of the module to be unloaded
472 @return flag indicating success (boolean) 480 @type str
481 @return flag indicating success
482 @rtype bool
473 """ 483 """
474 if name in self.__onDemandActiveModules: 484 if name in self.__onDemandActiveModules:
475 # cannot unload an ondemand plugin, that is in use 485 # cannot unload an ondemand plugin, that is in use
476 return False 486 return False
477 487
501 def removePluginFromSysModules(self, pluginName, package, internalPackages): 511 def removePluginFromSysModules(self, pluginName, package, internalPackages):
502 """ 512 """
503 Public method to remove a plugin and all related modules from 513 Public method to remove a plugin and all related modules from
504 sys.modules. 514 sys.modules.
505 515
506 @param pluginName name of the plugin module (string) 516 @param pluginName name of the plugin module
507 @param package name of the plugin package (string) 517 @type str
508 @param internalPackages list of intenal packages (list of string) 518 @param package name of the plugin package
519 @type str
520 @param internalPackages list of intenal packages
521 @type list of str
509 @return flag indicating the plugin module was found in sys.modules 522 @return flag indicating the plugin module was found in sys.modules
510 (boolean) 523 @rtype bool
511 """ 524 """
512 packages = [package] + internalPackages 525 packages = [package] + internalPackages
513 found = False 526 found = False
514 if not package: 527 if not package:
515 package = "__None__" 528 package = "__None__"
533 """ 546 """
534 Public method to create a plugin object for the named on demand plugin. 547 Public method to create a plugin object for the named on demand plugin.
535 548
536 Note: The plug-in is not activated. 549 Note: The plug-in is not activated.
537 550
538 @param name name of the plug-in (string) 551 @param name name of the plug-in
552 @type str
539 @exception PluginActivationError raised to indicate an issue during the 553 @exception PluginActivationError raised to indicate an issue during the
540 plug-in activation 554 plug-in activation
541 """ 555 """
542 try: 556 try:
543 try: 557 try:
563 def initPluginToolbars(self, toolbarManager): 577 def initPluginToolbars(self, toolbarManager):
564 """ 578 """
565 Public method to initialize plug-in toolbars. 579 Public method to initialize plug-in toolbars.
566 580
567 @param toolbarManager reference to the toolbar manager object 581 @param toolbarManager reference to the toolbar manager object
568 (EricToolBarManager) 582 @type EricToolBarManager
569 """ 583 """
570 self.initOnDemandPlugins() 584 self.initOnDemandPlugins()
571 for pluginObject in self.__onDemandInactivePlugins.values(): 585 for pluginObject in self.__onDemandInactivePlugins.values():
572 with contextlib.suppress(AttributeError): 586 with contextlib.suppress(AttributeError):
573 pluginObject.initToolbar(self.__ui, toolbarManager) 587 pluginObject.initToolbar(self.__ui, toolbarManager)
668 def __canActivatePlugin(self, module): 682 def __canActivatePlugin(self, module):
669 """ 683 """
670 Private method to check, if a plugin can be activated. 684 Private method to check, if a plugin can be activated.
671 685
672 @param module reference to the module to be activated 686 @param module reference to the module to be activated
687 @type Module
673 @return flag indicating, if the module satisfies all requirements 688 @return flag indicating, if the module satisfies all requirements
674 for being activated (boolean) 689 for being activated
690 @rtype bool
675 @exception PluginModuleFormatError raised to indicate an invalid 691 @exception PluginModuleFormatError raised to indicate an invalid
676 plug-in module format 692 plug-in module format
677 @exception PluginClassFormatError raised to indicate an invalid 693 @exception PluginClassFormatError raised to indicate an invalid
678 plug-in class format 694 plug-in class format
679 """ 695 """
709 def deactivatePlugin(self, name, onDemand=False): 725 def deactivatePlugin(self, name, onDemand=False):
710 """ 726 """
711 Public method to deactivate a plugin. 727 Public method to deactivate a plugin.
712 728
713 @param name name of the module to be deactivated 729 @param name name of the module to be deactivated
730 @type str
714 @param onDemand flag indicating deactivation of an 731 @param onDemand flag indicating deactivation of an
715 on demand plugin (boolean) 732 on demand plugin
733 @type bool
716 """ 734 """
717 try: 735 try:
718 module = ( 736 module = (
719 self.__onDemandActiveModules[name] 737 self.__onDemandActiveModules[name]
720 if onDemand 738 if onDemand
749 def __canDeactivatePlugin(self, module): 767 def __canDeactivatePlugin(self, module):
750 """ 768 """
751 Private method to check, if a plugin can be deactivated. 769 Private method to check, if a plugin can be deactivated.
752 770
753 @param module reference to the module to be deactivated 771 @param module reference to the module to be deactivated
772 @type Module
754 @return flag indicating, if the module satisfies all requirements 773 @return flag indicating, if the module satisfies all requirements
755 for being deactivated (boolean) 774 for being deactivated
775 @rtype bool
756 """ 776 """
757 return getPluginHeaderEntry(module, "deactivateable", True) 777 return getPluginHeaderEntry(module, "deactivateable", True)
758 778
759 def getPluginObject(self, type_, typename, maybeActive=False): 779 def getPluginObject(self, type_, typename, maybeActive=False):
760 """ 780 """
761 Public method to activate an ondemand plugin given by type and 781 Public method to activate an on-demand plugin given by type and
762 typename. 782 type name.
763 783
764 @param type_ type of the plugin to be activated 784 @param type_ type of the plugin to be activated
765 @type str 785 @type str
766 @param typename name of the plugin within the type category 786 @param typename name of the plugin within the type category
767 @type str 787 @type str
866 def __getShortInfo(self, module): 886 def __getShortInfo(self, module):
867 """ 887 """
868 Private method to extract the short info from a module. 888 Private method to extract the short info from a module.
869 889
870 @param module module to extract short info from 890 @param module module to extract short info from
871 @return dictionay containing plug-in data 891 @type Module
892 @return dictionary containing plug-in data
872 @rtype dict ("plugin_name": str, "version": str, "short_desc": str, 893 @rtype dict ("plugin_name": str, "version": str, "short_desc": str,
873 "error": bool) 894 "error": bool)
874 """ 895 """
875 return { 896 return {
876 "plugin_name": getPluginHeaderEntry(module, "name", ""), 897 "plugin_name": getPluginHeaderEntry(module, "name", ""),
881 902
882 def getPluginDetails(self, name): 903 def getPluginDetails(self, name):
883 """ 904 """
884 Public method to get detailed information about a plugin. 905 Public method to get detailed information about a plugin.
885 906
886 @param name name of the module to get detailed infos about (string) 907 @param name name of the module to get detailed infos about
908 @type str
887 @return details of the plugin as a dictionary 909 @return details of the plugin as a dictionary
910 @rtype dict
888 """ 911 """
889 details = {} 912 details = {}
890 913
891 autoactivate = True 914 autoactivate = True
892 active = True 915 active = True
942 def getPluginDisplayStrings(self, type_): 965 def getPluginDisplayStrings(self, type_):
943 """ 966 """
944 Public method to get the display strings of all plugins of a specific 967 Public method to get the display strings of all plugins of a specific
945 type. 968 type.
946 969
947 @param type_ type of the plugins (string) 970 @param type_ type of the plugins
971 @type str
948 @return dictionary with name as key and display string as value 972 @return dictionary with name as key and display string as value
949 (dictionary of string) 973 @rtype dict
950 """ 974 """
951 pluginDict = {} 975 pluginDict = {}
952 976
953 for module in list(self.__onDemandActiveModules.values()) + list( 977 for module in list(self.__onDemandActiveModules.values()) + list(
954 self.__onDemandInactiveModules.values() 978 self.__onDemandInactiveModules.values()
967 991
968 def getPluginPreviewPixmap(self, type_, name): 992 def getPluginPreviewPixmap(self, type_, name):
969 """ 993 """
970 Public method to get a preview pixmap of a plugin of a specific type. 994 Public method to get a preview pixmap of a plugin of a specific type.
971 995
972 @param type_ type of the plugin (string) 996 @param type_ type of the plugin
973 @param name name of the plugin type (string) 997 @type str
974 @return preview pixmap (QPixmap) 998 @param name name of the plugin type
999 @type str
1000 @return preview pixmap
1001 @rtype QPixmap
975 """ 1002 """
976 for module in list(self.__onDemandActiveModules.values()) + list( 1003 for module in list(self.__onDemandActiveModules.values()) + list(
977 self.__onDemandInactiveModules.values() 1004 self.__onDemandInactiveModules.values()
978 ): 1005 ):
979 if ( 1006 if (
989 1016
990 def getPluginApiFiles(self, language): 1017 def getPluginApiFiles(self, language):
991 """ 1018 """
992 Public method to get the list of API files installed by a plugin. 1019 Public method to get the list of API files installed by a plugin.
993 1020
994 @param language language of the requested API files (string) 1021 @param language language of the requested API files
995 @return list of API filenames (list of string) 1022 @type str
1023 @return list of API filenames
1024 @rtype list of str
996 """ 1025 """
997 apis = [] 1026 apis = []
998 1027
999 for module in list(self.__activeModules.values()) + list( 1028 for module in list(self.__activeModules.values()) + list(
1000 self.__onDemandActiveModules.values() 1029 self.__onDemandActiveModules.values()
1053 (boolean), always False</li> 1082 (boolean), always False</li>
1054 <li>header - string to be diplayed as a header (string)</li> 1083 <li>header - string to be diplayed as a header (string)</li>
1055 <li>text - entry text to be shown (string)</li> 1084 <li>text - entry text to be shown (string)</li>
1056 <li>version - version text to be shown (string)</li> 1085 <li>version - version text to be shown (string)</li>
1057 </ul> 1086 </ul>
1087 @rtype list of dict
1058 """ 1088 """
1059 infos = [] 1089 infos = []
1060 1090
1061 for module in list(self.__activeModules.values()) + list( 1091 for module in list(self.__activeModules.values()) + list(
1062 self.__inactiveModules.values() 1092 self.__inactiveModules.values()
1104 <dd>This will be used by the configuration dialog and must always 1134 <dd>This will be used by the configuration dialog and must always
1105 be None</dd> 1135 be None</dd>
1106 </dl> 1136 </dl>
1107 1137
1108 @return plug-in configuration data 1138 @return plug-in configuration data
1139 @rtype dict
1109 """ 1140 """
1110 configData = {} 1141 configData = {}
1111 for module in ( 1142 for module in (
1112 list(self.__activeModules.values()) 1143 list(self.__activeModules.values())
1113 + list(self.__onDemandActiveModules.values()) 1144 + list(self.__onDemandActiveModules.values())
1119 1150
1120 def isPluginLoaded(self, pluginName): 1151 def isPluginLoaded(self, pluginName):
1121 """ 1152 """
1122 Public method to check, if a certain plugin is loaded. 1153 Public method to check, if a certain plugin is loaded.
1123 1154
1124 @param pluginName name of the plugin to check for (string) 1155 @param pluginName name of the plugin to check for
1125 @return flag indicating, if the plugin is loaded (boolean) 1156 @type str
1157 @return flag indicating, if the plugin is loaded
1158 @rtype bool
1126 """ 1159 """
1127 return ( 1160 return (
1128 pluginName in self.__activeModules 1161 pluginName in self.__activeModules
1129 or pluginName in self.__inactiveModules 1162 or pluginName in self.__inactiveModules
1130 or pluginName in self.__onDemandActiveModules 1163 or pluginName in self.__onDemandActiveModules
1133 1166
1134 def isPluginActive(self, pluginName): 1167 def isPluginActive(self, pluginName):
1135 """ 1168 """
1136 Public method to check, if a certain plugin is active. 1169 Public method to check, if a certain plugin is active.
1137 1170
1138 @param pluginName name of the plugin to check for (string) 1171 @param pluginName name of the plugin to check for
1139 @return flag indicating, if the plugin is active (boolean) 1172 @type str
1173 @return flag indicating, if the plugin is active
1174 @rtype bool
1140 """ 1175 """
1141 return ( 1176 return (
1142 pluginName in self.__activeModules 1177 pluginName in self.__activeModules
1143 or pluginName in self.__onDemandActiveModules 1178 or pluginName in self.__onDemandActiveModules
1144 ) 1179 )
1158 Plugins supporting this functionality must support the module function 1193 Plugins supporting this functionality must support the module function
1159 getVcsSystemIndicator returning a dictionary with indicator as key and 1194 getVcsSystemIndicator returning a dictionary with indicator as key and
1160 a tuple with the vcs name (string) and vcs display string (string). 1195 a tuple with the vcs name (string) and vcs display string (string).
1161 1196
1162 @return dictionary with indicator as key and a list of tuples as 1197 @return dictionary with indicator as key and a list of tuples as
1163 values. Each tuple contains the vcs name (string) and vcs display 1198 values. Each tuple contains the vcs name (str) and vcs display
1164 string (string). 1199 string (str).
1200 @rtype dict
1165 """ 1201 """
1166 vcsDict = {} 1202 vcsDict = {}
1167 1203
1168 for module in list(self.__onDemandActiveModules.values()) + list( 1204 for module in list(self.__onDemandActiveModules.values()) + list(
1169 self.__onDemandInactiveModules.values() 1205 self.__onDemandInactiveModules.values()
1349 url, 1385 url,
1350 author, # noqa: U100 1386 author, # noqa: U100
1351 version, 1387 version,
1352 filename, 1388 filename,
1353 status, # noqa: U100 1389 status, # noqa: U100
1390 category, # noqa: U100
1354 ): 1391 ):
1355 """ 1392 """
1356 Public method to check a plug-in's data for an update. 1393 Public method to check a plug-in's data for an update.
1357 1394
1358 @param name data for the name field (string) 1395 @param name data for the name field
1359 @param short data for the short field (string) 1396 @type str
1360 @param description data for the description field (list of strings) 1397 @param short data for the short field
1361 @param url data for the url field (string) 1398 @type str
1362 @param author data for the author field (string) 1399 @param description data for the description field
1363 @param version data for the version field (string) 1400 @type list of str
1364 @param filename data for the filename field (string) 1401 @param url data for the url field
1365 @param status status of the plugin (string [stable, unstable, unknown]) 1402 @type str
1403 @param author data for the author field
1404 @type str
1405 @param version data for the version field
1406 @type str
1407 @param filename data for the filename field
1408 @type str
1409 @param status status of the plugin (one of stable, unstable, unknown)
1410 @type str
1411 @param category category designation of the plugin
1412 @type str
1366 """ 1413 """
1367 # ignore hidden plug-ins 1414 # ignore hidden plug-ins
1368 pluginName = os.path.splitext(url.rsplit("/", 1)[1])[0] 1415 pluginName = os.path.splitext(url.rsplit("/", 1)[1])[0]
1369 if pluginName in Preferences.getPluginManager("HiddenPlugins"): 1416 if pluginName in Preferences.getPluginManager("HiddenPlugins"):
1370 return 1417 return
1412 1459
1413 def __sslErrors(self, reply, errors): 1460 def __sslErrors(self, reply, errors):
1414 """ 1461 """
1415 Private slot to handle SSL errors. 1462 Private slot to handle SSL errors.
1416 1463
1417 @param reply reference to the reply object (QNetworkReply) 1464 @param reply reference to the reply object
1418 @param errors list of SSL errors (list of QSslError) 1465 @type QNetworkReply
1466 @param errors list of SSL errors
1467 @type list of QSslError
1419 """ 1468 """
1420 ignored = self.__sslErrorHandler.sslErrorsReply(reply, errors)[0] 1469 ignored = self.__sslErrorHandler.sslErrorsReply(reply, errors)[0]
1421 if ignored == EricSslErrorState.NOT_IGNORED: 1470 if ignored == EricSslErrorState.NOT_IGNORED:
1422 self.__downloadCancelled = True 1471 self.__downloadCancelled = True
1423 1472
1431 type. 1480 type.
1432 1481
1433 Plugins supporting this functionality must support the module function 1482 Plugins supporting this functionality must support the module function
1434 clearPrivateData() and have the module level attribute pluginType. 1483 clearPrivateData() and have the module level attribute pluginType.
1435 1484
1436 @param type_ type of the plugin to clear private data for (string) 1485 @param type_ type of the plugin to clear private data for
1486 @type str
1437 """ 1487 """
1438 for module in ( 1488 for module in (
1439 list(self.__onDemandActiveModules.values()) 1489 list(self.__onDemandActiveModules.values())
1440 + list(self.__onDemandInactiveModules.values()) 1490 + list(self.__onDemandInactiveModules.values())
1441 + list(self.__activeModules.values()) 1491 + list(self.__activeModules.values())

eric ide

mercurial