在對liunx操做svn的方式,作了改動,使用python的,subprocess進行操做java
在第一種方案中,我使用了先拉到本地,而後再建立,在進行上傳,實際在svn中能夠直接建立文件,並進行文件複製,具體代碼以下python
#!/usr/bin/env python # -*- coding:utf-8 -*- # CreateDate: 2018-01-17 import os import re import subprocess import locale import sys class SvnCommand(object): def __init__(self, project): self.cmd = 'http://svn.egomsl.com/svn/repos/autotest.globalegrow.com/projectScript/uitest' self.project = project # 獲取文件路徑 def checkout(self): #下載目錄 """ checkout code from SVN respoitory. :params url: svn url. :params path: target path. """ command = 'svn checkout ' + self.cmd message = 'checkout code success' subprocess.check_output(command, shell=True) return {'code': 0, 'msg': message} # 新建文件 def crate(self): # 新建svn目錄 project = self.cmd + '/' + self.project command = 'svn mkdir -m "making" ' + project print command message = 'create file success' subprocess.check_output(command, shell=True) s.copyfile(); return {'code': 0, 'msg': message} def copyfile(self): targetDir = self.cmd + '/' + self.project #要複製的文件 url = 'svn list http://svn.egomsl.com/svn/repos/autotest.globalegrow.com/projectScript/uitest/template' #模板文件 address = subprocess.check_output(url, shell=True) pri_list = address.split('\n') print pri_list for i in range(len(pri_list)): sourceDir = self.cmd + "/template" + "/" + pri_list[i] command2 = 'svn copy ' + sourceDir + ' ' + targetDir + " -m 'copy project' " print command2 subprocess.check_output(command2, shell=True) def update(self): #更新項目 """ update latest code. """ self.cmd = 'svn update' message = 'update code success' try: subprocess.check_output(self.cmd, shell=True) except Exception: self.cmd = 'svn cleanup' subprocess.check_output(self.cmd, shell=True) self.cmd = 'svn update' subprocess.check_output(self.cmd, shell=True) return {'code': 0, 'msg': message} # 更新svn時須要獲取svn的地址,這樣只更新本身的項目 def svncommit(self): project = self.cmd + '/' + self.project print u"開始提交svn地址" command = "svn ci -m commit 'commit' " + project print command message = 'commit code success' subprocess.check_output(command, shell=True) return {'code': 0, 'msg': message} if __name__ == "__main__": s = SvnCommand(sys.argv[1]) s.crate() s.copyfile()