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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值