######## Script Requirements ########
Operating system: Windows
Input: path Sub-path user name password
Example: python svn_update_list.py E:\svn\ data\code,data\asset,data\fight username password
Behavior: perform svn update in E:\svn\data\code, E:\svn\data\asset, and E:\svn\data\fight sequentially
Successful end code and success information, failure return failure end code, and failure information are successfully returned
######## Script Demo ########
#!/usr/bin/env python#coding:utf-8import subprocess,os,sysparentpath = sys.argv[1] #第一个参数根目录, such as d:\datasubpath = sys.argv[2] #第二个参数子路径, e.g. 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 "/>
This article is from the "wsyht90 blog" blog, make sure to keep this source http://wsyht90.blog.51cto.com/9014030/1882309
Python Development svn_update Script