From 0dab304363f4633b315860790ee2689aca1b6c53 Mon Sep 17 00:00:00 2001 From: Lingchaox Xin Date: Wed, 20 Mar 2013 14:25:47 +0800 Subject: [PATCH] Pylinted for job_mail_sender.py Change-Id: Iee5108416a5e02d6bfb493548cc4eaa4d1615aac --- job_mail_sender.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/job_mail_sender.py b/job_mail_sender.py index 260d732..6ebbcdb 100755 --- a/job_mail_sender.py +++ b/job_mail_sender.py @@ -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()) -- 2.7.4