eric6/PluginManager/PluginManager.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8268
6b8128e0c9d1
child 8400
b3eefd7e58d1
--- a/eric6/PluginManager/PluginManager.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/PluginManager/PluginManager.py	Sat May 01 14:27:20 2021 +0200
@@ -12,6 +12,7 @@
 import zipfile
 import types
 import importlib
+import contextlib
 
 from PyQt5.QtCore import (
     pyqtSignal, QObject, QDate, QFile, QFileInfo, QUrl, QIODevice
@@ -26,7 +27,7 @@
 
 from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired
 try:
-    from E5Network.E5SslErrorHandler import E5SslErrorHandler
+    from E5Network.E5SslErrorHandler import E5SslErrorHandler, E5SslErrorState
     SSL_AVAILABLE = True
 except ImportError:
     SSL_AVAILABLE = False
@@ -95,7 +96,7 @@
         @exception PluginModulesError raised to indicate the absence of
             plug-in modules
         """
-        super(PluginManager, self).__init__(parent)
+        super().__init__(parent)
         
         self.__ui = parent
         self.__develPluginFile = develPlugin
@@ -160,11 +161,8 @@
             self.__networkManager.sslErrors.connect(self.__sslErrors)
         self.__replies = []
         
-        try:
+        with contextlib.suppress(AttributeError):
             self.__ui.onlineStateChanged.connect(self.__onlineStateChanged)
-        except AttributeError:
-            # it was not called from eric
-            pass
     
     def finalizeSetup(self):
         """
@@ -300,7 +298,7 @@
         """
         for key in self.__priorityOrder:
             if key in self.pluginDirs:
-                if not self.pluginDirs[key] in sys.path:
+                if self.pluginDirs[key] not in sys.path:
                     sys.path.insert(2, self.pluginDirs[key])
                 UI.PixmapCache.addSearchPath(self.pluginDirs[key])
         
@@ -428,12 +426,10 @@
             if reload_:
                 importlib.reload(module)
                 self.initOnDemandPlugin(name)
-                try:
+                with contextlib.suppress(KeyError, AttributeError):
                     pluginObject = self.__onDemandInactivePlugins[name]
                     pluginObject.initToolbar(
                         self.__ui, e5App().getObject("ToolbarManager"))
-                except (KeyError, AttributeError):
-                    pass
         except PluginLoadError:
             print("Error loading plug-in module:", name)
         except Exception as err:
@@ -459,26 +455,18 @@
             self.deactivatePlugin(name)
         
         if name in self.__inactiveModules:
-            try:
+            with contextlib.suppress(KeyError):
                 pluginObject = self.__inactivePlugins[name]
-                try:
+                with contextlib.suppress(AttributeError):
                     pluginObject.prepareUnload()
-                except AttributeError:
-                    pass
                 del self.__inactivePlugins[name]
-            except KeyError:
-                pass
             del self.__inactiveModules[name]
         elif name in self.__onDemandInactiveModules:
-            try:
+            with contextlib.suppress(KeyError):
                 pluginObject = self.__onDemandInactivePlugins[name]
-                try:
+                with contextlib.suppress(AttributeError):
                     pluginObject.prepareUnload()
-                except AttributeError:
-                    pass
                 del self.__onDemandInactivePlugins[name]
-            except KeyError:
-                pass
             del self.__onDemandInactiveModules[name]
         elif name in self.__failedModules:
             del self.__failedModules[name]
@@ -561,11 +549,8 @@
         """
         self.initOnDemandPlugins()
         for pluginObject in self.__onDemandInactivePlugins.values():
-            try:
+            with contextlib.suppress(AttributeError):
                 pluginObject.initToolbar(self.__ui, toolbarManager)
-            except AttributeError:
-                # ignore it
-                pass
     
     def activatePlugins(self):
         """
@@ -602,10 +587,11 @@
         """
         try:
             try:
-                if onDemand:
-                    module = self.__onDemandInactiveModules[name]
-                else:
-                    module = self.__inactiveModules[name]
+                module = (
+                    self.__onDemandInactiveModules[name]
+                    if onDemand else
+                    self.__inactiveModules[name]
+                )
             except KeyError:
                 return None
             
@@ -643,18 +629,14 @@
             
             if onDemand:
                 self.__onDemandInactiveModules.pop(name)
-                try:
+                with contextlib.suppress(KeyError):
                     self.__onDemandInactivePlugins.pop(name)
-                except KeyError:
-                    pass
                 self.__onDemandActivePlugins[name] = pluginObject
                 self.__onDemandActiveModules[name] = module
             else:
                 self.__inactiveModules.pop(name)
-                try:
+                with contextlib.suppress(KeyError):
                     self.__inactivePlugins.pop(name)
-                except KeyError:
-                    pass
                 self.__activePlugins[name] = pluginObject
                 self.__activeModules[name] = module
             return obj
@@ -714,10 +696,11 @@
             on demand plugin (boolean)
         """
         try:
-            if onDemand:
-                module = self.__onDemandActiveModules[name]
-            else:
-                module = self.__activeModules[name]
+            module = (
+                self.__onDemandActiveModules[name]
+                if onDemand else
+                self.__activeModules[name]
+            )
         except KeyError:
             return
         
@@ -739,10 +722,8 @@
                     self.__onDemandInactiveModules[name] = module
                 else:
                     self.__activeModules.pop(name)
-                    try:
+                    with contextlib.suppress(KeyError):
                         self.__activePlugins.pop(name)
-                    except KeyError:
-                        pass
                     self.__inactivePlugins[name] = pluginObject
                     self.__inactiveModules[name] = module
     
@@ -1166,14 +1147,16 @@
             list(self.__onDemandActiveModules.values()) +
             list(self.__onDemandInactiveModules.values())
         ):
-            if getattr(module, "pluginType", "") == "version_control":
-                if hasattr(module, "getVcsSystemIndicator"):
-                    res = module.getVcsSystemIndicator()
-                    for indicator, vcsData in list(res.items()):
-                        if indicator in vcsDict:
-                            vcsDict[indicator].append(vcsData)
-                        else:
-                            vcsDict[indicator] = [vcsData]
+            if (
+                getattr(module, "pluginType", "") == "version_control" and
+                hasattr(module, "getVcsSystemIndicator")
+            ):
+                res = module.getVcsSystemIndicator()
+                for indicator, vcsData in list(res.items()):
+                    if indicator in vcsDict:
+                        vcsDict[indicator].append(vcsData)
+                    else:
+                        vcsDict[indicator] = [vcsData]
         
         return vcsDict
     
@@ -1253,18 +1236,13 @@
             if lastModified.isValid() and lastModified.date().isValid():
                 lastModifiedDate = lastModified.date()
                 now = QDate.currentDate()
-                if period == 1 and lastModifiedDate.day() == now.day():
-                    # daily
-                    return
-                elif period == 2 and lastModifiedDate.daysTo(now) < 7:
-                    # weekly
-                    return
-                elif (
-                    period == 3 and
-                    (lastModifiedDate.daysTo(now) <
-                     lastModifiedDate.daysInMonth())
+                if (
+                    (period == 1 and lastModifiedDate.day() == now.day()) or
+                    (period == 2 and lastModifiedDate.daysTo(now) < 7) or
+                    (period == 3 and (lastModifiedDate.daysTo(now) <
+                                      lastModifiedDate.daysInMonth()))
                 ):
-                    # monthly
+                    # daily, weekly, monthly
                     return
         
         self.__updateAvailable = False
@@ -1410,7 +1388,7 @@
         @param errors list of SSL errors (list of QSslError)
         """
         ignored = self.__sslErrorHandler.sslErrorsReply(reply, errors)[0]
-        if ignored == E5SslErrorHandler.NotIgnored:
+        if ignored == E5SslErrorState.NOT_IGNORED:
             self.__downloadCancelled = True
     
     ########################################################################
@@ -1433,9 +1411,11 @@
             list(self.__activeModules.values()) +
             list(self.__inactiveModules.values())
         ):
-            if getattr(module, "pluginType", "") == type_:
-                if hasattr(module, "clearPrivateData"):
-                    module.clearPrivateData()
+            if (
+                getattr(module, "pluginType", "") == type_ and
+                hasattr(module, "clearPrivateData")
+            ):
+                module.clearPrivateData()
 
 #
 # eflag: noqa = M801

eric ide

mercurial