IIS自動化發布工具實現
IIS自動化發布工具實現-Manager【二】
閱讀次數:171 次 來源:admin 發布時間:思路:
1.首先是動化要獲取項目的差異文件列表,實現方式是發布通過cmd 執行git 命令。
git pull 拉取最新代碼
git log 查看git簽入記錄 ,工具使用參數 --pretty=format:" + h,實現+ an,+ cd,+ s\" 格式化輸出格式為 hash,作者,日期,動化備注
git diff 查看某次簽入到現在的發布差異
git show 查看某次前入的詳情
#coding:utf8import jsonimport osimport sysreload(sys)sys.setdefaultencoding("utf-8")class Git(object): branch = \'\' def __init__(self): print(\'git init\') \'\'\' git 簽入記錄 \'\'\' def log(self,path,after = None,before = None,no_merges = False): #isMerges = True result = [] cmd = [] #\'cd %s & git log --merges --pretty=format:" + h,+ an,+ cd,+ s\" --date=local & exit\'%(\'D://git//kdfafa_solution//src//Kdfafa.Cts\') cmd.append("cd %s &"%(path)) cmd.append("git log") if len(self.branch)>0: cmd.append("develop")#分支 if(no_merges): cmd.append("--no-merges") cmd.append(\'--pretty=format:+h,+an,+cd,+s\'.replace("+","%")) cmd.append(\'--date=local\') if(after): cmd.append(\'--after="%s"\'%(after)) if(before): cmd.append(\'--before="%s"\'%(before)) #print(cmd) cmd_str =\' \'.join(cmd) print(cmd_str) p = os.popen(cmd_str) #執行 cmd #txt = p.read() txt = p.read().decode(\'utf8\') #s.decode(\'utf8\').encode(\'gb2312\').decode(\'utf8\') #print(txt) for line in txt.splitlines(): col = line.split(\',\') log = { \'hash\':col[0].strip(),\'author\':col[1].strip(),\'date\':col[2].strip(),\'remark\':col[3].strip()} result.append(log) #print(log) return result \'\'\' git 選中分支與現在文件的差異列表 \'\'\' def diff(self,path,hash, src_path = None): result = [] cmd = [] #\'cd /d { 0} & git diff { 1} --name-only & exit path cmd.append("cd %s &"%(path)) cmd.append("git diff %s"%(hash)) cmd.append("--name-only")#分支 cmd_str =\' \'.join(cmd) #cmd = cmd.replace("+","%") print(cmd_str) print(\'----------------\') p = os.popen(cmd_str) #txt = p.read() txt = p.read().decode(\'utf8\') #s.decode(\'utf8\').encode(\'gb2312\').decode(\'utf8\').encode(\'utf8\') if src_path: src_path = src_path.replace(\'/\',\'\\\').replace(\'//\',\'\\\') for line in txt.splitlines(): line = line.replace(\'/\',\'\\\') #print(line) if src_path is None or line.find(src_path) > -1: result.append(line) return result \'\'\' git 查看某個分支的變更 \'\'\' def show(self,path,hash): #print(msg) result = [] cmd = [] #\'cd /d { 0} & git diff { 1} --name-only & exit path cmd.append("cd %s &"%(path)) cmd.append(\'git show --stat { 0}\'.format(hash)) cmd_str = \' \'.join(cmd) print(cmd_str) p = os.popen(cmd_str) txt = p.read().decode(\'utf8\') #txt = p.read() for line in txt.splitlines(): result.append(line) return result def pull(self,path): #print(msg) result = [] cmd = [] #\'cd /d { 0} & git diff { 1} --name-only & exit path cmd.append("cd %s &"%(path)) cmd.append(\'git pull\') cmd_str = \' \'.join(cmd) print(cmd_str) p = os.popen(cmd_str) txt = p.read().decode(\'utf8\') #txt = p.read() for line in txt.splitlines(): result.append(line) return result
View Code
2.接下來是文件挑揀
過濾規則:1.包含后綴 2.排除文件 3.排除文件夾
3.打包文件
4.上傳,支持配置多個上傳地址
工具未經允許不得轉載:>貴州網站建設公司 » IIS自動化發布工具實現