?零丶腳本起因:
測試需要一個代碼提交規(guī)范,對每個任務(wù)填在表格上
Paste_Image.png
我的思路是,定制git lg 日志,指定代碼提交規(guī)范,把xml格式的日志,輸出到excel上;復(fù)制上去就可以;
git自動生成標簽<time><author>
人為定制標簽:<num><des><rev><ad>
就是說代碼提交要按照:
<num>任務(wù)編號</num><des>描述</des><rev>代碼審核人</rev><ad>安卓互審人</ad>
這個格式來;順序不敏感
一丶定制git Lg
# 參數(shù)定義列表
'%H': commit hash
'%h': 縮短的commit hash
'%T': tree hash
'%t': 縮短的 tree hash
'%P': parent hashes
'%p': 縮短的 parent hashes
'%an': 作者名字
'%aN': mailmap的作者名字 (.mailmap對應(yīng)禽笑,詳情參照git-shortlog(1)或者git-blame(1))
'%ae': 作者郵箱
'%aE': 作者郵箱 (.mailmap對應(yīng),詳情參照git-shortlog(1)或者git-blame(1))
'%ad': 日期 (--date= 制定的格式)
'%aD': 日期, RFC2822格式
'%ar': 日期, 相對格式(1 day ago)
'%at': 日期, UNIX timestamp
'%ai': 日期, ISO 8601 格式
'%cn': 提交者名字
'%cN': 提交者名字 (.mailmap對應(yīng),詳情參照git-shortlog(1)或者git-blame(1))
'%ce': 提交者 email
'%cE': 提交者 email (.mailmap對應(yīng)佩谣,詳情參照git-shortlog(1)或者git-blame(1))
'%cd': 提交日期 (--date= 制定的格式)
'%cD': 提交日期, RFC2822格式
'%cr': 提交日期, 相對格式(1 day ago)
'%ct': 提交日期, UNIX timestamp
'%ci': 提交日期, ISO 8601 格式
'%d': ref名稱
'%e': encoding
'%s': commit信息標題
'%f': sanitized subject line, suitable for a filename
'%b': commit信息內(nèi)容
'%N': commit notes
'%gD': reflog selector, e.g., refs/stash@{1}
'%gd': shortened reflog selector, e.g., stash@{1}
'%gs': reflog subject
'%Cred': 切換到紅色
'%Cgreen': 切換到綠色
'%Cblue': 切換到藍色
'%Creset': 重設(shè)顏色
'%C(...)': 制定顏色, as described in color.branch.* config option
'%m': left, right or boundary mark
'%n': 換行
'%%': a raw %
'%x00': print a byte from a hex code
'%w([[,[,]]])': switch line wrapping, like the -w option of git-shortlog(1).
需求:
我要定制一個xml格式的git日志;<time>時間</time><author></author>commit標題
格式:
<time>%ai</time><author>%an</author>%s
1.修改:
$open open ~/.gitconfig
2.在[alias]標簽修改如下:
[alias]
lg = log --color --pretty=format:'<time>%ai</time><author>%an</author>%s' --abbrev-commit --
3.保存下
結(jié)果:
Paste_Image.png
如果想設(shè)置顏色,格式如下:
%Cgreen 內(nèi)容 %Creset
舉個例子:
[alias]
lg = log --color --graph --pretty=format:'<時間 :%Cgreen%ai%Creset><作者:%C(bold blue)%an%Creset><內(nèi)容: %C(red)%s%Creset> ' --abbrev-commit --
Paste_Image.png
二丶生成excel
上腳本:
#!/usr/bin/python
#-*- coding: utf-8 -*-
#encoding=utf-8
import os
from bs4 import BeautifulSoup
import xlwt
os.system('git lg > hyd.xml')
with open('hyd.xml', 'r') as f:
xml_doc =f.read() #讀取xml文本內(nèi)容
soup = BeautifulSoup(xml_doc, 'html.parser')
keyword = ['num','time','author','des','rev','ad'] #關(guān)鍵詞list
datatable = xlwt.Workbook(encoding='utf-8', style_compression=0)
newsheet = datatable.add_sheet('mxxx', cell_overwrite_ok=True) #新建excel文檔sheet
num = 0 #列
for i in range(len(keyword)):
newsheet.write(0, num, keyword[i]) #寫入每列keyword
info_list = []
for se in soup.find_all(keyword[i]):
info = se.get_text()
info_list.append(info) #找出所有對應(yīng)標簽內(nèi)的text組成list
print(info_list)
for i in range(len(info_list)):
newsheet.write(i+1, num, info_list[i]) #將該list中數(shù)據(jù)以列寫入excel表
num += 1 #列數(shù)加一日戈,繼續(xù)遍歷關(guān)鍵詞寫入excel表格
datatable.save('hydGitLog.xls')
os.system('mv hydGitLog.xls /Users/hyd/Desktop/hydGitLog.xls')
修改下最后的桌面路徑;
把腳本復(fù)制到你工程目錄下,運行一下就ok了
三丶最終效果:
Paste_Image.png