Beispiel #1
0
def notify(text, subject):
    """
  <Purpose>
    Send email with message body text to the members of the notify_list

  <Arguments>
    text, the text of the email message body to be generated

  <Exceptions>
    None.

  <Side Effects>
    Sends email.

  <Returns>
    None.
  """
    try:
        hostname = socket.gethostname()
    except:
        hostname = "unknown host"
    else:
        try:
            hostname = socket.gethostbyname_ex(hostname)[0]
        except:
            pass
    subject = subject + " @ " + hostname + " : " + sys.argv[0]

    for emailaddr in notify_list:
        log("notifying " + emailaddr)
        send_gmail.send_gmail(emailaddr, subject, text, "")

    return
def notify(text, subject):
  """
  <Purpose>
    Send email with message body text to the members of the notify_list

  <Arguments>
    text, the text of the email message body to be generated

  <Exceptions>
    None.

  <Side Effects>
    Sends email.

  <Returns>
    None.
  """
  try:
    hostname = socket.gethostname()
  except:
    hostname = "unknown host"
  else:
    try:
      hostname = socket.gethostbyname_ex(hostname)[0]
    except:
      pass
  subject = subject + " @ "+ hostname + " : " + sys.argv[0]
  
  for emailaddr in notify_list:
    log("notifying " + emailaddr)
    send_gmail.send_gmail(emailaddr, subject, text, "")
	
  return
Beispiel #3
0
def spawn():
    tarball_file = flask.request.files["tarball"]
    command = flask.request.form["command"]
    title = flask.request.form.get("title", "Unnamed test")
    emailees = flask.request.form.getlist("emailee")
    for emailee in emailees:
        assert "@" in emailee
    with database_lock:
        test_id = database.get("next_test_id", 0)
        database["next_test_id"] = test_id + 1
        database["%d.metadata" % test_id] = {
            "title": title,
            "start_time": time.time(),
            "command": command,
            "emailees": emailees
        }
        database.sync()
    try:
        running_tasks[test_id] = {}
        try:
            with database_lock:
                database["%d.result" % test_id] = {"status": "starting"}
                database.sync()
            test_dir = os.path.join(root_dir, "test-%d" % test_id)
            os.mkdir(test_dir)
            box_dir = os.path.join(test_dir, "box")
            os.mkdir(box_dir)
            try:
                tar_cmd = ["tar", "--extract", "-z", "-C", box_dir]
                if hasattr(tarball_file, "fileno"):
                    subprocess32.check_output(tar_cmd + ["--file=-"],
                                              stdin=tarball_file,
                                              stderr=subprocess32.STDOUT)
                else:
                    tarball_path = os.path.join(test_dir, "tarball-temp.tar")
                    tarball_file.save(tarball_path)
                    subprocess32.check_output(tar_cmd +
                                              ["--file", tarball_path],
                                              stderr=subprocess32.STDOUT)
                    os.remove(tarball_path)
            except subprocess32.CalledProcessError, e:
                raise ValueError("Bad tarball: " + e.output)
            if not os.access(os.path.join(box_dir, "renderer"), os.X_OK):
                raise ValueError("renderer is missing or not executable")
            for emailee in emailees:
                send_gmail.send_gmail(subject=title,
                                      body=flask.url_for("view",
                                                         test_id=test_id,
                                                         _external=True),
                                      sender=(emailer, emailer_password),
                                      receiver=emailee)
        except Exception, e:
            del running_tasks[test_id]
            raise
Beispiel #4
0
def status_email(script, sender, recipient):
	start = datetime.datetime.now()
	script_str = " ".join(script)
	print "Running '%s'..." % script_str
	status = subprocess.check_call(script)
	runtime = str(datetime.datetime.now() - start)
	message = "'%s' exited with status %s after %s" % (script_str, status, runtime)
	if status == 0:
		message = "Good news! " + message
	subject = "'%s' finished" % script_str
	print message
	print "Preparing to send mail"
	send_gmail.send_gmail(sender, pw, recipient, subject, message)
