十二12 发表于 2018-8-9 09:20:30

Python开发Svn_Update脚本

#!/usr/bin/env python  
#coding:utf-8
  

  
import subprocess,os,sys
  
parentPath = sys.argv      #第一个参数根目录,如d:\data\
  
subPath = sys.argv         #第二个参数子路径,如minion1,minion2
  
svnname = sys.argv         #用户名
  
svnpw = sys.argv             #密码
  
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";
页: [1]
查看完整版本: Python开发Svn_Update脚本