def main(): ''' user on-demand test of the mailer module and configuration ''' import argparse import ini_config import PvMail doc = 'test the email sender from PvMail ' + PvMail.__version__ parser = argparse.ArgumentParser(description=doc) msg = 'email address(es), whitespace-separated if more than one' parser.add_argument('recipient', action='store', nargs='+', help=msg, default="") results = parser.parse_args() print doc cfg = ini_config.Config() print "Using configuration from: " + cfg.ini_file print "Using user name: " + cfg.get()['user'] recipients = results.recipient print "Sending email(s) to: " + str(" ".join(recipients)) print "mail transfer agent: " + cfg.mail_transfer_agent subject = 'PvMail mailer test message: ' + cfg.mail_transfer_agent message = 'This is a test of the PvMail mailer, v' + PvMail.__version__ message += '\nFor more help, see: ' + PvMail.__url__ send_message(subject, message, recipients, cfg)
def __init__(self, ui_file=None, logger=None, logfile=None, config=None, *args, **kw): '''make this class callable from pvMail application''' self.ui = uic.loadUi(PvMail.get_pkg_file_path(ui_file or MAIN_UI_FILE)) # PySide way: # http://stackoverflow.com/questions/7144313/loading-qtdesigners-ui-files-in-pyside/18293756#18293756 self.ui.history.clear() self.logger = logger self.logfile = logfile self.config = config or ini_config.Config() self.setStatus('starting') self.email_address_model = EmailListModel([], self.ui) self.pvmail = None self.watching = False # menu item handlers self.ui.actionSend_test_email.triggered.connect(self.doSendTestMessage) self.ui.actionE_xit.triggered.connect(self.doClose) self.ui.actionAbout_pvMail.triggered.connect(self.doAbout) # button handlers self.ui.w_btn_run.clicked.connect(self.doRun) self.ui.w_btn_stop.clicked.connect(self.doStop) # the list of email recipients self.ui.emails.setModel(self.email_address_model) # adjust dynamic labels self.ui.config_file_name.setText(config.ini_file) self.ui.log_file_name.setText(str(logfile)) self.ui.w_running_stopped.setText('stopped') self.ui.l_pv_trigger = QtGui.QLabel('trigger') self.ui.pv_trigger = bcdaqwidgets.BcdaQLabel() self.ui.pv_trigger.setToolTip('PV not connected, no text available') self.ui.formLayout.addRow(self.ui.l_pv_trigger, self.ui.pv_trigger) self.triggerSignal = PvMailSignalDef() self.triggerSignal.EPICS_monitor.connect(self.onTrigger_gui_thread) self.ui.l_pv_message = QtGui.QLabel('message') self.ui.pv_message = bcdaqwidgets.BcdaQLineEdit() self.ui.pv_message.setToolTip('PV not connected, no text available') self.ui.pv_message.setReadOnly(True) self.ui.formLayout.addRow(self.ui.l_pv_message, self.ui.pv_message) self.messageSignal = PvMailSignalDef() self.messageSignal.EPICS_monitor.connect(self.onMessage_gui_thread) self.setStatus('ready')
def SendMessage(pvm, agent_db, reporter=None): ''' construct and send the message :param obj pvm: instance of PvMail object on which to report ''' #print "SendMessage", type(pvm), pvm logger("SendMessage") pvm.trigger = False # triggered event received agent_db = agent_db or ini_config.Config() email_agent_dict = dict(sendmail=mailer.sendMail_sendmail, SMTP=mailer.sendMail_SMTP) emailer = email_agent_dict[agent_db.mail_transfer_agent] try: _send(emailer, pvm, agent_db, logger=logger) except Exception, exc: msg = 'problem sending email: ' + str(exc) logger(msg)
def main(triggerPV, messagePV, recipients, logger=None, logfile=None, config=None): app = QtGui.QApplication(sys.argv) config = config or ini_config.Config() gui = PvMail_GUI(logger=logger, logfile=logfile, config=config) gui.setStatus('PID: ' + str(os.getpid())) if logfile is not None and os.path.exists(logfile): gui.ui.history.append(open(logfile, 'r').read()) gui.setStatus('log file: ' + logfile) gui.setStatus('email configuration file: ' + config.ini_file) gui.setStatus('email agent: ' + config.mail_transfer_agent) gui.setMessagePV(messagePV) gui.setTriggerPV(triggerPV) gui.setEmailList(recipients) gui.show() _r = app.exec_() sys.exit(_r)
def main(): '''parse command-line arguments and choose which interface to use''' vpath = os.path.abspath(os.path.dirname(__file__)) vfile = os.path.join(vpath, 'VERSION') version = open(vfile).read().strip() doc = 'v' + version + ', ' + __doc__.strip() parser = argparse.ArgumentParser(description=doc) # positional arguments # not required if GUI option is selected parser.add_argument('trigger_PV', action='store', nargs='?', help="EPICS trigger PV name", default="") parser.add_argument('message_PV', action='store', nargs='?', help="EPICS message PV name", default="") parser.add_argument('email_addresses', action='store', nargs='?', help="email address(es), comma-separated if more than one", default="") # optional arguments parser.add_argument('-l', action='store', dest='log_file', help="for logging program progress and comments", default=LOG_FILE) parser.add_argument('-i', action='store', dest='logging_interval', type=float, help="checkpoint reporting interval (s) in log file", default=CHECKPOINT_INTERVAL_S) parser.add_argument('-r', action='store', dest='sleep_duration', type=float, help="sleep duration (s) in main event loop", default=RETRY_INTERVAL_S) parser.add_argument('-g', '--gui', action='store_true', default=False, dest='interface', help='Use the graphical rather than command-line interface') parser.add_argument('-v', '--version', action='version', version=version) results = parser.parse_args() addresses = results.email_addresses.strip().split(",") interface = {False: 'command-line', True: 'GUI'}[results.interface] agent_db = ini_config.Config() logging.basicConfig(filename=results.log_file, level=logging.INFO) logger("#"*60) logger("startup") logger("trigger PV = " + results.trigger_PV) logger("message PV = " + results.message_PV) logger("email list = " + str(addresses) ) logger("log file = " + results.log_file) logger("logging interval = " + str( results.logging_interval ) ) logger("sleep duration = " + str( results.sleep_duration ) ) logger("interface = " + interface) user = os.environ.get('LOGNAME', None) or os.environ.get('USERNAME', None) logger("user = "******"host = " + socket.gethostname() ) logger("program = " + sys.argv[0] ) logger("PID = " + str(os.getpid()) ) logger("PyEpics version = " + str(epics.__version__) ) logger("config file = " + agent_db.ini_file ) if results.interface is False: # When the GUI is not selected, # ensure the positional arguments are given tests = [ len(results.trigger_PV), len(results.message_PV), len(" ".join(addresses)), ] if 0 in tests: parser.print_usage() sys.exit() # call the interface {False: cli, True: gui}[results.interface](results)
def setUp(self): self.cfg = ini_config.Config()