#!/usr/bin/python#_*_ coding:utf-8 _*_Import Time fromEmail. MimetextImportMimetext fromEmail. MimemultipartImportMimemultipart fromEmail. MimebaseImportMimebase fromEmailImportUtils, Encoders fromEmail.headerImportHeaderImportmimetypesImportSYSImportSmtplibImportgetoptImportOSImportReImportShutilImportTime , DateTime" "Scripting Features: (1) Check that all builting_setting.h are able to compile and write the results to the Buildlog file. (2) Send the results of the compilation to the responsible person through the mailbox. (3) The system performs regular tasks to check the build_setting. Note: The absolute path update for SRC: gpathsrc" "gpathsrc= u"/home/kk/share/bak/512_new/code"gpathbuildlist= gpathsrc + u"/kitking/buildlist.h"Gpathbuildlog= gpathsrc + u"/kitking/buildlog.h"defSearchbinfile (curbuildname):Globalgpathsrc Binfilepath= Gpathsrc +"/mergedir"Isfindfile=0 forFileNameinchOs.listdir (binfilepath):if(Re.search (". *rr.*\.bin.*", filename)): Isfindfile= 1 Break Else: Isfindfile=0ifIsfindfile = =0:if(Os.path.isfile (gpathbuildlist)): Open (Gpathbuildlog,"a"). Writelines (Curbuildname)Else: Open (Gpathbuildlog,"W"). Writelines (Curbuildname)defCompile (): BuildList=[] Strcurbuildname="" #View the manifest file if(Os.path.isfile (gpathbuildlist)): BuildList= Open (Gpathbuildlist,"R"). ReadLines ()#No inventory tasks, need to be re-generated if(len (buildList) = =0): forDirpath, Dirnames, FileNamesinchOs.walk (GPATHSRC +"/.. /build_record"): forStrcurbuildnameinchDirNames:buildList.append (Strcurbuildname+"\ n") #update the manifest file after each removal of a task 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: #Note: The path string for the attachment should be Unicode encoded #Sender mailbox recipient mailbox Mailbox password subject content attachment nameSendMail ('[email protected]','[email protected]','XXX','Compile Results','please view log! ', Gpathbuildlog) os.remove (gpathbuildlog) os.remove (gpathbuildlist)defSendMail (fromaddress, toaddress, Usepassword,subject=none, Content=none, attfile=None, subtype='Plain', charset='Utf-8'): Username=fromaddress#create an instance with an attachmentmsg =Mimemultipart () msg[' from'] =fromaddress msg[' to'] =toaddressifSubject:#titlemsg['Subject'] =subject msg['Date'] = Utils.formatdate (localtime=1) ifcontent:#Add message ContentTXT =Mimetext (content, subtype, CharSet) Msg.attach (TXT)ifAttfile:#Construction Attachments #Note: The passed in Parameter attfile is Unicode, otherwise a file with a Chinese directory or name cannot be read #basename is a file name, because the passed-in parameter attfile is Unicode encoded, the basename here is also Unicode encodedbasename =os.path.basename (attfile)#Print basename #Note: The specified ATT is encoded as gb2312ATT = mimetext (open (Attfile,'RB'). Read (),'Base64','gb2312') att["Content-type"] ='Application/octet-stream' #Note: Here basename to convert to gb2312 encoding, otherwise Chinese will be garbled. #specifically, the basename here is Unicode encoded, so you can use Basename.encode (' gb2312 ') #If basename is utf-8 encoded, use Basename.decode (' Utf-8 '). Encode (' gb2312 ')att["content-disposition"] ='attachment; filename=%s'% Basename.encode ('gb2312') Msg.attach (ATT)Try: #SMTP = SmtplibSMTP =Smtplib. SMTP ()#connecting to a serverSmtp.connect ('smtp.163.com',' -') #LoginSmtp.login (username, Usepassword)#Send mailSmtp.sendmail (fromaddress, Toaddress, msg.as_string ())#Exitsmtp.quit ()Print('Mail sent successfully email has send out!') exceptException as E:PrintStr (e)if __name__=="__main__": #get the absolute path where the script is locatedAbsolutepath =Sys.path[0]#Switch directories for compilationOs.chdir (GPATHSRC)#compilingCompile ()#sys.exit (1)
Python periodically checks the compilation of build_setting