python 인 스 턴 스
#!/usr/bin/python
#coding=gbk
import re
import sys
import subprocess
import os
class Mytool:
#
def getFileContent(self,filepath):
if(os.path.exists(filepath)==False):
return -1
else:
content=''
#print filepath
f=file(filepath,'r')
try:
while True:
line=f.readline()
content=content+line
if len(line)==0:
break
finally: #print line
f.close()
#print 'line',line
return content
#
def getRexReturn(self,rex,content):
p=re.compile(rex)
iter=p.finditer(content)
for m in iter:
res=m.group()
#print res
return res
#
def getRexReturnList(self,rex,content):
res=[]
p=re.compile(rex)
iter=p.finditer(content)
for m in iter:
res.append(m.group())
#print m.group()
#print res
return res
# UM
def getWriteUM(self,content):
#p=re.compile(r'( \s([\S]+})\s)')
#p=re.compile(r'((?: \s+)(\S)+)')
p=re.compile(r'((?<= )(\S)+(?=\s))')
iter=p.finditer(content)
writerList=[]
for m in iter:
#print "m" ,m.group(1)
writerList.append(m.group(1))
print writerList
return writerList
def getWriteUMEmailList(self,content):
emailList=''
p=re.compile(r'((?<= )(\S)+(?=\s))')
emailList=p.findall(content)
print emailList
#
def getRdinfo(self,rdinfo):
rdinfocontent=''
content=self.getFileContent(rdinfo)
print content
if (content==-1):
#/wls/deployop/versions/storage/isv2_db_2.15.0_standard/dist_stg_autod_1
path=os.getcwd()
rex='(?<=storage/)(.*?)(?=_standard)'
p=re.compile(rex)
returnlist=p.findall(path)
rdinfocontent=returnlist[0].upper()
#print rdinfocontent
else:
titlerex=r'((?<=headline=)(\S)+)'
title=self.getRexReturn(titlerex,content)
rdrex=r'((?<=rdid=)(\S)+)'
rd=self.getRexReturn(rdrex,content)
testenv2rex=r'((?<=testenv2=)(\S)+)'
testenv2=self.getRexReturn(testenv2rex,content)
developerrex=r'((?<=developer=)(\S)+)'
developer=self.getRexReturn(developerrex,content)
rddaterex=r'((?<=rddate=)(\S)+)'
rddate=self.getRexReturn(rddaterex,content)
prd_planbegindaterex=r'((?<=prd_planbegindate=)(\S)+)'
prd_planbegindate=self.getRexReturn(prd_planbegindaterex,content)
pwdpath=os.getcwd()
rdinfocontent="=========== beigin==================================
"
rdinfocontent=rdinfocontent+rd+' '+title+'
'+' '+testenv2+'
'+' :'+developer+'
'
rdinfocontent=rdinfocontent+' :'+rddate+'
'+' :'+prd_planbegindate+'
'+pwdpath
rdinfocontent=rdinfocontent+"
========== end======================================="
return rdinfocontent
def sendmail(self,sender,receiver,subject,message):
'''
dsendmail --help
Usage: dsendmail -s SUBJECT {-m MESSAGE|-f FILE} --to RECIPCIENTS [OPTION]...
-s, --subject
-m, --message
-f, --file
--to , ,
--cc
--bcc
-a, --attach ,
-c, --content-type text/html text/plain,
--from ,
--smtp smtp ,
--help
'''
cmdargs='/wls/deploysys/tools/dsendmail '
cmdargs=cmdargs+' -s ' +'"'+subject+'"' +' -m '+'"'+ message +'"'+ ' --from ' +'" '+ sender +' "'+ ' --to '+'" '+receiver+' "'
print cmdargs
cmdargs=cmdargs+' -a '+' -c '+ 'text/plain'
print cmdargs
p=subprocess.call(cmdargs,shell=True)
if(p==0):
print 'sendmail success'
else:
print 'sendmail fail'
def getDcheckContent(self):
cmdargs='deploytool dcheck'
dcheckContent=' ,
'
dcheckContent+=subprocess.Popen(cmdargs,shell=True,stdout=subprocess.PIPE).communicate()[0]
#print dcheckContent
#dcheckContent=subprocess.call(cmdargs,shell=True)
where=dcheckContent.find('log ')
dcheckContent=dcheckContent[where+12:]
dcheckContent+="
"
dcheckContent=dcheckContent.replace('[1m','')
dcheckContent=dcheckContent.replace('[0m','')
dcheckContent=dcheckContent.replace('[32m','')
dcheckContent=dcheckContent.replace('[31m','')
dcheckContent=dcheckContent.replace('[33m','')
dcheckContent=dcheckContent.replace('[ ','')
dcheckContent=dcheckContent.replace('>>','')
return dcheckContent
#dcheck
def getErrorSqlLog(self):
#s=self.getFileContent('ccc.txt')
s=self.getDcheckContent()
errorlogContent=''
str1='.sql'
str1sqlList =[]
if(str1 in s):
#1: ./dml/gbs/sr_pa02461797_74_gbspkg_dml_guozhengmin961_gbs.sql
str1rex=r'([\S]+sql)'
str1sqlList=self.getRexReturnList(str1rex,s)
#print str1
str2='.run'
str2sqlList=[]
if(str2 in s):
str2rex=r'([\S]+run)'
str2sqlList=self.getRexReturnList(str2rex,s)
#print str2 +':'
#print str2sqlList
str2Alllogcontent=''
for f in str2sqlList:
logcontent='==========================================================
'
logcontent=logcontent+f+'
'
logcontent=logcontent+'==========================================================
'
logcontent=logcontent+self.getFileContent(f)
str2Alllogcontent=str2Alllogcontent+" :
"+logcontent
#print str2Alllogcontent
errorlogContent=errorlogContent+str2Alllogcontent
str3='.fail'
str3sqlList=[]
if (str3 in s):
str3rex=r'([\S]+fail)'
str3sqlList=self.getRexReturnList(str3rex,s)
#print str3+':'
str3Alllogcontent=''
#print str3sqlList
for f in str3sqlList:
logcontent='==========================================================
'
logcontent=logcontent+f+'
'
logcontent=logcontent+'==========================================================
'
logcontent=logcontent+self.getFileContent(f)
str3Alllogcontent=str3Alllogcontent+logcontent
#print str3Alllogcontent
errorlogContent=errorlogContent+" :
"+str3Alllogcontent
str4='.suc'
str4sqlList=[]
if (str4 in s):
str4rex=r'([\S]+suc)'
str4sqlList=self.getRexReturnList(str4rex,s)
#print str4+':'
str4Alllogcontent=''
for f in str4sqlList:
logcontent='==========================================================
'
logcontent=logcontent+f+'
'
logcontent=logcontent+'==========================================================
'
logcontent=logcontent+self.getFileContent(f)
str4Alllogcontent=str4Alllogcontent+" :
"+logcontent
errorlogContent+=str4Alllogcontent
#print errorlogContent
return errorlogContent
mytool=Mytool()
print mytool.getFileContent('rdinfos');
#rdinfos=mytool.getRdinfo('rdInfo.txt')
dcheckContent=mytool.getDcheckContent()
ErrorSqlLog=mytool.getErrorSqlLog()
#msg=rdinfos+'
'+ErrorSqlLog
#content=mytool.getFileContent("egis.html")
#titlerex=r'((?<=headline=)(\S)+)'
#print writer.getRexReturn(titlerex,'headline= 1 -- EIM-RSTP-DB1.0.0')
#print "content:",content
#print mytool.getWriteUM(content)
rdinfos=mytool.getRdinfo('rdInfo.txt')
print rdinfos
msg="'"+rdinfos+"
"+dcheckContent+ErrorSqlLog+"'"
mytool.sendmail('***@163.com',***@163.com','sendmail test',msg)
#print mytool.getDcheckContent()
#print msg
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.