用git来管理工程的开发,git log是非常有用的‘历史'资料,需求就是来自这里,我们希望能对git log有一个定制性强的过滤。此段脚本就是在完成这种类型的任务。对于一个repo所有branch中的commit,脚本将会把message中存在BUG ID的一类commits给提取整理出来,并提供了额外的search_key, 用于定制过滤。
复制代码 代码如下:
# -*- coding: utf-8 -*-
# created by vince67 Feb.2014
# nuovince@gmail.com
import re
import os
import subprocess
def run(project_dir, date_from, date_to, search_key, filename):
bug_dic = {}
bug_branch_dic = {}
try:
os.chdir(project_dir)
except Exception, e:
raise e
branches_list = []
branches_list = get_branches()
for branch in branches_list:
bug_branch_dic = deal_branch(date_from,
date_to,
branch,
search_key)
for item in bug_branch_dic:
if item not in bug_dic:
bug_dic[item] = bug_branch_dic[item]
else:
bug_dic[item] += bug_branch_dic[item]
log_output(filename, bug_dic)
# abstract log of one branch
def deal_branch(date_from, date_to, branch, search_key):
try:
os.system('git checkout ' + branch)
os.system('git pull ')
except Exception, error:
print error
cmd_git_log = ["git",
"log",
"--stat",
"--no-merges",
"-m",
"--after="+date_from,
"--before="+date_to]
proc = subprocess.Popen(cmd_git_log,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
bug_branch_dic = deal_lines(date_from,
date_to,
search_key,
stdout)
return bug_branch_dic
# write commits log to file
def log_output(filename, bug_dic):
fi = open(filename, 'w')
for item in bug_dic:
m1 = '--'*5 + 'BUG:' + item + '--'*20 + '\n'
fi.write(m1)
for commit in bug_dic[item]:
fi.write(commit)
fi.close()
# analyze log
def deal_lines(date_from, date_to, search_key, stdout):
bug_dic = {}
for line in stdout.split('commit '):
if re.search('Bug: \d+', line) is not None and re.search(search_key, line) is not None:
bug_id = line.split('Bug: ')[1].split('\n')[0]
if bug_id not in bug_dic:
bug_dic[bug_id] = [line]
else:
bug_dic[bug_id] += [line]
return bug_dic
# get all branches of a project
def get_branches():
branch_list = []
branches = []
tmp_str = ''
try:
cmd_git_remote = 'git remote show origin'
proc = subprocess.Popen(cmd_git_remote.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
tmp_str = stdout.split('Local branches configured')[0]
try:
tmp_str = tmp_str.split('Remote branches:\n')[1]
except:
tmp_str = tmp_str.split('Remote branch:\n')[1]
branches = tmp_str.split('\n')
for branch in branches[0:-1]:
if re.search(' tracked', branch) is not None:
branch = branch.replace('tracked', '').strip(' ')
branch_list.append(branch)
except Exception, error:
if branch_list == []:
print "Can not get any branch!"
return branch_list
if __name__ == '__main__':
# path of the .git project. example: "/home/username/projects/jekyll_vincent"
project_dir = ""
date_from = "2014-01-25"
date_to = "2014-02-26"
# only search 'Bug: \d+' for default
search_key = ""
# name of output file. example:"/home/username/jekyll_0125_0226.log"
filename = ""
run(project_dir, date_from, date_to, search_key, filename)
git,log,日志
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]