Commits

Zhang Huangbin committed 1d3fcf1

Print error message if plugin module doesn't exist. Thanks Luc Verhoeven for the feedback.

Comments (0)

Files changed (3)

 iRedAPD-1.3.4:
+    * Print error message if plugin module doesn't exist.
     * New plugin: ldap_domain_wblist, used for per-domain white/blacklist
       support (including domain alias). NOTE: This plugin requires latest
       iRedMail LDAP schema file for proper attributes. It's shipped in

src/iredapd-rr.py

 
 __version__ = "1.3.4"
 
-sys.path.append(os.path.abspath(os.path.dirname(__file__)) + '/plugins-rr')
-
 ACTION_ACCEPT = 'DUNNO'
 ACTION_DEFER = 'DEFER_IF_PERMIT Service temporarily unavailable'
 ACTION_REJECT = 'REJECT Not Authorized'
 ACTION_DEFAULT = 'DUNNO'
 
+PLUGIN_DIR = os.path.abspath(os.path.dirname(__file__)) + '/plugins-rr'
+sys.path.append(PLUGIN_DIR)
+
 # Get config file.
 if len(sys.argv) != 2:
     sys.exit('Usage: %s /path/to/iredapd.ini')
                     modeler = MySQLModeler()
 
                 result = modeler.handle_data(self.map)
-                logging.debug("Final action: %s." % str(result))
                 if result != None:
                     action = result
                 else:
                     action = ACTION_ACCEPT
+                logging.debug("Final action: %s." % str(result))
             except Exception, e:
                 action = ACTION_DEFAULT
                 logging.debug('Error: %s. Use default action instead: %s' %
                 for plugin in self.plugins:
                     try:
                         self.modules.append(__import__(plugin))
+                    except ImportError:
+                        # Print error message if plugin module doesn't exist.
+                        # Use logging.info to let admin know this critical error.
+                        logging.info('Error: plugin %s/%s.py not exist.' % (PLUGIN_DIR, plugin))
                     except Exception, e:
                         logging.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))
 
                 for plugin in self.plugins:
                     try:
                         self.modules.append(__import__(plugin))
+                    except ImportError:
+                        # Print error message if plugin module doesn't exist.
+                        # Use logging.info to let admin know this critical error.
+                        logging.info('Error: plugin %s/%s.py not exist.' % (PLUGIN_DIR, plugin))
                     except Exception, e:
                         logging.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))
 
 
 __version__ = "1.3.4"
 
-sys.path.append(os.path.abspath(os.path.dirname(__file__)) + '/plugins')
-
 ACTION_ACCEPT = 'DUNNO'
 ACTION_DEFER = 'DEFER_IF_PERMIT Service temporarily unavailable'
 ACTION_REJECT = 'REJECT Not Authorized'
 ACTION_DEFAULT = 'DUNNO'
 
+PLUGIN_DIR = os.path.abspath(os.path.dirname(__file__)) + '/plugins'
+sys.path.append(PLUGIN_DIR)
+
 # Get config file.
 if len(sys.argv) != 2:
     sys.exit('Usage: %s /path/to/iredapd.ini')
                     modeler = MySQLModeler()
 
                 result = modeler.handle_data(self.map)
-                logging.debug("Final action: %s." % str(result))
                 if result != None:
                     action = result
                 else:
                     action = ACTION_ACCEPT
+                logging.debug("Final action: %s." % str(result))
             except Exception, e:
                 action = ACTION_DEFAULT
                 logging.debug('Error: %s. Use default action instead: %s' %
                 for plugin in self.plugins:
                     try:
                         self.modules.append(__import__(plugin))
+                    except ImportError:
+                        # Print error message if plugin module doesn't exist.
+                        # Use logging.info to let admin know this critical error.
+                        logging.info('Error: plugin %s/%s.py not exist.' % (PLUGIN_DIR, plugin))
                     except Exception, e:
                         logging.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))
 
                 for plugin in self.plugins:
                     try:
                         self.modules.append(__import__(plugin))
+                    except ImportError:
+                        # Print error message if plugin module doesn't exist.
+                        # Use logging.info to let admin know this critical error.
+                        logging.info('Error: plugin %s/%s.py not exist.' % (PLUGIN_DIR, plugin))
                     except Exception, e:
                         logging.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.