python SVN書き込み更新ログの発行
7215 ワード
SCENE = "mjdy_dyhry"
DIRS = {
"md5/scenes/" + SCENE,
"data/tex/scenes/" + SCENE,
"data/tex/share",
"data/mesh/scenes/" + SCENE,
}
import os
WORKSPACE = "D:/workspace/muData/"#os.getcwd()+
# execute command, and return the output
def execCmd(cmd):
r = os.popen(cmd)
text = r.read()
r.close()
return text
# write "data" to file-filename
def writeFile(filename, data):
f = open(filename, "w")
f.write(data)
f.close()
def svnCommit(targetDir):
cmd = "svn up \"%s\" --non-interactive -q"
logtext = execCmd(cmd% targetDir) + "
"
cmd = "svn add \"%s\" --force"
logtext += execCmd(cmd% targetDir) + "
"
cmd = "svn commit \"%s\" -m 'Auto_Commit'"
logtext += execCmd(cmd% targetDir) + "
"
return logtext
def updateAll():
logtext = ""
for key in DIRS:
logtext += svnCommit(WORKSPACE + key)
print logtext
return logtext
import re
import time
def filter(text):
vec = text.split("
")
rs = ""
for line in vec:
print line
if re.match( r'Sending*', line, re.M|re.I):
rs += line + "
"
elif re.match( r'Adding*', line, re.M|re.I):
rs += line + "
"
return rs
info = updateAll()
loginfo = filter(info)
if not os.path.exists("loghistory"):
os.mkdir("loghistory")
curtime = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".txt"
logfile = "loghistory/" + curtime
writeFile(logfile, loginfo)
if(len(loginfo) > 8):
execCmd("loghistory\\" + curtime)