Beispiel #5
0
def status_email(script, sender, recipient):
    start = datetime.datetime.now()
    script_str = " ".join(script)
    print "Running '%s'..." % script_str
    status = subprocess.check_call(script)
    runtime = str(datetime.datetime.now() - start)
    message = "'%s' exited with status %s after %s" % (script_str, status,
                                                       runtime)
    if status == 0:
        message = "Good news! " + message
    subject = "'%s' finished" % script_str
    print message
    print "Preparing to send mail"
    send_gmail.send_gmail(sender, pw, recipient, subject, message)
Beispiel #6
0
def spawn():
    tarball_file = flask.request.files["tarball"]
    command = flask.request.form["command"]
    title = flask.request.form.get("title", "Unnamed test")
    emailees = flask.request.form.getlist("emailee")
    for emailee in emailees:
        assert "@" in emailee
    with database_lock:
        test_id = database.get("next_test_id", 0)
        database["next_test_id"] = test_id + 1
        database["%d.metadata" % test_id] = {
            "title": title,
            "start_time": time.time(),
            "command": command,
            "emailees": emailees
            }
        database.sync()
    try:
        running_tasks[test_id] = { }
        try:
            with database_lock:
                database["%d.result" % test_id] = { "status": "starting" }
                database.sync()
            test_dir = os.path.join(root_dir, "test-%d" % test_id)
            os.mkdir(test_dir)
            box_dir = os.path.join(test_dir, "box")
            os.mkdir(box_dir)
            try:
                tar_cmd = ["tar", "--extract", "-z", "-C", box_dir]
                if hasattr(tarball_file, "fileno"):
                    subprocess32.check_output(tar_cmd + ["--file=-"], stdin = tarball_file, stderr = subprocess32.STDOUT)
                else:
                    tarball_path = os.path.join(test_dir, "tarball-temp.tar")
                    tarball_file.save(tarball_path)
                    subprocess32.check_output(tar_cmd + ["--file", tarball_path], stderr = subprocess32.STDOUT)
                    os.remove(tarball_path)
            except subprocess32.CalledProcessError, e:
                raise ValueError("Bad tarball: " + e.output)
            if not os.access(os.path.join(box_dir, "renderer"), os.X_OK):
                raise ValueError("renderer is missing or not executable")
            for emailee in emailees:
                send_gmail.send_gmail(
                    subject = title,
                    body = flask.url_for("view", test_id = test_id, _external = True),
                    sender = (emailer, emailer_password),
                    receiver = emailee)
        except Exception, e:
            del running_tasks[test_id]
            raise
def notify(text, subject):
  """
  <Purpose>
    Send email with message body text to the members of the notify_list

  <Arguments>
    text, the text of the email message body to be generated

  <Exceptions>
    None.

  <Side Effects>
    Sends email.

  <Returns>
    None.
  """
  try:
    hostname = socket.gethostname()
  except:
    hostname = "unknown host"
  else:
    try:
      hostname = socket.gethostbyname_ex(hostname)[0]
    except:
      pass
  subject = subject + " @ "+ hostname + " : " + sys.argv[0]

  #This will loop through a file containing emails that need to be notified and create a list out of them
  notify_list = []
  email_file = open("email_address_list_file", "r")
  email_list = email_file.readlines()
  email_file.close()
  for email_address in email_list:
    email_address = email_address.rstrip("\r\n")
    notify_list.append(email_address)
    log("notifying " + email_address)
    send_gmail.send_gmail(email_address, subject, text, "")
  return
