# -*- coding: UTF-8 -*- import os import sys SvnCmd = os.environ.get("svn") branchName = "trunk" svn_arpgAssetsPath = "https://119.91.229.66/svn/u2china_cli_proj/"+branchName+"/arpg/Assets/" local_arpgAssetsPath = "./u2china_cli_proj/arpg/Assets/" #文件夹列表 clientFolderList = ["Lua", "Protocol","RawResources/Language","Scripts/AIMachine/HotFixLogic","SvrDesc"] svn_ServerAssetsPath = "https://119.91.229.66/svn/u2china_svr_proj/"+branchName+"/" local_ServerAssetsPath = "./u2china_svr_proj/" serverFolderList = ["cfg/data","ServerComm/GameConfig","ServerComm/protocol"] basePath = os.getcwd() # 更新服务器端svn def svnServerUpdate(folderPath): #SvnCmd + " cleanup ../config_system --remove-unversioned" #判断文件夹是否存在 if not os.path.exists(local_ServerAssetsPath + folderPath): command = SvnCmd + " checkout " + svn_ServerAssetsPath + folderPath + " " + local_ServerAssetsPath + folderPath + ''' --username u2cbuilder --password 'u2china&bj' ''' else: command = SvnCmd + " revert -R " + local_ServerAssetsPath + folderPath os.system(command) #切换分支 command = SvnCmd + " switch " + svn_ServerAssetsPath + folderPath + " " + local_ServerAssetsPath + folderPath + ''' --username u2cbuilder --password 'u2china&bj' ''' print(command) result = os.system(command) command = SvnCmd + " update " + local_ServerAssetsPath + folderPath + ''' --username u2cbuilder --password 'u2china&bj' ''' result = os.system(command) + result os.chdir(basePath) if result != 0: sys.exit(1) print("update Finish cd: "+os.getcwd()) # 更新客户端svn def svnUpdate(folderPath): if not os.path.exists(local_arpgAssetsPath + folderPath): command = SvnCmd + " checkout " + svn_arpgAssetsPath + folderPath + " " + local_arpgAssetsPath + folderPath + ''' --username u2cbuilder --password 'u2china&bj' ''' print(command) else: command = SvnCmd + " revert -R " + local_arpgAssetsPath + folderPath print(command) os.system(command) #切换分支 command = SvnCmd + " switch " + svn_arpgAssetsPath + folderPath + " " + local_arpgAssetsPath + folderPath + ''' --username u2cbuilder --password 'u2china&bj' ''' print(command) result = os.system(command) command = SvnCmd + " update " + local_arpgAssetsPath + folderPath + ''' --username u2cbuilder --password 'u2china&bj' ''' result = os.system(command) + result if result != 0: sys.exit(1) os.chdir(basePath) print("update Finish cd: "+os.getcwd()) # 提交客户端svn def svnCommit(CommitFolderPath): os.chdir(basePath + "/" + CommitFolderPath) command = SvnCmd + " add * --force " result = os.system(command) # 删除svn中已经删除的文件 command = SvnCmd + " st | grep '^!' | awk '{print $2}' | xargs "+ SvnCmd +" del" result = os.system(command) + result command = SvnCmd + ''' ci -m "[meta] auto submit by jenkins" ''' + ''' --username u2cbuilder --password 'u2china&bj' ''' result = os.system(command) + result if result != 0: sys.exit(1) os.chdir(basePath) print("cd: " + os.getcwd()) if __name__ == '__main__': if len(sys.argv) > 3: branchName = sys.argv[1] #分支名 cmd = sys.argv[2] #命令 commitType = sys.argv[3] #提交类型 server , client , serverAndclient svn_arpgAssetsPath = "https://119.91.229.66/svn/u2china_cli_proj/" + branchName + "/arpg/Assets/" svn_ServerAssetsPath = "https://119.91.229.66/svn/u2china_svr_proj/" + branchName + "/" if cmd == "commit": if commitType == "client" or commitType == "serverAndclient": for folder in clientFolderList: svnCommit(local_arpgAssetsPath + folder) if commitType == "server" or commitType == "serverAndclient": for folder in serverFolderList: svnCommit(local_ServerAssetsPath + folder) print("svnCommit Done!") exit(0) elif cmd == "update": for folder in clientFolderList: svnUpdate(folder) for folder in serverFolderList: svnServerUpdate(folder) print("svnUpdate Done!") exit(0) else: print("error cmd :"+cmd) exit(1) else: print("error cmd : update or commit") exit(1)