def sendCloseMail(content, repo, receivers, CloseDay): mail = Mail() mail.set_sender('*****@*****.**') mail.set_receivers(receivers) mail.set_title('%s repo关闭超过%s天未更新的issue/pr通知' % (repo, CloseDay)) mail.set_message(content, messageType='html', encoding='gb2312') mail.send()
def mail(HTML_CONTENT): mail = Mail() mail.set_sender('*****@*****.**') mail.set_receivers(['*****@*****.**']) mail.set_title("【告警】效率云过去4小时/过去1天CI指标") mail.set_message(HTML_CONTENT, messageType='html', encoding='gb2312') mail.send()
def sendMonitorMail(content): mail = Mail() mail.set_sender('*****@*****.**') mail.set_receivers(['*****@*****.**']) mail.set_title('gitClone时间超过10min!') mail.set_message(content, messageType='html', encoding='gb2312') mail.send()
def mails(self): self.mail_content = StringIO() self.mail_content.write("*This is an automatically generated email. Do not reply.*\n\n\n") self.is_need_mail = False if not self.is_all_7zfiles_exist: self.is_need_mail = True self.mail_content.write("**************************Missing 7z files**************************\n") self.mail_content.writelines(self.mail_content_7zfiles.getvalue()) self.mail_content.write("\n\n") if not self.is_all_scs_configed: self.is_need_mail = True self.mail_content.write("**************************Scs not configed**************************\n") self.mail_content.write(self.mail_content_scs) self.mail_content.write("\n\n") if not self.is_recovered_bitbake: self.is_need_mail = True self.mail_content.write("**************************Recover bitbake**************************\n") self.mail_content.writelines(self.mail_content_recover.getvalue()) self.mail_content.write("\n\n") elif not self.is_bitbake_content_fine: self.is_need_mail = True self.mail_content.write("**************************Recover bitbake**************************\n") self.mail_content.writelines(self.mail_content_recover.getvalue()) self.mail_content.write("\n\n") if self.is_need_mail: mail = Mail(self.config.get("mail_from"), self.config.get("mail_to")) mail.create(self.config.get("mail_subject"), self.mail_content.getvalue()) mail.send()
def sendCloseMail(content): mail = Mail() mail.set_sender('*****@*****.**') mail.set_receivers(['*****@*****.**']) mail.set_title('关闭超过1年未更新的issue/pr通知~') mail.set_message(content, messageType='html', encoding='gb2312') mail.send()
def sendMail(self, mailContent): HTML_CONTENT = "<html><body><p>Hi, ALL:</p>" HTML_CONTENT += mailContent HTML_CONTENT += "<p>如有问题,请联系张春乐.</p> <p>张春乐</p></body></html>" mail = Mail() mail.set_sender('*****@*****.**') mail.set_receivers(['*****@*****.**']) mail.set_title('[告警]自动取消超时任务') mail.set_message(HTML_CONTENT, messageType='html', encoding='gb2312') mail.send()
def sendMail(self, mailContent): """ this function will send alarm mail. """ mail = Mail() mail.set_sender('*****@*****.**') mail.set_receivers(['*****@*****.**']) mail.set_title('[告警]任务等待超时') mail.set_message(mailContent, messageType='html', encoding='gb2312') mail.send()
def run(self): _message = render_to_string('mail/gk3_announce.html') _mail = Mail(u"果库 3.0 隆重上线!", _message) count = 0 for _obj in Email_List.objects.filter(done=False): try: _mail.send(address=_obj.email) _obj.done = True _obj.save() logger.info("[edm][info] %s sent success.", _obj.email) except Exception, e: logger.error("[edm][error] %s", e) count += 1 if count >= 1000: break
def retrieve_password(self): self.__ensure_user_obj() self.__ensure_user_profile_obj() _token = self.__create_one_time_token('reset_password') _url = 'http://www.guoku.com/reset_password/?token=' + _token _message = render_to_string( 'mail/forget_password.html', { 'url' : _url, 'nickname' : self.user_profile_obj.nickname } ) _mail = Mail(u"重设果库帐号密码", _message) print self.user_obj.email _mail.send( address = self.user_obj.email )
def save(self, *args, **kwargs): if not self.name_cn: try: youdao = requests.get(''.join( [settings.YOUDAO_BASEURL, self.name_en])).json() name_cn = youdao.get('translation', [])[0] if any(u'\u4e00' <= char <= u'\u9fff' for char in name_cn): self.name_cn = name_cn else: raise RuntimeError('Cannot translate %s to chinese!' % self.name_en) except: Mail.send(['*****@*****.**', '*****@*****.**'], 'Failure Overseas City Translation', 'Youdao cannot translation %s.' % self.name_en) # need add method for country map # if not self.country_cn: super(City, self).save(*args, **kwargs)
def sendMail(ciIndex_thisWeek, ciIndex_lastWeek=0): thisWeekCommit = ciIndex_thisWeek['commitCount'] lastWeekCommit = ciIndex_lastWeek[ 'commitCount'] if ciIndex_lastWeek != 0 else 0 COMMIT_AND_TIME = "<table border='1' align=center> <caption><font size='3'><b>用户感知指标</b></font></caption>" if ciIndex_lastWeek == 0: DIFF_RATE = "%.2f" % float((thisWeekCommit - 0.00001) / 0.00001 * 100) else: DIFF_RATE = "%.2f" % float( abs(thisWeekCommit - lastWeekCommit) / lastWeekCommit * 100) if thisWeekCommit - lastWeekCommit > 0: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>commit数</td><td bgcolor='#ff6eb4'>%s(↑ %s" % ( thisWeekCommit, DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" else: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>commit数</td><td bgcolor='#b5c4b1'>%s(↓ %s" % ( thisWeekCommit, DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" MAX_WAITTIME = max( float(ciIndex_thisWeek['PR-CI-Coverage_average_wait_time']), float(ciIndex_thisWeek['PR-CI-Py35_average_wait_time']), float(ciIndex_thisWeek['PR-CI-Inference_average_wait_time']), float(ciIndex_thisWeek['PR-CI-CPU-Py2_average_wait_time'])) MAX_EXECTIME = max( float(ciIndex_thisWeek['PR-CI-Coverage_average_exec_time']), float(ciIndex_thisWeek['PR-CI-Py35_average_exec_time']), float(ciIndex_thisWeek['PR-CI-Inference_average_exec_time']), float(ciIndex_thisWeek['PR-CI-CPU-Py2_average_exec_time'])) COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>commit从提交到返回结果耗时</td><td>%.2f min</td></tr>" % ( MAX_WAITTIME + MAX_EXECTIME) COMMIT_AND_TIME += "</table>" HTML_CONTENT = "<html><body><p>Hi, ALL:</p> <p>本周CI评价指标详细信息可参考如下表格:</p> %s" % COMMIT_AND_TIME HTML_TABLE_CONTENT = write_excel_xls(ciIndex_thisWeek, ciIndex_lastWeek) HTML_CONTENT = HTML_CONTENT + "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td</tr></table>" + HTML_TABLE_CONTENT + "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td</tr></table>" + "<p>如有问题,随时联系</p> <p>张春乐</p></body></html>" mail = Mail() mail.set_sender('*****@*****.**') mail.set_receivers(['*****@*****.**']) mail.set_title( '效率云%s~%s CI评价指标统计' % (ciIndex_thisWeek['startTime'], ciIndex_thisWeek['endTime'])) mail.set_message(HTML_CONTENT, messageType='html', encoding='gb2312') mail.send()
def sendMail(ciIndex_thisWeek, ciIndex_lastWeek=0): COMMIT_AND_TIME = "<table border='1' align=center> <caption><font size='3'><b>用户感知指标</b></font></caption>" repo_list = localConfig.cf.get('ciIndex', 'commitCount').split(',') #用户感知指标: 各个repo的commit的数目 for repo in repo_list: key = '%s_commitCount' % repo.split('/')[1] thisWeekCommit = ciIndex_thisWeek[key] lastWeekCommit = ciIndex_lastWeek[key] if ciIndex_lastWeek != 0 else 0 if ciIndex_lastWeek == 0: DIFF_RATE = "%.2f" % float( (thisWeekCommit - 0.00001) / 0.00001 * 100) else: DIFF_RATE = "%.2f" % float( abs(thisWeekCommit - lastWeekCommit) / lastWeekCommit * 100) if thisWeekCommit - lastWeekCommit > 0: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>%s commit数/个</td><td bgcolor='#ff6eb4'>%s(↑ %s" % ( repo.split('/')[1], thisWeekCommit, DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" else: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>%s commit数/个</td><td bgcolor='#b5c4b1'>%s(↓ %s" % ( repo.split('/')[1], thisWeekCommit, DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" #用户感知指标: commit从提交到返回结果平均耗时 thisweek_MAX_CONSUMTIME = 0 CI_NAME_list = localConfig.cf.get('ciIndex', 'ci_name').split(',') #所有的ci for ci in CI_NAME_list: if float(ciIndex_thisWeek['%s_average_consum_time' % ci]) > thisweek_MAX_CONSUMTIME: thisweek_MAX_CONSUMTIME = float( ciIndex_thisWeek['%s_average_consum_time' % ci]) max_CONSUMTIME_CI = ci lastweek_MAX_CONSUMTIME = float(ciIndex_lastWeek['%s_average_consum_time' % max_CONSUMTIME_CI]) consum_DIFF_RATE = "%.2f" % float( abs(thisweek_MAX_CONSUMTIME - lastweek_MAX_CONSUMTIME) / lastweek_MAX_CONSUMTIME * 100) if thisweek_MAX_CONSUMTIME - lastweek_MAX_CONSUMTIME > 0: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>commit从提交到返回结果平均耗时/min</td><td bgcolor='#ff6eb4'>%s(↑ %s" % ( thisweek_MAX_CONSUMTIME, consum_DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" else: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>commit从提交到返回结果平均耗时/min</td><td bgcolor='#b5c4b1'>%s(↓ %s" % ( thisweek_MAX_CONSUMTIME, consum_DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" #用户感知指标: commit从提交到返回结果最长耗时 thisweek_Longest_Time = float(ciIndex_thisWeek['LongestTime']) lastweek_Longest_Time = float(ciIndex_lastWeek['LongestTime']) longestTime_DIFF_RATE = "%.2f" % float( abs(thisweek_Longest_Time - lastweek_Longest_Time) / lastweek_Longest_Time * 100) if thisweek_Longest_Time - lastweek_Longest_Time > 0: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>commit从提交到返回结果最长耗时/min</td><td bgcolor='#ff6eb4'>%s(↑ %s" % ( thisweek_Longest_Time, longestTime_DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" else: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>commit从提交到返回结果最长耗时/min</td><td bgcolor='#b5c4b1'>%s(↓ %s" % ( thisweek_Longest_Time, longestTime_DIFF_RATE) COMMIT_AND_TIME += "%)</td></tr>" #用户感知指标: 单测随机挂引起的RERUN占比 thisWeek_rerun_index = testRerun( '%s 00:00:00' % ciIndex_thisWeek['startTime'], '%s 00:00:00' % ciIndex_thisWeek['endTime']) lastWeek_rerun_index = testRerun( '%s 00:00:00' % ciIndex_lastWeek['startTime'], '%s 00:00:00' % ciIndex_lastWeek['endTime']) rerun_DIFF_RATE = "%.2f" % float( abs( float(thisWeek_rerun_index['all_testfailed_rerunRatio']) - float(lastWeek_rerun_index['all_testfailed_rerunRatio']))) if float(thisWeek_rerun_index['all_testfailed_rerunRatio']) - float( lastWeek_rerun_index['all_testfailed_rerunRatio']) > 0: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>单测随机挂引起的RERUN占比</td>" RERUN_INDEX_DIFF = "<td bgcolor='#ff6eb4'>%s" % thisWeek_rerun_index[ 'all_testfailed_rerunRatio'] + "%(↑ " + "%s" % rerun_DIFF_RATE + "%)</td>" else: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>单测随机挂引起的RERUN占比</td>" RERUN_INDEX_DIFF = "<td bgcolor='#b5c4b1'>%s" % thisWeek_rerun_index[ 'all_testfailed_rerunRatio'] + "%(↓ " + "%s" % rerun_DIFF_RATE + "%)</td>" COMMIT_AND_TIME += RERUN_INDEX_DIFF COMMIT_AND_TIME += "</tr>" #用户感知指标: 平均失败率最大的CI及大小 thisweek_MAX_FAILEDRATE = 0 for ci in CI_NAME_list: if float(ciIndex_thisWeek['%s_failRate' % ci]) > thisweek_MAX_FAILEDRATE: thisweek_MAX_FAILEDRATE = float(ciIndex_thisWeek['%s_failRate' % ci]) max_FAILEDRATE_CI = ci lastweek_MAX_FAILEDRATE = float(ciIndex_lastWeek['%s_failRate' % max_FAILEDRATE_CI]) failed_DIFF_RATE = "%.2f" % float( abs(float(thisweek_MAX_FAILEDRATE) - float(lastweek_MAX_FAILEDRATE)) * 100) if float(thisweek_MAX_FAILEDRATE) - float(lastweek_MAX_FAILEDRATE) > 0: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>平均失败率最大的CI及大小</td>" FAILED_INDEX_DIFF = "<td bgcolor='#ff6eb4'>%s: %.2f" % ( max_FAILEDRATE_CI, thisweek_MAX_FAILEDRATE * 100) + "%(↑ " + "%s" % failed_DIFF_RATE + "%)</td>" else: COMMIT_AND_TIME += "<tr align=center><td bgcolor='#d0d0d0'>平均失败率最大的CI及大小</td>" FAILED_INDEX_DIFF = "<td bgcolor='#b5c4b1'>%s: %.2f" % ( max_FAILEDRATE_CI, thisweek_MAX_FAILEDRATE * 100) + "%(↓ " + "%s" % failed_DIFF_RATE + "%)</td>" COMMIT_AND_TIME += FAILED_INDEX_DIFF COMMIT_AND_TIME += "</tr></table>" #效率云CI由于单测随机挂RERUN占比 thisWeek_RERUN_TABLE = "<table border='1' align=center> <caption><font size='3'><b>效率云CI由于单测随机挂RERUN占比</b></font></caption>" thisWeek_RERUN_TABLE += "<tr align=center><td bgcolor='#d0d0d0'>CI名称</td><td>整体</td><td>PR-CI-Coverage</td><td> PR-CI-Py3</td><td>PR-CI-Mac</td><td>PR-CI-Mac-Python3</td><td>PR-CI-Windows</td>" thisWeek_RERUN_TABLE += "</tr><tr align=center><td bgcolor='#d0d0d0'>单测随机挂引起的Rerun</td><td>%s" % thisWeek_rerun_index[ 'all_testfailed_rerunRatio'] thisWeek_RERUN_TABLE += "%</td>" rerun_ci_by_utfail_list = localConfig.cf.get( 'ciIndex', 'rerun_ci_by_utfail').split(',') for ci in rerun_ci_by_utfail_list: thisWeek_RERUN_TABLE += "<td>{}%</td>".format( thisWeek_rerun_index['%s_testfailed_rerunRatio' % ci]) thisWeek_RERUN_TABLE += "</tr></table>" #失败原因占比 EXCODE_TABLE = excode('%s 00:00:00' % ciIndex_thisWeek['startTime'], '%s 00:00:00' % ciIndex_thisWeek['endTime']) #对内关键指标与对内详细指标 KEY_CI_INDEX_TABLE, DETAIL_CI_INDEX_TABLE = get_key_detail_ci_index( ciIndex_thisWeek, ciIndex_lastWeek) #汇总表格 HTML_CONTENT = "<html><body><p>Hi, ALL:</p> <p>本周(%s 00:00:00 ~ %s 00:00:00)CI评价指标详细信息可参考如下表格:</p> <p>CI评价指标的计算方式可见: http://agroup.baidu.com/paddle-ci/md/article/3352500</p><p>现在机器资源如下: V100(coverage/py3) 17台, P4(Inference/CPU) 4台, Mac 8台, Windows 15台</p> %s" % ( ciIndex_thisWeek['startTime'], ciIndex_thisWeek['endTime'], COMMIT_AND_TIME) HTML_CONTENT = HTML_CONTENT + "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td</tr></table>" \ + KEY_CI_INDEX_TABLE + "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td</tr></table>" \ + thisWeek_RERUN_TABLE + "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td</tr></table>" \ + EXCODE_TABLE + "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td</tr></table>"\ + DETAIL_CI_INDEX_TABLE + "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td</tr></table>" \ + "<p>如有问题,请反馈到CE and CI值班群(xxx)或联系张春乐.</p> <p>张春乐</p></body></html>" mail = Mail() mail.set_sender('xxxx') mail.set_receivers(['*****@*****.**']) mail.set_title( '效率云%s~%s CI评价指标统计' % (ciIndex_thisWeek['startTime'], ciIndex_thisWeek['endTime'])) mail.set_message(HTML_CONTENT, messageType='html', encoding='gb2312') mail.send()
if start_time is None: exit(1) sql = f"SELECT * FROM RPA.CRM_DV_ERASE_VOUCHER where {condition}" df = pd.read_sql(sql, con=conn) except cx_Oracle.DatabaseError as e: print(e) # log.log_critical("There is a problem with Oracle DETAILS : EXCEPTION - {e}") location = './erased_voucher_report.xlsx' try: os.remove(location) except FileNotFoundError as e: # log.log_warn(f"No File Found to be deleted LOCATION - {location}") pass if len(df) > 0: df.to_excel(location) else: location = None mail = Mail(channel=Mail.outlook) with open('./erased_voucher_config.json') as config_file: data = json.load(config_file) targets = data['targets'] cc = data['cc'] mail_body = f'<p>Dear Concern,</p> {len(df)} number of SR has been processed between {start_time} to {end_time} <p>Thanks</p>' mail.send_mail_to(targets, cc, 'CRM RPA Report', mail_body, location) mail.send()
def main(): global proxy_client, proxy_server LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" log_filename = 'logs/test_' + time.strftime("%Y%m%d", time.localtime()) + '.log' logging.basicConfig(filename=log_filename, level=logging.INFO, format=LOG_FORMAT) # 当前脚本所在目录路径 path = os.path.dirname(os.path.realpath(__file__)) test_config = TestConfig(path) if len(sys.argv) > 1: report_name = sys.argv[1] if 'ls' == sys.argv[1]: files = getFileName(path + '/config/') print(Util.pretty(files)) return else: report_name = 'default' # 获取测试用例数据 config = test_config.get_test_case(sys.argv) # 是否开启代理 is_open_proxy = config.get('BROWSER').get('proxy') if is_open_proxy: from browsermobproxy import Server bmp_path = config.get('BROWSER').get('bmp_path') logging.info('开启代理 ' + bmp_path) proxy_server = Server(bmp_path) proxy_server.start() proxy_client = proxy_server.create_proxy() # 浏览器类型 browser_type = config.get('BROWSER').get('type') # 是否使用H5测试,并指定移动设备名称 h5 = config.get('BROWSER').get('H5', False) device_name = config.get('BROWSER').get('device_name', 'iPhone 7') # 是否开启无头模式 headless = config.get('BROWSER').get('headless', False) if browser_type == 'Firefox': options = FirefoxOptions() if headless: options.add_argument("-headless") options.page_load_strategy = 'normal' if h5: user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16" options.set_preference("general.useragent.override", user_agent) if is_open_proxy: options.add_argument('--proxy-server={0}'.format( proxy_client.proxy)) browser = webdriver.Firefox(options=options) elif browser_type == 'Chrome': options = ChromeOptions() if headless: options.add_argument("--window-size=1920,1080") # 设置浏览器分辨率(窗口大小) options.add_argument( "--start-maximized") # 最大化运行(全屏窗口),不设置,获取元素可能会报错 options.add_argument("--disable-extensions") options.add_argument('--no-sandbox') # 取消沙盒模式,浏览器的安全性会降低 # 禁用GPU加速,降低资源损耗,only for Windows but not a valid configuration for Linux OS options.add_argument('--disable-gpu') options.add_argument('--disable-dev-shm-usage') # 解决资源有限的问题 options.add_argument('--lang=en_US') options.add_argument("--headless") options.page_load_strategy = 'normal' if h5: mobileEmulation = {'deviceName': device_name} options.add_experimental_option('mobileEmulation', mobileEmulation) if is_open_proxy: options.add_argument('--proxy-server={0}'.format( proxy_client.proxy)) browser = webdriver.Chrome(options=options) else: print('浏览器' + browser_type + ':类型不支持') return False logging.info('开始使用 ' + browser_type + ' 浏览器进行自动化测试') if is_open_proxy: proxy_client.new_har("req", options={ 'captureHeaders': True, 'captureContent': True }) if browser_type == 'Firefox' and h5: browser.set_window_size(360, 640) else: browser.maximize_window() # 浏览器等待时间 # browser.implicitly_wait(10) url = config.get('WEBSITE').get('url') browser.get(url) if is_open_proxy: Http.logHar(proxy_client.har) # 执行配置的TEST对象 test = config.get('TEST') suite = unittest.TestSuite() m = Menu() for key in test: menus = m.getMenuConfig(config, key) try: if is_open_proxy: test_data = [browser, menus, proxy_client] else: test_data = [browser, menus] suite.addTest( ParametrizedTestCase.parametrize(Action, 'test_menu', param=test_data)) except AssertExcetion: print(key + " 断言失败") # 是否生成报告,默认开启调试模式,不生成报告 debug = config.get('DEBUG', True) if debug: runner = unittest.TextTestRunner() runner.run(suite) else: # 报告是否含有截图,DEBUG为False且IMAGE设置为True时生效 image = config.get('IMAGE', False) report_path = path + '/reports/' report_file = report_name + "_" + time.strftime( "%Y%m%d", time.localtime()) + '.html' fp = open(report_path + report_file, 'wb') report_title = '你的测试报告' report_desc = '使用配置:' + report_name + '生成的测试报告' runner = HTMLTestRunner(stream=fp, verbosity=2, images=image, title=report_title, description=report_desc, tester='pystest') runner.run(suite) fp.close() sleep(5) browser.quit() # send mail or not mail = config.get('MAIL') if not debug and mail and mail.get('SEND'): email_title = report_title email_content = report_desc smtp = Mail(config.get('MAIL'), report_path) smtp.connect() smtp.login() smtp.send(email_title, email_content, report_file) smtp.quit() if is_open_proxy: proxy_client.close() proxy_server.stop()