标签:style class blog code tar color
马上进入工作自动化:
[root@localhost ~]# cat svn_bbs.py import os,sys,commands,subprocess import re,time svnUrl = "svn://xxx" svnExportCmdPre = "svn export svn://xxx/" sitePath = "/xxx" updateFolder = "/srv/salt/xxx/" saltMinion = "xxx" saltCpCmdPre = "salt ‘" + saltMinion + "‘ cmd.run " + "‘ cp " saltChownCmdPre = "salt ‘" + saltMinion + "‘ cmd.run " + "‘chown nginx:nginx " saltChmodCmdPre = "salt ‘" + saltMinion + "‘ cmd.run " + "‘chmod 664 " saltGetFilePre = "salt ‘" + saltMinion + "‘ cp.get_file salt://xxx/" localFileList = [] remoteFileList = [] def getSvnFile(rVersion): svnLogCmd ="svn log -v -r" + rVersion +" " + svnUrl svnLogOut = subprocess.Popen(svnLogCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in svnLogOut.stdout.readlines(): if len(line.strip())!=0 and line.startswith(" "): fileName = line.split()[1] fileNameS = fileName.split(‘/‘)[-1] filePath = sitePath + fileName localFileList.append(fileNameS) remoteFileList.append(filePath) svnExportCmd = svnExportCmdPre + fileName + " " + updateFolder + fileNameS subprocess.Popen(svnExportCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) def backupFile(bFileName): cpCmd = saltCpCmdPre + bFileName + " " + bFileName +".old‘" subprocess.Popen(cpCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) saltChownCmd = saltChownCmdPre + bFileName + ".old‘" subprocess.Popen(saltChownCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) saltChmodCmd = saltChmodCmdPre + bFileName + ".old‘" subprocess.Popen(saltChmodCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) def updateFile(localFile, remoteFile): saltCpCmd = saltGetFilePre + localFile + " " + remoteFile + " makedirs=True" #print saltCpCmd subprocess.Popen(saltCpCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) saltChownCmd = saltChownCmdPre + remoteFile + "‘" subprocess.Popen(saltChownCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) saltChmodCmd = saltChmodCmdPre + remoteFile + "‘" subprocess.Popen(saltChmodCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) def main(): getSvnFile(rVersion) print localFileList for file in remoteFileList: backupFile(file) #updateFile(uF, rF) for local,remote in zip(localFileList,remoteFileList): print local,remote if __name__=="__main__": rVersion = sys.argv[1] main()
标签:style class blog code tar color
原文地址:http://www.cnblogs.com/aguncn/p/3809233.html