python的工作记录A

马上进入工作自动化:

[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()

 

python的工作记录A,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。