python PyQt5 implements the demo of email reminder after vivado completes the implementation

Keywords: Python PyQt5 vivado

1 function

ug904 mentioned that if you want to use a remote host to start one or more job s, select "start and run on the remote host (Linux only)". If I want to use another windows host to run programs, I need to open remote control to monitor the operation or check it often. In order to solve this problem, I implemented a simple demo with python pyqt5.

Realized function: monitor the log file of vivado implementation at an interval of 1 minute. If there is information in the log: [common 17-206] exiting vivado at XXX, send some previous key steps and the searched time to the received email address.

2 code

2.1 introduction

import sys
import re
import threading
import time
import win32ui
import smtplib
from email.mime.text import MIMEText

def fun_sendmail(list_info):
    print("entry fun_sendmail")
    #Set up the information required by the server
    #163 mailbox server address
    mail_host = 'smtp.163.com'  
    #163 user name
    mail_user = '137xxxxxxxx'  
    #Password (some mailboxes are IMAP/SMTP authorization codes) 
    mail_pass = 'xxxxxxxxxxxxxx'   
    #Email address of mail sender
    sender = '137xxxxxxxx@163.com'  
    #The email address of the mail recipient. Note that [] packages are required, which means you can write multiple email addresses for mass sending
    receivers = ['163xxxxxxx@qq.com']  

    #Set email information
    #Mail content settings
    text_str = ''.join(list_info)
    message = MIMEText(text_str,'plain','utf-8')
    #Mail subject       
    message['Subject'] = "The program is finished!" 
    #sender information 
    message['From'] = sender 
    #Recipient information     
    message['To'] = receivers[0]   
    print(message)
    #Sign in and send mail
    try:
        smtpObj = smtplib.SMTP() 
        #Connect to server
        smtpObj.connect(mail_host,25)
        #Log in to the server
        smtpObj.login(mail_user,mail_pass) 
        #send out
        smtpObj.sendmail(
            sender,receivers,message.as_string()) 
        #sign out
        smtpObj.quit() 
        print('success')
    except smtplib.SMTPException as e:
        print('error',e)

def fun_serch_keyword(path):
    print("entry fun_serch_keyword")
    global list_info
    file = open(path, mode = 'r')
    info_index = 0
    info_num = len(list_info)
    time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    line = file.readline()
    while line:
        line = file.readline() 
        if(re.findall('Starting|Ending|Exiting', line)):
            info_index += 1
            if info_index > info_num:
                list_info.append(time_str+'\t'+line)
                print(line)
        if(re.findall('Exiting', line)):
            fun_sendmail(list_info)
            sys.exit(0)
    file.close()

def fun_timer():
    print("entry fun_timer")
    fun_serch_keyword(impl_runme_log_path)
    global timer
    timer = threading.Timer(60, fun_timer)
    timer.start()

list_info = []
dlg = win32ui.CreateFileDialog(1) 
dlg.SetOFNInitialDir('')          
dlg.DoModal()
impl_runme_log_path = dlg.GetPathName()
print(impl_runme_log_path)
timer = threading.Timer(1, fun_timer)
timer.start()

Program logic:

  1. Open the file dialog box and select the path of the runme.log file.
  2. Nested instantiated 60s timers to complete keyword search of runme.log file every 60s.
  3. Save the information containing "Starting|Ending|Exiting".
  4. If there is information about the "Exiting" keyword, send an email.
  5. Send the keyword information to the receiving mailbox.

Change the email information to your own. Environmental Science:

  • Python 3.8.8
  • PyQt5

2.2 use

Here are the steps to get the IMAP/SMTP authorization code from the 163 mailbox tested:

3 packaging and publishing

In order to facilitate the use of hosts without an installation environment, I wrote an interface using PyQt5 and packaged it. Because I am also Xiaobai, the program may have many bug s. At present, I have only tested it a few times. The procedure is described as follows:

  • The email authorization code is encrypted with AES algorithm. In fact, it's OK to use it without encryption. In order to learn python, I added it.
  • The parameter storage is implemented using qssettings and stored in "config.ini" under the path of the running file. If you need to enter parameters for the first run, it will be loaded automatically, and only the authorization code is encrypted.
  • Operation logic
    • First, click Select path to select the path of the current implementation
    • Click start to store the parameters, and query whether there is runme.log under the selected path. If not, create a new blank document. Because if you haven't run implementation, or didn't run at the beginning.
    • If the log file cannot be created, it indicates that it has started to run. At this time, directly start to query the keywords every 60s.
    • If exiting vivado is found, an email is sent. The contents of the email are as follows:

4 attachments

Link: https://pan.baidu.com/s/1ZRkBG-hMbQsAxd2MpetpXQ
Extraction code: open

Posted by maxat on Thu, 25 Nov 2021 18:07:16 -0800