#!/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', '')
#登录
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 定期检查Build_setting的编译情况的更多相关文章

  1. python如何调用c编译好可执行程序

    python如何调用c编译好可执行程序       以下总结出几种在Python 中调用 C/C++ 代码的方法 ------------------------------------------- ...

  2. Python 语言特性:编译+解释、动态类型语言、动态语言

    1. 解释性语言和编译性语言 1.1 定义 1.2 Python 属于编译型还是解释型? 1.3 收获 2. 动态类型语言 2.1 定义 2.2 比较 2. 动态语言(动态编程语言) 3.1 定义 3 ...

  3. python的exe反编译

    目录 python的exe反编译 方法一.使用archive_viewer.py提取pyc 方法二.使用pyinstxtractor.py提取pyc python的exe反编译 驱动人生样本为pyth ...

  4. 《python解释器源码剖析》第0章--python的架构与编译python

    本系列是以陈儒先生的<python源码剖析>为学习素材,所记录的学习内容.不同的是陈儒先生的<python源码剖析>所剖析的是python2.5,本系列对应的是python3. ...

  5. windows平台python 2.7环境编译安装zbarlight

    类似于前一篇博文,http://www.cnblogs.com/zhongtang/p/7148082.html中描述的情况. 编译zbarlight同样出现问题,简要处理步骤如下: 1.到https ...

  6. python介绍、安装及相关语法、python运维、编译与解释

    1.python介绍 Python(英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/)是一种广泛使用的解释型.高级编程.通用型编程语言,由吉多.范罗苏姆创造,第一版发布于1991年.可以视 ...

  7. Python在Linux下编译安装报错:Makefile:1141:install

    正常情况下执行:./configuremake && make install可以直接安装python,但是在在更新了乌版图后居然报错了!!!检查了一圈,发现乌版图安装了python3 ...

  8. python字典嵌套字典的情况下获取某个key的value

    最近在用python写接口的测试程序,期间用到解析字典获取某个key的value,由于多个接口返回的字典格式不是固定的并存在多层嵌套的情况.在字典的方法中也没有找到可直接达到目的的方法(也可能是我对字 ...

  9. windows下安装python的C扩展编译环境(解决“Unable to find vcvarsall.bat”)

    个人文章除注明转载外,均为个人原创或者翻译. 个人文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也尊重你的智商: 本文链接:http://www.cnblogs.com/f ...

随机推荐

  1. Environment.NewLine

    https://docs.microsoft.com/en-us/dotnet/api/system.environment.newline?view=netframework-4.7.2 https ...

  2. classloader的演进

    classloader从1.6到1.7整体分成了两个版本.重点区别就是并行类加载. 1.6版本 protected synchronized Class loadClass(String name, ...

  3. 2-14 MySQL初步认识,及CentOS6.8环境,源码方式安装MySQL

    什么是数据库: 存放数据的仓库RDBMS-->(Relational Database Management System) 关系型数据库管理系统DBMS--->(Database Man ...

  4. UVA-10806 Dijkstra, Dijkstra. (最小费用流,网络流建模)

    题目大意:给一张带权简单图,找出一条经过起点s和终点t的最小回路. 题目分析:建立网络,以s为源点,t为汇点,另每条边的容量为1,单位费用为边权值.求最小费用流,增广两次后的最小费用便是答案. 代码如 ...

  5. 原生javascript-图片滚动按需加载

    图片滚动按需加载:在某个区域的图片(自定义的范围,一般是首屏以下的区域),拉动滚动,图片出现在可视范围才开始加载,目的是减少请求,减耗宽带,提高首屏的呈现速度,让用户第一时间看到网页内容,留下美好的第 ...

  6. 331. Verify Preorder Serialization of a Binary Tree -- 判断是否为合法的先序序列

    One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...

  7. 5G RRC——为NAS层提供连接管理,消息传递等服务; 对接入网的底层协议实体提供参数配置的功能; 负责UE移动性管理相关的测量、控制等功能

    from:http://www.cnblogs.com/kkdd-2013/p/3868676.html 1 RRC协议功能 为NAS层提供连接管理,消息传递等服务: 对接入网的底层协议实体提供参数配 ...

  8. android中string.xml中%一$s、%1$d等的用法

    %n$ms:代表输出的是字符串,n代表是第几个参数,设置m的值可以在输出之前放置空格 %n$md:代表输出的是整数,n代表是第几个参数,设置m的值可以在输出之前放置空格,也可以设为0m,在输出之前放置 ...

  9. asp.net导出excel并弹出保存提示框

    asp.net导出excel并弹出保存提示框 2013-07-12 | 阅:1  转:78   |  分享  腾讯空间 人人网 开心网 新浪微博 腾讯微博 搜狐空间 推荐给朋友 举报          ...

  10. 【LeetCode 222_完全二叉树_遍历】Count Complete Tree Nodes

    解法一:递归 int countNodes(TreeNode* root) { if (root == NULL) ; TreeNode *pLeft = root->left; TreeNod ...