Exemple #1
0
    def email_init(self, report, reportName):
        '''邮件发送'''
        with open(report, 'rb') as f:
            mail_body = f.read()
        # 创建一个带附件的邮件实例
        msg = MIMEMultipart()
        #msg.attach(MIMEApplication(""))        #设置发送的正文
        report_file = MIMEApplication(mail_body)
        # 定义附件名称(附件的名称可以随便定义,你写的是什么邮件里面显示的就是什么)
        report_file.add_header('Content-Disposition',
                               'attachment',
                               filename=reportName)
        msg.attach(report_file)  # 添加附件
        msg['Subject'] = '自动化测试报告: ' + reportName  # 邮件标题
        msg['From'] = self.addresser  #发件人
        msg['To'] = ",".join(self.addressee)  #收件人列表
        try:
            server = smtplib.SMTP(self.smtp)
            server.login(self.user, self.passwd)
            server.sendmail(self.addresser, self.addressee, msg.as_string())
            server.quit()
            logger.info("----邮件发送成功----")

        except smtplib.SMTPException as e:
            logger.error("邮件发送失败{}".format(e))
def os_remove(filename):
    '''os系统命令,删除文件操作方法'''
    if os.path.exists(filename):
        os.remove(filename)
        logger.info(filename + "删除成功")
    else:
        logger.error("失败,{}文件不存在".format(filename))
def get_token(phone):
    for i in range(10):
        try:
            url = "http://192.168.203.151:13600/SC/v21/family/auth/token?mobile={}".format(
                phone)
            res = requests.get(url=url)
            res1 = json.loads(res.text)["body"]["data"]
            break
        except Exception as e:
            logger.error('token获取失败:%s' % phone)
            continue
    return res1
 def del_file(self, file_path, num):
     '''删除文件操作'''
     try:
         while True:
             dir = os.listdir(file_path)
             dir.sort(
                 key=lambda fn: os.path.getmtime(file_path + '\\' + fn))
             if len(dir) > int(num):
                 filepath = os.path.join(file_path, dir[0])
                 os.remove(filepath)
                 logger.info("删除成功,文件目录:{}".format(filepath))
                 continue
             else:
                 break
     except Exception as e:
         logger.error('删除文件失败{}'.format(e))