######## 脚本需求 ########
运行系统: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-8 import subprocess,os,sys parentPath = sys.argv[1] #第一个参数根目录,如d:\data\ subPath = sys.argv[2] #第二个参数子路径,如minion1,minion2 svnname = 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 ########
######## Error Execution Demo1,Path Error ########
######## Error Execution Demo1,Password Error ########
######## Error Execution Demo1,Error update directory ########