Commits

Zhang Huangbin  committed 1a31033

Code cleanup.

  • Participants
  • Parent commits 40fe3c3

Comments (0)

Files changed (4)

File src/iredapd-rr.py

 import logging
 import daemon
 
-__version__ = '1.3.7'
-
-SMTP_ACTIONS['defer'] = 'DEFER_IF_PERMIT Service temporarily unavailable'
-
-PLUGIN_DIR = os.path.abspath(os.path.dirname(__file__)) + '/plugins-rr'
-sys.path.append(PLUGIN_DIR)
+# Append plugin directory.
+sys.path.append(os.path.abspath(os.path.dirname(__file__)) + '/plugins-rr')
 
 # Get config file.
 if len(sys.argv) != 2:
 
 from libs import __version__, SMTP_ACTIONS
 
-class apdChannel(asynchat.async_chat):
+class apd_channel(asynchat.async_chat):
     def __init__(self, conn, remoteaddr):
         asynchat.async_chat.__init__(self, conn)
         self.buffer = []
             logging.debug("Connection closed")
 
 
-class apdSocket(asyncore.dispatcher):
+class apd_socket(asyncore.dispatcher):
     def __init__(self, localaddr):
         asyncore.dispatcher.__init__(self)
         self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
 
     def handle_accept(self):
         conn, remoteaddr = self.accept()
-        channel = apdChannel(conn, remoteaddr)
+        channel = apd_channel(conn, remoteaddr)
 
 
 class SQLModeler:
                     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))
+                        logging.info('Error: plugin %s.py not exist.' % plugin)
                     except Exception, e:
                         logging.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))
 
                     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))
+                        logging.info('Error: plugin %s.py not exist.' % plugin)
                     except Exception, e:
                         logging.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))
 
                     )
 
     # Initialize policy daemon.
-    socketDaemon = apdSocket((listen_addr, listen_port))
+    socket_daemon = apd_socket((listen_addr, listen_port))
 
     # Run this program as daemon.
     if run_as_daemon == 'yes':

File src/iredapd.py

 import logging
 import daemon
 
-PLUGIN_DIR = os.path.abspath(os.path.dirname(__file__)) + '/plugins'
-sys.path.append(PLUGIN_DIR)
+# Append plugin directory.
+sys.path.append(os.path.abspath(os.path.dirname(__file__)) + '/plugins')
 
 # Get config file.
 if len(sys.argv) != 2:
 from libs import __version__, SMTP_ACTIONS
 
 
-class apdChannel(asynchat.async_chat):
+class apd_channel(asynchat.async_chat):
     def __init__(self, conn, remoteaddr):
         asynchat.async_chat.__init__(self, conn)
         self.buffer = []
         self.buffer.append(data)
 
     def found_terminator(self):
-        if len(self.buffer) is not 0:
+        if self.buffer:
             line = self.buffer.pop()
             logging.debug("smtp session: " + line)
             if line.find('=') != -1:
             logging.debug("Connection closed")
 
 
-class apdSocket(asyncore.dispatcher):
+class apd_socket(asyncore.dispatcher):
     def __init__(self, localaddr):
         asyncore.dispatcher.__init__(self)
         self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
 
     def handle_accept(self):
         conn, remoteaddr = self.accept()
-        channel = apdChannel(conn, remoteaddr)
+        channel = apd_channel(conn, remoteaddr)
 
 
 def main():
                     )
 
     # Initialize policy daemon.
-    socketDaemon = apdSocket((listen_addr, listen_port))
+    socket_daemon = apd_socket((listen_addr, listen_port))
 
     # Run this program as daemon.
     if run_as_daemon == 'yes':

File src/libs/ldaplib.py

             self.plugins = self.cfg.get('ldap', 'plugins', '')
             self.plugins = [v.strip() for v in self.plugins.split(',')]
 
-            if len(self.plugins) > 0:
+            if self.plugins:
 
                 # Get account dn and LDIF data.
                 recipientDn, recipientLdif = self.__get_recipient_dn_ldif(map['recipient'])
                     except ImportError:
                         # Print error message if plugin module doesn't exist.
                         # Use self.logger.info to let admin know this critical error.
-                        self.logger.info('Error: plugin %s/%s.py not exist.' % (PLUGIN_DIR, plugin))
+                        self.logger.info('Error: plugin %s.py not exist.' % plugin)
                     except Exception, e:
                         self.logger.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))
 

File src/libs/sqllib.py

                     except ImportError:
                         # Print error message if plugin module doesn't exist.
                         # Use self.logger.info to let admin know this critical error.
-                        self.logger.info('Error: plugin %s/%s.py not exist.' % (PLUGIN_DIR, plugin))
+                        self.logger.info('Error: plugin %s.py not exist.' % plugin)
                     except Exception, e:
                         self.logger.debug('Error while importing plugin module (%s): %s' % (plugin, str(e)))