码迷,mamicode.com
首页 > 编程语言 > 详细

python的工作记录A

时间:2014-06-26 14:41:11      阅读:227      评论:0      收藏:0      [点我收藏+]

标签: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()

 

python的工作记录A,布布扣,bubuko.com

python的工作记录A

标签:style   class   blog   code   tar   color   

原文地址:http://www.cnblogs.com/aguncn/p/3809233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!