Python 定期检查Build_setting的编译情况
Python 编译 情况 build setting
2023-09-27 14:21:53 时间
#!/usr/bin/python #_*_ coding:utf-8 _*_ import time from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email import Utils, Encoders from email.header import Header import mimetypes import sys import smtplib import getopt import os import re import shutil import time, datetime ''' 脚本功能: (1)检查所有的builting_setting.h是否能够编译通过,并将编译结果写入 buildLog文件中。 (2)将编译结果通过邮箱发送给负责人。 (3)系统定期执行任务,检查build_setting。 注意:SRC的绝对路径更新:gPathSrc ''' gPathSrc = u"/home/kk/share/bak/512_new/code" gPathBuildList = gPathSrc + u"/kitking/buildList.h" gPathBuildLog = gPathSrc + u"/kitking/buildLog.h" def SearchbinFile(curBuildName): global gPathSrc binFilepath = gPathSrc + "/mergedir" IsFindfile = 0 for filename in os.listdir(binFilepath): if (re.search(".*RR.*\.bin.*",filename)): IsFindfile = 1 break else: IsFindfile = 0 if IsFindfile == 0: if (os.path.isfile(gPathBuildList)): open(gPathBuildLog, "a").writelines(curBuildName) else: open(gPathBuildLog, "w").writelines(curBuildName) def Compile(): buildList = [] strCurBuildName = "" #查看清单文件 if(os.path.isfile(gPathBuildList)): buildList = open(gPathBuildList, "r").readlines() #无清单任务,需要重新产生 if(len(buildList) == 0): for dirPath, dirNames, fileNames in os.walk(gPathSrc + "/../BUILD_RECORD"): for strCurBuildName in dirNames: buildList.append(strCurBuildName+"\n") #每次移除一个任务后,更新清单文件 if(len(buildList)): strCurBuildName = buildList.pop() open(gPathSrc + "/../BUILD_RECORD/BUILD_NOW.h", "w").write("#define BUILD_NAME " + strCurBuildName) os.system(gPathSrc + "/build_history.sh") SearchbinFile(strCurBuildName) if (len(buildList)): open(gPathBuildList, "w").writelines(buildList) else: # 注意:附件的路径字符串应为unicode编码 # 发送者邮箱 接收者邮箱 邮箱密码 主题 内容 附件名 SendMail('rad_xxx@163.com', 'xxx@163.com', 'xxx','编译结果','请查看Log!',gPathBuildLog) os.remove(gPathBuildLog) os.remove(gPathBuildList) def SendMail(fromAddress, toAddress, usepassword,subject=None, content=None, attfile=None, \ subtype='plain', charset='utf-8'): username = fromAddress #创建一个带附件的实例 msg = MIMEMultipart() msg['From'] = fromAddress msg['To'] = toAddress if subject: #标题 msg['Subject'] = subject msg['Date'] = Utils.formatdate(localtime=1) if content: #添加邮件内容 txt = MIMEText(content, subtype, charset) msg.attach(txt) if attfile: #构造附件 #注意:传入的参数attfile为unicode,否则带中文的目录或名称的文件读不出来 # basename 为文件名称,由于传入的参数attfile为unicode编码,此处的basename也为unicode编码 basename = os.path.basename(attfile) #print basename #注意:指定att的编码方式为gb2312 att = MIMEText(open(attfile, 'rb').read(), 'base64', 'gb2312') att["Content-Type"] = 'application/octet-stream' #注意:此处basename要转换为gb2312编码,否则中文会有乱码。 # 特别,此处的basename为unicode编码,所以可以用basename.encode('gb2312') # 如果basename为utf-8编码,要用basename.decode('utf-8').encode('gb2312') att["Content-Disposition"] = 'attachment; filename=%s' % basename.encode('gb2312') msg.attach(att) try: #smtp = smtplib smtp = smtplib.SMTP() #连接服务器 smtp.connect('smtp.163.com', '25') #登录 smtp.login(username, usepassword) #发送邮件 smtp.sendmail(fromAddress, toAddress, msg.as_string()) #退出 smtp.quit() print('邮件发送成功email has send out !') except Exception as e: print str(e) if __name__ == "__main__": #获取脚本所在的绝对路径 AbsolutePath = sys.path[0] #切换目录进行编译 os.chdir(gPathSrc) #编译 Compile() #sys.exit(1)
相关文章
- python并发编程之threading线程(一)
- 编程语言理解1-c语言,c++,java和python这些语言有何区别?编译型编程语言编译语言,解释型编程语言解释型语言
- 机器学习-kmeans(实现步骤、sklearn实现、python自实现、优缺点)
- Python 基础
- python flask学习(1)与Git基础操作
- 【Python】【微信】itchat库
- 广度优先遍历-python
- 《易学Python》—— 1.2 是什么让Python如此杰出
- 基于Python(Django)+MySQL实现(Web)大学生信用评价系统分析与设计【100010400】
- 《Python语言程序设计》——1.8 程序设计错误
- 初识Python(注释、代码缩进、编码规范、标识符、变量)
- 为python编译C++模块时一定要注意的事情—————不要在anaconda环境下使用cmake来编译C++扩展模块!!!
- Python+Django+SAE系列教程10-----Django模板
- python:python2与python3共存时,pip冲突,提示Fatal error in launcher: Unable to create process using '"d:python27python2.exe" "D:Python27Scriptspip2.exe" '
- 使用python将MNIST数据转换为图片