Pylinted for job_mail_sender.py
authorLingchaox Xin <lingchaox.xin@intel.com>
Wed, 20 Mar 2013 06:25:47 +0000 (14:25 +0800)
committerLingchaox Xin <lingchaox.xin@intel.com>
Fri, 22 Mar 2013 07:17:53 +0000 (15:17 +0800)
Change-Id: Iee5108416a5e02d6bfb493548cc4eaa4d1615aac

job_mail_sender.py

index 260d732..6ebbcdb 100755 (executable)
@@ -1,21 +1,17 @@
 #!/usr/bin/env python
 
+"""This script is used to send mail due to job's finishing state"""
+
 import os
 import re
 import base64
+import sys
 
-from common.send_mail import sendmail, makemail
-from common.envparas import export
+from common.send_mail import sendmail
 
-envparas = ['FROM',
-            'TO',
-            'MESSAGE',
-            'SMTP_SERVER']
 
-export(envparas, locals())
-            
 def is_base64str(string):
-    ''' return Ture or False '''
+    ''' If a string is base64 coded, return True; otherwise False'''
     try:
         if (len(string) % 4) == 0:
             if re.match("[A-Za-z0-9/+=]*$", string):
@@ -24,8 +20,16 @@ def is_base64str(string):
         return False
     return False
 
-if is_base64str(MESSAGE):
-    sendmail(FROM, TO.split(','), base64.b64decode(MESSAGE), SMTP_SERVER)
-else:
-    print "Invalid mail message, job abort!"
+def main():
+    """The main body"""
+
+    message = os.getenv('MESSAGE')
+
+    if is_base64str(message):
+        sendmail(os.getenv('FROM'), os.getenv('TO').split(','),
+                base64.b64decode(message), os.getenv('SMTP_SERVER'))
+    else:
+        print "Invalid mail message, job abort!"
 
+if __name__ == '__main__':
+    sys.exit(main())