Commits

Zhang Huangbin committed 1d3fcf1

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

  • Participants
  • Parent commits 65d2f72

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)))