python实现windows系统通过svn自动提交本地目录
#!/usr/bin/env python #coding=utf-8 import os import xlrd import sys import shutil import importlib importlib.reload(sys) def execCmd(cmd): r = os.popen(cmd) text = r.read() r.close() return text #扫描目录下所有文件 def scanfiles(directory, listAllFiles): listfilex = os.listdir(directory) for i in range(0, len(listfilex)): path = os.path.join(directory, listfilex[i]) if os.path.isdir(path): scanfiles(path, listAllFiles) else: listAllFiles.append(path) return listAllFiles #更新目录 def svnUpdate(localDir): command_str = "svn up " + localDir # print(">> ", command_str) text = execCmd(command_str) print(text) #提交目录 def svnCommit(localDir): command_str = "svn add --force " + localDir # print(">> ", command_str) text = execCmd(command_str) print(text) command_str = "svn ci -m auto_commit " + localDir # print(">> ", command_str) text = execCmd(command_str) print(text) #读取配置的xls配置文件 def readExcelData(excel_path): bookobj = xlrd.open_workbook(excel_path,encoding_override="utf-8") sheetobj = bookobj.sheet_by_index(0) return sheetobj if __name__ == "__main__": #excel_path = "E:\pythonCode\SvnTool.xls" excel_path = sys.argv[1] sheetobj = readExcelData(excel_path) nrows = sheetobj.nrows ncols = sheetobj.ncols for i in range(1, nrows): for j in range(ncols): if j == 0: local_checkout_path = sheetobj.row_values(i)[j] print("local_checkout_path: %s" % (sheetobj.row_values(i)[j])) elif j == 1: type = sheetobj.row_values(i)[j] print("type: %s" % (sheetobj.row_values(i)[j])) #只更新,不提交 if type == "0": print("start update dir: [%s]" % (local_checkout_path)) svnUpdate(local_checkout_path) #更新+提交 elif type == "1": listAllFiles = [] print("start update dir: [%s]" % (local_checkout_path)) svnUpdate(local_checkout_path) print("start commit dir: [%s]" % (local_checkout_path)) svnCommit(local_checkout_path) scanfiles(local_checkout_path, listAllFiles) print("files size [%s], list if size > 50 then no print" % len(listAllFiles) ) for i, val in enumerate(listAllFiles): print ("NO:%s VALUE:%s" % (i+1, val)) #顶多打印50条 if i >= 49: break print("*********************************************************************************************************************")
配置文件附件格式


浙公网安备 33010602011771号