PluginManager/PluginManager.py

branch
Py2 comp.
changeset 3060
5883ce99ee12
parent 3058
0a02c433f52d
parent 3036
30c81c9e88b8
child 3142
55030c09e142
equal deleted inserted replaced
3058:0a02c433f52d 3060:5883ce99ee12
80 self.__inactivePluginsKey = "PluginManager/InactivePlugins" 80 self.__inactivePluginsKey = "PluginManager/InactivePlugins"
81 81
82 self.pluginDirs = { 82 self.pluginDirs = {
83 "eric5": os.path.join(getConfig('ericDir'), "Plugins"), 83 "eric5": os.path.join(getConfig('ericDir'), "Plugins"),
84 "global": os.path.join(Utilities.getPythonModulesDirectory(), 84 "global": os.path.join(Utilities.getPythonModulesDirectory(),
85 "eric5plugins"), 85 "eric5plugins"),
86 "user": os.path.join(Utilities.getConfigDir(), "eric5plugins"), 86 "user": os.path.join(Utilities.getConfigDir(), "eric5plugins"),
87 } 87 }
88 self.__priorityOrder = ["eric5", "global", "user"] 88 self.__priorityOrder = ["eric5", "global", "user"]
89 89
90 self.__defaultDownloadDir = os.path.join( 90 self.__defaultDownloadDir = os.path.join(
123 def finalizeSetup(self): 123 def finalizeSetup(self):
124 """ 124 """
125 Public method to finalize the setup of the plugin manager. 125 Public method to finalize the setup of the plugin manager.
126 """ 126 """
127 for module in list(self.__onDemandInactiveModules.values()) + \ 127 for module in list(self.__onDemandInactiveModules.values()) + \
128 list(self.__onDemandActiveModules.values()): 128 list(self.__onDemandActiveModules.values()):
129 if hasattr(module, "moduleSetup"): 129 if hasattr(module, "moduleSetup"):
130 module.moduleSetup() 130 module.moduleSetup()
131 131
132 def getPluginDir(self, key): 132 def getPluginDir(self, key):
133 """ 133 """
161 f = open(fname, "w") 161 f = open(fname, "w")
162 f.close() 162 f.close()
163 except IOError: 163 except IOError:
164 return ( 164 return (
165 False, 165 False,
166 self.trUtf8("Could not create a package for {0}.")\ 166 self.trUtf8("Could not create a package for {0}.")
167 .format(self.__develPluginFile)) 167 .format(self.__develPluginFile))
168 168
169 if Preferences.getPluginManager("ActivateExternal"): 169 if Preferences.getPluginManager("ActivateExternal"):
170 fname = os.path.join(self.pluginDirs["user"], "__init__.py") 170 fname = os.path.join(self.pluginDirs["user"], "__init__.py")
171 if not os.path.exists(fname): 171 if not os.path.exists(fname):
221 self.getPluginModules(self.pluginDirs["global"]) 221 self.getPluginModules(self.pluginDirs["global"])
222 if "user" in self.pluginDirs: 222 if "user" in self.pluginDirs:
223 self.__foundUserModules = \ 223 self.__foundUserModules = \
224 self.getPluginModules(self.pluginDirs["user"]) 224 self.getPluginModules(self.pluginDirs["user"])
225 225
226 return len(self.__foundCoreModules + self.__foundGlobalModules + \ 226 return len(self.__foundCoreModules + self.__foundGlobalModules +
227 self.__foundUserModules) > 0 227 self.__foundUserModules) > 0
228 228
229 def getPluginModules(self, pluginPath): 229 def getPluginModules(self, pluginPath):
230 """ 230 """
231 Public method to get a list of plugin modules. 231 Public method to get a list of plugin modules.
232 232
233 @param pluginPath name of the path to search (string) 233 @param pluginPath name of the path to search (string)
234 @return list of plugin module names (list of string) 234 @return list of plugin module names (list of string)
235 """ 235 """
236 pluginFiles = [f[:-3] for f in os.listdir(pluginPath) \ 236 pluginFiles = [f[:-3] for f in os.listdir(pluginPath)
237 if self.isValidPluginName(f)] 237 if self.isValidPluginName(f)]
238 return pluginFiles[:] 238 return pluginFiles[:]
239 239
240 def isValidPluginName(self, pluginName): 240 def isValidPluginName(self, pluginName):
241 """ 241 """
769 """ 769 """
770 pluginDict = {} 770 pluginDict = {}
771 771
772 for name, module in \ 772 for name, module in \
773 list(self.__onDemandActiveModules.items()) + \ 773 list(self.__onDemandActiveModules.items()) + \
774 list(self.__onDemandInactiveModules.items()): 774 list(self.__onDemandInactiveModules.items()):
775 if getattr(module, "pluginType") == type_ and \ 775 if getattr(module, "pluginType") == type_ and \
776 getattr(module, "error", "") == "": 776 getattr(module, "error", "") == "":
777 plugin_name = getattr(module, "pluginTypename") 777 plugin_name = getattr(module, "pluginTypename")
778 if hasattr(module, "displayString"): 778 if hasattr(module, "displayString"):
779 try: 779 try:
795 @param name name of the plugin type (string) 795 @param name name of the plugin type (string)
796 @return preview pixmap (QPixmap) 796 @return preview pixmap (QPixmap)
797 """ 797 """
798 for modname, module in \ 798 for modname, module in \
799 list(self.__onDemandActiveModules.items()) + \ 799 list(self.__onDemandActiveModules.items()) + \
800 list(self.__onDemandInactiveModules.items()): 800 list(self.__onDemandInactiveModules.items()):
801 if getattr(module, "pluginType") == type_ and \ 801 if getattr(module, "pluginType") == type_ and \
802 getattr(module, "pluginTypename") == name: 802 getattr(module, "pluginTypename") == name:
803 if hasattr(module, "previewPix"): 803 if hasattr(module, "previewPix"):
804 return module.previewPix() 804 return module.previewPix()
805 else: 805 else:
815 @return list of API filenames (list of string) 815 @return list of API filenames (list of string)
816 """ 816 """
817 apis = [] 817 apis = []
818 818
819 for module in list(self.__activeModules.values()) + \ 819 for module in list(self.__activeModules.values()) + \
820 list(self.__onDemandActiveModules.values()): 820 list(self.__onDemandActiveModules.values()):
821 if hasattr(module, "apiFiles"): 821 if hasattr(module, "apiFiles"):
822 apis.extend(module.apiFiles(language)) 822 apis.extend(module.apiFiles(language))
823 823
824 return apis 824 return apis
825 825
858 </ul> 858 </ul>
859 """ 859 """
860 infos = [] 860 infos = []
861 861
862 for module in list(self.__activeModules.values()) + \ 862 for module in list(self.__activeModules.values()) + \
863 list(self.__inactiveModules.values()): 863 list(self.__inactiveModules.values()):
864 if hasattr(module, "exeDisplayDataList"): 864 if hasattr(module, "exeDisplayDataList"):
865 infos.extend(module.exeDisplayDataList()) 865 infos.extend(module.exeDisplayDataList())
866 elif hasattr(module, "exeDisplayData"): 866 elif hasattr(module, "exeDisplayData"):
867 infos.append(module.exeDisplayData()) 867 infos.append(module.exeDisplayData())
868 for module in list(self.__onDemandActiveModules.values()) + \ 868 for module in list(self.__onDemandActiveModules.values()) + \
869 list(self.__onDemandInactiveModules.values()): 869 list(self.__onDemandInactiveModules.values()):
870 if hasattr(module, "exeDisplayDataList"): 870 if hasattr(module, "exeDisplayDataList"):
871 infos.extend(module.exeDisplayDataList()) 871 infos.extend(module.exeDisplayDataList())
872 elif hasattr(module, "exeDisplayData"): 872 elif hasattr(module, "exeDisplayData"):
873 infos.append(module.exeDisplayData()) 873 infos.append(module.exeDisplayData())
874 874
906 906
907 @return plug-in configuration data 907 @return plug-in configuration data
908 """ 908 """
909 configData = {} 909 configData = {}
910 for module in list(self.__activeModules.values()) + \ 910 for module in list(self.__activeModules.values()) + \
911 list(self.__onDemandActiveModules.values()) + \ 911 list(self.__onDemandActiveModules.values()) + \
912 list(self.__onDemandInactiveModules.values()): 912 list(self.__onDemandInactiveModules.values()):
913 if hasattr(module, 'getConfigData'): 913 if hasattr(module, 'getConfigData'):
914 configData.update(module.getConfigData()) 914 configData.update(module.getConfigData())
915 return configData 915 return configData
916 916
917 def isPluginLoaded(self, pluginName): 917 def isPluginLoaded(self, pluginName):
920 920
921 @param pluginName name of the plugin to check for (string) 921 @param pluginName name of the plugin to check for (string)
922 @return flag indicating, if the plugin is loaded (boolean) 922 @return flag indicating, if the plugin is loaded (boolean)
923 """ 923 """
924 return pluginName in self.__activeModules or \ 924 return pluginName in self.__activeModules or \
925 pluginName in self.__inactiveModules or \ 925 pluginName in self.__inactiveModules or \
926 pluginName in self.__onDemandActiveModules or \ 926 pluginName in self.__onDemandActiveModules or \
927 pluginName in self.__onDemandInactiveModules 927 pluginName in self.__onDemandInactiveModules
928 928
929 def isPluginActive(self, pluginName): 929 def isPluginActive(self, pluginName):
930 """ 930 """
931 Public method to check, if a certain plugin is active. 931 Public method to check, if a certain plugin is active.
932 932
933 @param pluginName name of the plugin to check for (string) 933 @param pluginName name of the plugin to check for (string)
934 @return flag indicating, if the plugin is active (boolean) 934 @return flag indicating, if the plugin is active (boolean)
935 """ 935 """
936 return pluginName in self.__activeModules or \ 936 return pluginName in self.__activeModules or \
937 pluginName in self.__onDemandActiveModules 937 pluginName in self.__onDemandActiveModules
938 938
939 ########################################################################### 939 ###########################################################################
940 ## Specialized plugin module handling methods below 940 ## Specialized plugin module handling methods below
941 ########################################################################### 941 ###########################################################################
942 942
958 """ 958 """
959 vcsDict = {} 959 vcsDict = {}
960 960
961 for name, module in \ 961 for name, module in \
962 list(self.__onDemandActiveModules.items()) + \ 962 list(self.__onDemandActiveModules.items()) + \
963 list(self.__onDemandInactiveModules.items()): 963 list(self.__onDemandInactiveModules.items()):
964 if getattr(module, "pluginType") == "version_control": 964 if getattr(module, "pluginType") == "version_control":
965 if hasattr(module, "getVcsSystemIndicator"): 965 if hasattr(module, "getVcsSystemIndicator"):
966 res = module.getVcsSystemIndicator() 966 res = module.getVcsSystemIndicator()
967 for indicator, vcsData in list(res.items()): 967 for indicator, vcsData in list(res.items()):
968 if indicator in vcsDict: 968 if indicator in vcsDict:
1005 self.trUtf8( 1005 self.trUtf8(
1006 """<p>The plugin download directory""" 1006 """<p>The plugin download directory"""
1007 """ <b>{0}</b> could not be created. Please""" 1007 """ <b>{0}</b> could not be created. Please"""
1008 """ configure it via the configuration""" 1008 """ configure it via the configuration"""
1009 """ dialog.</p><p>Reason: {1}</p>""") 1009 """ dialog.</p><p>Reason: {1}</p>""")
1010 .format(downloadDir, str(err))) 1010 .format(downloadDir, str(err)))
1011 downloadDir = "" 1011 downloadDir = ""
1012 1012
1013 Preferences.setPluginManager("DownloadPath", downloadDir) 1013 Preferences.setPluginManager("DownloadPath", downloadDir)
1014 1014
1015 def preferencesChanged(self): 1015 def preferencesChanged(self):

eric ide

mercurial