Beispiel #8
0
def main():
  """
  <Purpose>
      Checks out milestones.txt from the repository. Interprets
      it and sends email if anyone is late on their sprints.
  
  <Arguments>
      None
  
  <Exceptions>
      Not sure.

  <Side Effects>
      Sends email.

  <Returns>
      Returns 1 if anyone is late. Otherwise returns 0.
  """
  global notify_list
  global svn_repo_path

  # grab latest milestones revision from the repo
  milestones_txt = command_output("svn cat http://seattle.cs.washington.edu/svn/seattle/trunk/milestones.txt")
  
# failure example:
#  milestones_txt = """
#:sprint
#01/01/2009
#eye candy
#789 alper parallelize resource acquisition and release
#sean redesign GENI portal
#"""

  # setup gmail lib
  if enable_email:
    gmail_user, gmail_pwd = open("/var/local/svn/hooks/gmail_account","r").read().strip().split()
    send_gmail.init_gmail(gmail_user=gmail_user, gmail_pwd=gmail_pwd)

  # check if any of the sprint personnel are past deadline
  sprints = parse_sprints(milestones_txt)
  if sprints is None:
    # syntax error in parsing milestones_txt
    print "syntax error in parsing milestones file"
    if enable_email:
      # send email to notify_list members
      for email in notify_list:
        send_gmail.send_gmail(email, "svn-hook milestokes-checker syntax error in milestones file", "", "")
    return 1
    
  for sprint in sprints:
      sprint_date = datetime.strptime("%s 00:00:00"%(sprint['date']), "%m/%d/%Y %H:%M:%S")
      # print sprint_date
      if sprint_date <= datetime.now():
          if sprint['date'] == datetime.now().strftime("%m/%d/%Y"):
            # sprint due today
            notify = True
          else:
            # sprint in the past
            notify = False
            
          notify_str = '''
For the %s sprint for the %s strike force:

'''%(sprint['date'], sprint['force'])
          # check if we need to notify
          for user in sprint['users']:
            try:
              rev = "Completed as of revision %i"%(int(user.split(' ')[0]))
              task = ' '.join(user.split(' ')[2:])
              user = user.split(' ')[1]
            except ValueError:
              rev = "Failed to complete"
              # always notify when someone failed in a sprint
              notify = True
              task = ' '.join(user.split(' ')[1:])
              user = user.split(' ')[0]
              
            notify_str += '''
User            %s
Task            %s
%s'''%(user, task, rev) + '\n\n'
          
          if notify:
            print notify_str
            if enable_email:
              # send email to notify_list members
              for email in notify_list:
                send_gmail.send_gmail(email, "[status] strike force: %s, sprint: %s"%(sprint['force'], sprint['date']), notify_str, "")
  return 0
Beispiel #9
0
from send_gmail import send_gmail

send_gmail('*****@*****.**', 'this is subject', 'this is body')
Beispiel #10
0
    camera.start_preview()
    camera.preview_fullscreen = True
    
    try:
        print "%s Camera capture started" % (datetime.datetime.now())
        while 1:
            camera.wait_recording(.1)
            if write_now:
                write_image();                             # Write the jpg image
                camera.wait_recording( trigger_delay )     # Wait delay period
                camera.stop_recording()                    # Stop the recording
                write_video( stream );                     # Save the video capture
                wrap_video();                              # wrap it in an MP4 container
                downsize_image();                          # downsize the jpg image
#                send_gmail( "email.html", "Alert from CLX", "public/foo_small.jpg" );  # Send out the mail
                send_gmail( email_file, ourpath + "public/foo_small.jpg" );  # Send out the mail               
                print "Restarting video"
                camera.start_recording(stream, format='h264')                
                write_now = False
            if exit_now:
                break
    except Exception as ex:
        print "Exception!!! ", ex

        errfile = open( "cam_cap.log", "w" )
        traceback.print_tb( errfile )

    finally:
        print "Stopped camera"
        camera.stop_recording()
Beispiel #11
0
# Import Libraries
import os, sys

d = os.path.dirname(__file__)
d = d if d else '.'
sys.path.append(d + "/../Lib")

import send_gmail

