Changeset 658


Ignore:
Timestamp:
Nov 25, 2011 8:14:28 PM (14 years ago)
Author:
jemian
Message:

revise sendMail() and change name of log file, based on pid

Location:
pvMail/src/pyEpics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pvMail/src/pyEpics

    • Property svn:ignore
      • TabularUnified  

        old new  
        1 pvMail.log
         1*.log
        22pvMail_email.txt
        33
  • TabularUnified pvMail/src/pyEpics/pvMail.py

    r657 r658  
    6060import logging
    6161import os
    62 import shlex
    6362import socket
    64 import subprocess
    6563import sys
    6664import time
    6765
    6866
     67__description__ = "Watch an EPICS PV. Send email when it changes from 0 to 1."
    6968__version__ = "3.0a." + "$Rev$".split(" ")[1]
    7069__svnid__ = "$Id$"
    71 __description__ = "Watch an EPICS PV. Send email when it changes from 0 to 1."
    72 LOG_FILE = "pvMail.log"
     70__license__ = "(c) 2009-2012, UChicago Argonne, LLC, BSD-style license, see LICENSE file for details"
     71
     72LOG_FILE = "pvMail-%d.log" % os.getpid()
    7373MESSAGE_FILE = "pvmail_email.txt"
    7474RETRY_INTERVAL_S = 0.2
     
    206206        '''
    207207        logger("send_test_message")
    208         self.recipients = ["prjemian@gmail.com"]
     208        self.recipients = ["jemian", "prjemian"]
    209209        self.message = "this is a test\n\n" + self.addMessageTail()
    210210        self.subject = "pvMail development test"
     
    222222    messageFile = "/tmp/pvmail_message.txt"
    223223    logger("sending email to: " + ", ".join(recipients))
    224     # send the message
     224   
     225    # write the message to a file
     226    # TODO: how can we avoid writing a temporary file?
    225227    pvMailMsg = open(messageFile, "w")
    226228    pvMailMsg.write(message)
    227229    pvMailMsg.close()
    228230
     231    # send the message
    229232    cmd_fmt = '''mail -s "%s" %s < %s'''
    230     for who in recipients:
    231         # send a message to each recipient
    232         cmd = cmd_fmt % ( subject, who, messageFile )
    233         logger( cmd )
    234         os.popen(cmd)   # for now
    235         # popen is deprecated since Python 2.6
    236         # use subprocess module instead
    237        
    238         # THIS DOES NOT WORK CORRECTLY! 
    239         #sends mail to /tmp/pvmail_message.txt with no message
    240         #args = shlex.split(cmd)
    241         #subprocess.call(args) 
     233    cmd = cmd_fmt % ( subject, " ".join(recipients), messageFile )
     234    logger( cmd )
     235    os.popen(cmd)
     236    # popen is deprecated since Python 2.6
     237    # use subprocess module instead
     238   
     239    # THIS DOES NOT WORK CORRECTLY! 
     240    #sends mail to /tmp/pvmail_message.txt with no message
     241    #args = shlex.split(cmd)
     242    #subprocess.call(args) 
    242243
    243244
     
    272273            report_time = time.time() + 5.0
    273274            logger("time remaining: %.1f seconds ..." % (end_time - time.time()))
    274         time.sleep(retry_interval_s)
     275        time.sleep(retry_interval_s)
    275276    pvm.doStop()
    276277
Note: See TracChangeset for help on using the changeset viewer.