標籤:python開發svn_update指令碼
######## 指令碼需求 ########
運行系統:Windows
輸入:路徑 子路徑 使用者名稱 密碼
例子:python svn_update_list.py E:\svn\ data\code,data\asset,data\fight 使用者名稱 密碼
行為:依次在E:\svn\data\code、E:\svn\data\asset、E:\svn\data\fight執行svn update
成功返回成功結束碼和成功資訊、失敗返回失敗結束碼和失敗資訊
######## Script Demo ########
#!/usr/bin/env python#coding:utf-8import subprocess,os,sysparentPath = sys.argv[1] #第一個參數根目錄,如d:\datasubPath = sys.argv[2] #第二個參數子路徑,如minion1,minion2svnname = sys.argv[3] #使用者名稱svnpw = sys.argv[4] #密碼list = subPath.split(",") #第二個參數以逗號分隔for line in list: #輪詢第二個參數 path = parentPath + line #如:d:\data\ + minion1,d:\data\ + minion2, try: os.chdir(path) #切換到svn更新目錄 except Exception,e: print "###### 1 %s The path does not exist,scripts exit ######" % path print print "###### The error message is as follows ######" print e sys.exit(1) else: print "###### 1 %s switch success ######" % path #擷取錯誤輸出 mytask = subprocess.Popen(‘svn update --username %s --password %s‘ % (svnname, svnpw),shell=True,stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) #讀出錯誤資訊並賦值給stdstr變數 stdstr= mytask.stdout.read() #判斷有沒有輸出錯誤資訊 if ‘svn: E‘ in stdstr: print "###### 2 %s update fail,scripts exit ######" % path print print "###### The error message is as follows ######" print stdstr sys.exit(1) else: print "###### 2 %s update success ######" % path print "update finish";
######## Success Execution Demo ########
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/8B/7B/wKioL1hPntHBEWOfAAAn9d_Rzo8190.png-wh_500x0-wm_3-wmp_4-s_1391012307.png" title="1.png" alt="wKioL1hPntHBEWOfAAAn9d_Rzo8190.png-wh_50" />
######## Error Execution Demo1,Path Error ########
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/8B/7C/wKioL1hPqO6wO8sCAAAaPrerFjQ822.png-wh_500x0-wm_3-wmp_4-s_648392771.png" title="1.png" alt="wKioL1hPqO6wO8sCAAAaPrerFjQ822.png-wh_50" />
######## Error Execution Demo1,Password Error ########
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/8B/80/wKiom1hPqinC6fYoAAArCf5AVDM806.png-wh_500x0-wm_3-wmp_4-s_4195262125.png" title="1.png" alt="wKiom1hPqinC6fYoAAArCf5AVDM806.png-wh_50" />
######## Error Execution Demo1,Error update directory ########
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/8B/80/wKiom1hPqR3QTvrBAAAeOB1XlLQ191.png-wh_500x0-wm_3-wmp_4-s_3286494675.png" title="2.png" alt="wKiom1hPqR3QTvrBAAAeOB1XlLQ191.png-wh_50" />
本文出自 “wsyht90的部落格” 部落格,請務必保留此出處http://wsyht90.blog.51cto.com/9014030/1882309
Python開發Svn_Update指令碼