send_gmail.send_gmail("Température Perros-Guirec", "La température est 20°")

Beispiel #12
0
with Timer() as t:
    for each in col.find({}):
        domain = each['domain']
        page_type = each['pagetype']
        type_id = PAGE_TYPES.index(page_type)
        
        if domain:
            domains[domain][0] += 1
            domains[domain][type_id + 1] += 1
print "The creation of STAT costs: ", t.interval

# sort the result based on freq
with Timer() as t:
    sorted_domains = sorted(domains.items(), key=lambda k: k[1][0], reverse=True)
print "Sorting STAT costs: ", t.interval

# save the result
with Timer() as t:
    with open("../io/wrike_webpage_stat.txt", "w") as wf:
        for (domain, count_list) in sorted_domains:
            count_str = "\t".join(str(each) for each in count_list)
            wf.write("\t".join([domain, count_str]) + "\n")
print "Writing to a text file costs: ", t.interval

send_gmail(gmail_user='******',
           passwd="",
           recipient='*****@*****.**',
           subject='Wrike News Stat',
           body='Done')

def main():
    """
  <Purpose>
      Checks out milestones.txt from the repository. Interprets
      it and sends email if anyone is late on their sprints.
  
  <Arguments>
      None
  
  <Exceptions>
      Not sure.

  <Side Effects>
      Sends email.

  <Returns>
      Returns 1 if anyone is late. Otherwise returns 0.
  """
    global notify_list
    global svn_repo_path

    # grab latest milestones revision from the repo
    milestones_txt = command_output(
        "svn cat http://seattle.cs.washington.edu/svn/seattle/trunk/milestones.txt"
    )

    # failure example:
    #  milestones_txt = """
    #:sprint
    #01/01/2009
    #eye candy
    #789 alper parallelize resource acquisition and release
    #sean redesign GENI portal
    #"""

    # setup gmail lib
    if enable_email:
        gmail_user, gmail_pwd = open("/var/local/svn/hooks/gmail_account",
                                     "r").read().strip().split()
        send_gmail.init_gmail(gmail_user=gmail_user, gmail_pwd=gmail_pwd)

    # check if any of the sprint personnel are past deadline
    sprints = parse_sprints(milestones_txt)
    if sprints is None:
        # syntax error in parsing milestones_txt
        print "syntax error in parsing milestones file"
        if enable_email:
            # send email to notify_list members
            for email in notify_list:
                send_gmail.send_gmail(
                    email,
                    "svn-hook milestokes-checker syntax error in milestones file",
                    "", "")
        return 1

    for sprint in sprints:
        sprint_date = datetime.strptime("%s 00:00:00" % (sprint['date']),
                                        "%m/%d/%Y %H:%M:%S")
        # print sprint_date
        if sprint_date <= datetime.now():
            if sprint['date'] == datetime.now().strftime("%m/%d/%Y"):
                # sprint due today
                notify = True
            else:
                # sprint in the past
                notify = False

            notify_str = '''
For the %s sprint for the %s strike force:

''' % (sprint['date'], sprint['force'])
            # check if we need to notify
            for user in sprint['users']:
                try:
                    rev = "Completed as of revision %i" % (int(
                        user.split(' ')[0]))
                    task = ' '.join(user.split(' ')[2:])
                    user = user.split(' ')[1]
                except ValueError:
                    rev = "Failed to complete"
                    # always notify when someone failed in a sprint
                    notify = True
                    task = ' '.join(user.split(' ')[1:])
                    user = user.split(' ')[0]

                notify_str += '''
User            %s
Task            %s
%s''' % (user, task, rev) + '\n\n'

            if notify:
                print notify_str
                if enable_email:
                    # send email to notify_list members
                    for email in notify_list:
                        send_gmail.send_gmail(
                            email, "[status] strike force: %s, sprint: %s" %
                            (sprint['force'], sprint['date']), notify_str, "")
    return 0