Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / lib / alerts.py
index 9ec3f5c..be561b6 100644 (file)
@@ -1,10 +1,11 @@
-#!/usr/bin/python
 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
 """Chromite email utility functions."""
 
+from __future__ import print_function
+
 import cStringIO
 from email.mime.application import MIMEApplication
 from email.mime.multipart import MIMEMultipart
@@ -20,6 +21,20 @@ import traceback
 DEFAULT_SMTP_SERVER = 'localhost'
 
 
+def _SendEmailHelper(smtp_server, sender, email_recipients, msg):
+  """Send an email.
+
+  Args:
+    smtp_server: The server with which to send the message.
+    sender: The from address of the sender of the email.
+    email_recipients: The recipients of the message.
+    msg: A MIMEMultipart() object containing the body of the message.
+  """
+  smtp_client = smtplib.SMTP(smtp_server)
+  smtp_client.sendmail(sender, email_recipients, msg.as_string())
+  smtp_client.quit()
+
+
 def SendEmail(subject, recipients, smtp_server=None, message='',
               attachment=None, extra_fields=None):
   """Send an e-mail job notification with the given message in the body.
@@ -63,9 +78,7 @@ def SendEmail(subject, recipients, smtp_server=None, message='',
     part.add_header('Content-Disposition', 'attachment', filename='logs.txt.gz')
     msg.attach(part)
 
-  smtp_client = smtplib.SMTP(smtp_server)
-  smtp_client.sendmail(sender, email_recipients, msg.as_string())
-  smtp_client.quit()
+  _SendEmailHelper(smtp_server, sender, email_recipients, msg)
 
 
 def SendEmailLog(subject, recipients, smtp_server=None, message='',
@@ -103,4 +116,4 @@ def SendEmailLog(subject, recipients, smtp_server=None, message='',
     attachment = ''.join(log)
 
   SendEmail(subject, recipients, smtp_server, message=message,
-            attachment=attachment, extra_fields=extra_fields)
\ No newline at end of file
+            attachment=attachment, extra_fields=extra_fields)