139 if self.__develPluginFile: |
139 if self.__develPluginFile: |
140 path = Utilities.splitPath(self.__develPluginFile)[0] |
140 path = Utilities.splitPath(self.__develPluginFile)[0] |
141 fname = os.path.join(path, "__init__.py") |
141 fname = os.path.join(path, "__init__.py") |
142 if not os.path.exists(fname): |
142 if not os.path.exists(fname): |
143 try: |
143 try: |
144 f = open(fname, "wb") |
144 f = open(fname, "w") |
145 f.close() |
145 f.close() |
146 except IOError: |
146 except IOError: |
147 return (False, |
147 return (False, |
148 self.trUtf8("Could not create a package for {0}.")\ |
148 self.trUtf8("Could not create a package for {0}.")\ |
149 .format(self.__develPluginFile)) |
149 .format(self.__develPluginFile)) |
150 |
150 |
151 if Preferences.getPluginManager("ActivateExternal"): |
151 if Preferences.getPluginManager("ActivateExternal"): |
152 fname = os.path.join(self.pluginDirs["user"], "__init__.py") |
152 fname = os.path.join(self.pluginDirs["user"], "__init__.py") |
153 if not os.path.exists(fname): |
153 if not os.path.exists(fname): |
154 if not os.path.exists(self.pluginDirs["user"]): |
154 if not os.path.exists(self.pluginDirs["user"]): |
155 os.mkdir(self.pluginDirs["user"], 0755) |
155 os.mkdir(self.pluginDirs["user"], 0o755) |
156 try: |
156 try: |
157 f = open(fname, "wb") |
157 f = open(fname, "w") |
158 f.close() |
158 f.close() |
159 except IOError: |
159 except IOError: |
160 del self.pluginDirs["user"] |
160 del self.pluginDirs["user"] |
161 |
161 |
162 if not os.path.exists(self.pluginDirs["global"]) and \ |
162 if not os.path.exists(self.pluginDirs["global"]) and \ |
163 os.access(Utilities.getPythonModulesDirectory(), os.W_OK): |
163 os.access(Utilities.getPythonModulesDirectory(), os.W_OK): |
164 # create the global plugins directory |
164 # create the global plugins directory |
165 os.mkdir(self.pluginDirs["global"], 0755) |
165 os.mkdir(self.pluginDirs["global"], 0o755) |
166 fname = os.path.join(self.pluginDirs["global"], "__init__.py") |
166 fname = os.path.join(self.pluginDirs["global"], "__init__.py") |
167 f = open() |
167 f = open() |
168 f.write('# -*- coding: utf-8 -*-' + os.linesep) |
168 f.write('# -*- coding: utf-8 -*-' + os.linesep) |
169 f.write(os.linesep) |
169 f.write(os.linesep) |
170 f.write('"""' + os.linesep) |
170 f.write('"""' + os.linesep) |
311 module.eric4PluginModuleFilename = fname |
311 module.eric4PluginModuleFilename = fname |
312 self.__modulesCount += 1 |
312 self.__modulesCount += 1 |
313 if reload_: |
313 if reload_: |
314 reload(module) |
314 reload(module) |
315 except PluginLoadError: |
315 except PluginLoadError: |
316 print "Error loading plugin module:", name |
316 print("Error loading plugin module:", name) |
317 except StandardError, err: |
317 except Exception as err: |
318 module = imp.new_module(name) |
318 module = imp.new_module(name) |
319 module.error = \ |
319 module.error = \ |
320 self.trUtf8("Module failed to load. Error: {0}").format(unicode(err)) |
320 self.trUtf8("Module failed to load. Error: {0}").format(str(err)) |
321 self.__failedModules[name] = module |
321 self.__failedModules[name] = module |
322 print "Error loading plugin module:", name |
322 print("Error loading plugin module:", name) |
323 print unicode(err) |
323 print(str(err)) |
324 |
324 |
325 def unloadPlugin(self, name, directory): |
325 def unloadPlugin(self, name, directory): |
326 """ |
326 """ |
327 Public method to unload a plugin module. |
327 Public method to unload a plugin module. |
328 |
328 |
526 className, "activate") |
526 className, "activate") |
527 if not hasattr(pluginClass, "deactivate"): |
527 if not hasattr(pluginClass, "deactivate"): |
528 raise PluginClassFormatError(module.eric4PluginModuleName, |
528 raise PluginClassFormatError(module.eric4PluginModuleName, |
529 className, "deactivate") |
529 className, "deactivate") |
530 return True |
530 return True |
531 except PluginModuleFormatError, e: |
531 except PluginModuleFormatError as e: |
532 print repr(e) |
532 print(repr(e)) |
533 return False |
533 return False |
534 except PluginClassFormatError, e: |
534 except PluginClassFormatError as e: |
535 print repr(e) |
535 print(repr(e)) |
536 return False |
536 return False |
537 |
537 |
538 def deactivatePlugin(self, name, onDemand = False): |
538 def deactivatePlugin(self, name, onDemand = False): |
539 """ |
539 """ |
540 Public method to deactivate a plugin. |
540 Public method to deactivate a plugin. |
594 @param typename name of the plugin within the type category (string) |
594 @param typename name of the plugin within the type category (string) |
595 @keyparam maybeActive flag indicating, that the plugin may be active |
595 @keyparam maybeActive flag indicating, that the plugin may be active |
596 already (boolean) |
596 already (boolean) |
597 @return reference to the initialized plugin object |
597 @return reference to the initialized plugin object |
598 """ |
598 """ |
599 for name, module in self.__onDemandInactiveModules.items(): |
599 for name, module in list(self.__onDemandInactiveModules.items()): |
600 if getattr(module, "pluginType") == type_ and \ |
600 if getattr(module, "pluginType") == type_ and \ |
601 getattr(module, "pluginTypename") == typename: |
601 getattr(module, "pluginTypename") == typename: |
602 return self.activatePlugin(name, onDemand = True) |
602 return self.activatePlugin(name, onDemand = True) |
603 |
603 |
604 if maybeActive: |
604 if maybeActive: |
605 for name, module in self.__onDemandActiveModules.items(): |
605 for name, module in list(self.__onDemandActiveModules.items()): |
606 if getattr(module, "pluginType") == type_ and \ |
606 if getattr(module, "pluginType") == type_ and \ |
607 getattr(module, "pluginTypename") == typename: |
607 getattr(module, "pluginTypename") == typename: |
608 self.deactivatePlugin(name, onDemand = True) |
608 self.deactivatePlugin(name, onDemand = True) |
609 return self.activatePlugin(name, onDemand = True) |
609 return self.activatePlugin(name, onDemand = True) |
610 |
610 |
618 version (string), autoactivate (boolean), active (boolean), |
618 version (string), autoactivate (boolean), active (boolean), |
619 short description (string), error flag (boolean) |
619 short description (string), error flag (boolean) |
620 """ |
620 """ |
621 infos = [] |
621 infos = [] |
622 |
622 |
623 for name in self.__activeModules.keys(): |
623 for name in list(self.__activeModules.keys()): |
624 pname, shortDesc, error, version = \ |
624 pname, shortDesc, error, version = \ |
625 self.__getShortInfo(self.__activeModules[name]) |
625 self.__getShortInfo(self.__activeModules[name]) |
626 infos.append((name, pname, version, True, True, shortDesc, error)) |
626 infos.append((name, pname, version, True, True, shortDesc, error)) |
627 for name in self.__inactiveModules.keys(): |
627 for name in list(self.__inactiveModules.keys()): |
628 pname, shortDesc, error, version = \ |
628 pname, shortDesc, error, version = \ |
629 self.__getShortInfo(self.__inactiveModules[name]) |
629 self.__getShortInfo(self.__inactiveModules[name]) |
630 infos.append((name, pname, version, True, False, shortDesc, error)) |
630 infos.append((name, pname, version, True, False, shortDesc, error)) |
631 for name in self.__onDemandActiveModules.keys(): |
631 for name in list(self.__onDemandActiveModules.keys()): |
632 pname, shortDesc, error, version = \ |
632 pname, shortDesc, error, version = \ |
633 self.__getShortInfo(self.__onDemandActiveModules[name]) |
633 self.__getShortInfo(self.__onDemandActiveModules[name]) |
634 infos.append((name, pname, version, False, True, shortDesc, error)) |
634 infos.append((name, pname, version, False, True, shortDesc, error)) |
635 for name in self.__onDemandInactiveModules.keys(): |
635 for name in list(self.__onDemandInactiveModules.keys()): |
636 pname, shortDesc, error, version = \ |
636 pname, shortDesc, error, version = \ |
637 self.__getShortInfo(self.__onDemandInactiveModules[name]) |
637 self.__getShortInfo(self.__onDemandInactiveModules[name]) |
638 infos.append((name, pname, version, False, False, shortDesc, error)) |
638 infos.append((name, pname, version, False, False, shortDesc, error)) |
639 for name in self.__failedModules.keys(): |
639 for name in list(self.__failedModules.keys()): |
640 pname, shortDesc, error, version = \ |
640 pname, shortDesc, error, version = \ |
641 self.__getShortInfo(self.__failedModules[name]) |
641 self.__getShortInfo(self.__failedModules[name]) |
642 infos.append((name, pname, version, False, False, shortDesc, error)) |
642 infos.append((name, pname, version, False, False, shortDesc, error)) |
643 return infos |
643 return infos |
644 |
644 |
721 (dictionary of string) |
721 (dictionary of string) |
722 """ |
722 """ |
723 pluginDict = {} |
723 pluginDict = {} |
724 |
724 |
725 for name, module in \ |
725 for name, module in \ |
726 self.__onDemandActiveModules.items() + self.__onDemandInactiveModules.items(): |
726 list(self.__onDemandActiveModules.items()) + list(self.__onDemandInactiveModules.items()): |
727 if getattr(module, "pluginType") == type_ and \ |
727 if getattr(module, "pluginType") == type_ and \ |
728 getattr(module, "error", "") == "": |
728 getattr(module, "error", "") == "": |
729 plugin_name = getattr(module, "pluginTypename") |
729 plugin_name = getattr(module, "pluginTypename") |
730 if hasattr(module, "displayString"): |
730 if hasattr(module, "displayString"): |
731 try: |
731 try: |
746 @param type_ type of the plugin (string) |
746 @param type_ type of the plugin (string) |
747 @param name name of the plugin type (string) |
747 @param name name of the plugin type (string) |
748 @return preview pixmap (QPixmap) |
748 @return preview pixmap (QPixmap) |
749 """ |
749 """ |
750 for modname, module in \ |
750 for modname, module in \ |
751 self.__onDemandActiveModules.items() + self.__onDemandInactiveModules.items(): |
751 list(self.__onDemandActiveModules.items()) + list(self.__onDemandInactiveModules.items()): |
752 if getattr(module, "pluginType") == type_ and \ |
752 if getattr(module, "pluginType") == type_ and \ |
753 getattr(module, "pluginTypename") == name: |
753 getattr(module, "pluginTypename") == name: |
754 if hasattr(module, "previewPix"): |
754 if hasattr(module, "previewPix"): |
755 return module.previewPix() |
755 return module.previewPix() |
756 else: |
756 else: |
805 <li>version - version text to be shown (string)</li> |
805 <li>version - version text to be shown (string)</li> |
806 </ul> |
806 </ul> |
807 """ |
807 """ |
808 infos = [] |
808 infos = [] |
809 |
809 |
810 for module in self.__activeModules.values() + \ |
810 for module in list(self.__activeModules.values()) + \ |
811 self.__inactiveModules.values(): |
811 list(self.__inactiveModules.values()): |
812 if hasattr(module, "exeDisplayData"): |
812 if hasattr(module, "exeDisplayData"): |
813 infos.append(module.exeDisplayData()) |
813 infos.append(module.exeDisplayData()) |
814 for module in self.__onDemandActiveModules.values() + \ |
814 for module in list(self.__onDemandActiveModules.values()) + \ |
815 self.__onDemandInactiveModules.values(): |
815 list(self.__onDemandInactiveModules.values()): |
816 if hasattr(module, "exeDisplayData"): |
816 if hasattr(module, "exeDisplayData"): |
817 infos.append(module.exeDisplayData()) |
817 infos.append(module.exeDisplayData()) |
818 |
818 |
819 return infos |
819 return infos |
820 |
820 |
844 <dt>reference to configuration page</dt> |
844 <dt>reference to configuration page</dt> |
845 <dd>This will be used by the configuration dialog and must always be None</dd> |
845 <dd>This will be used by the configuration dialog and must always be None</dd> |
846 </dl> |
846 </dl> |
847 """ |
847 """ |
848 configData = {} |
848 configData = {} |
849 for module in self.__activeModules.values() + \ |
849 for module in list(self.__activeModules.values()) + \ |
850 self.__onDemandActiveModules.values() + \ |
850 list(self.__onDemandActiveModules.values()) + \ |
851 self.__onDemandInactiveModules.values(): |
851 list(self.__onDemandInactiveModules.values()): |
852 if hasattr(module, 'getConfigData'): |
852 if hasattr(module, 'getConfigData'): |
853 configData.update(module.getConfigData()) |
853 configData.update(module.getConfigData()) |
854 return configData |
854 return configData |
855 |
855 |
856 def isPluginLoaded(self, pluginName): |
856 def isPluginLoaded(self, pluginName): |
895 Each tuple contains the vcs name (string) and vcs display string (string). |
895 Each tuple contains the vcs name (string) and vcs display string (string). |
896 """ |
896 """ |
897 vcsDict = {} |
897 vcsDict = {} |
898 |
898 |
899 for name, module in \ |
899 for name, module in \ |
900 self.__onDemandActiveModules.items() + self.__onDemandInactiveModules.items(): |
900 list(self.__onDemandActiveModules.items()) + list(self.__onDemandInactiveModules.items()): |
901 if getattr(module, "pluginType") == "version_control": |
901 if getattr(module, "pluginType") == "version_control": |
902 if hasattr(module, "getVcsSystemIndicator"): |
902 if hasattr(module, "getVcsSystemIndicator"): |
903 res = module.getVcsSystemIndicator() |
903 res = module.getVcsSystemIndicator() |
904 for indicator, vcsData in res.items(): |
904 for indicator, vcsData in list(res.items()): |
905 if indicator in vcsDict: |
905 if indicator in vcsDict: |
906 vcsDict[indicator].append(vcsData) |
906 vcsDict[indicator].append(vcsData) |
907 else: |
907 else: |
908 vcsDict[indicator] = [vcsData] |
908 vcsDict[indicator] = [vcsData] |
909 |
909 |
925 if not downloadDir: |
925 if not downloadDir: |
926 downloadDir = self.__defaultDownloadDir |
926 downloadDir = self.__defaultDownloadDir |
927 |
927 |
928 if not os.path.exists(downloadDir): |
928 if not os.path.exists(downloadDir): |
929 try: |
929 try: |
930 os.mkdir(downloadDir, 0755) |
930 os.mkdir(downloadDir, 0o755) |
931 except (OSError, IOError), err: |
931 except (OSError, IOError) as err: |
932 # try again with (possibly) new default |
932 # try again with (possibly) new default |
933 downloadDir = self.__defaultDownloadDir |
933 downloadDir = self.__defaultDownloadDir |
934 if not os.path.exists(downloadDir): |
934 if not os.path.exists(downloadDir): |
935 try: |
935 try: |
936 os.mkdir(downloadDir, 0755) |
936 os.mkdir(downloadDir, 0o755) |
937 except (OSError, IOError), err: |
937 except (OSError, IOError) as err: |
938 QMessageBox.critical(self.__ui, |
938 QMessageBox.critical(self.__ui, |
939 self.trUtf8("Plugin Manager Error"), |
939 self.trUtf8("Plugin Manager Error"), |
940 self.trUtf8("""<p>The plugin download directory <b>{0}</b> """ |
940 self.trUtf8("""<p>The plugin download directory <b>{0}</b> """ |
941 """could not be created. Please configure it """ |
941 """could not be created. Please configure it """ |
942 """via the configuration dialog.</p>""" |
942 """via the configuration dialog.</p>""" |
943 """<p>Reason: {1}</p>""")\ |
943 """<p>Reason: {1}</p>""")\ |
944 .format(downloadDir, unicode(err))) |
944 .format(downloadDir, str(err))) |
945 downloadDir = "" |
945 downloadDir = "" |
946 |
946 |
947 Preferences.setPluginManager("DownloadPath", downloadDir) |
947 Preferences.setPluginManager("DownloadPath", downloadDir) |
948 |
948 |
949 def preferencesChanged(self): |
949 def preferencesChanged(self): |