IIS自动化发布工具实现-Manager【二】
思路:
1.首先是要获取项目的差异文件列表,实现方式是通过cmd 执行git 命令。
git pull 拉取最新代码
git log 查看git签入记录 ,使用参数 --pretty=format:" + h,+ an,+ cd,+ s\" 格式化输出格式为 hash,作者,日期,备注
git diff 查看某次签入到现在的差异
git show 查看某次前入的详情
#coding:utf8 import json import os import sys reload(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.上传,支持配置多个上传地址