最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用python分析git log日志示例

 更新時間:2014年02月27日 09:48:12   作者:  
這篇文章主要介紹了使用python分析git log日志示例,需要的朋友可以參考下

用git來管理工程的開發(fā),git log是非常有用的‘歷史'資料,需求就是來自這里,我們希望能對git log有一個定制性強(qiáng)的過濾。此段腳本就是在完成這種類型的任務(wù)。對于一個repo所有branch中的commit,腳本將會把message中存在BUG ID的一類commits給提取整理出來,并提供了額外的search_key, 用于定制過濾。

復(fù)制代碼 代碼如下:

# -*- 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)

相關(guān)文章

  • requests.gPython?用requests.get獲取網(wǎng)頁內(nèi)容為空?’?’問題

    requests.gPython?用requests.get獲取網(wǎng)頁內(nèi)容為空?’?’問題

    這篇文章主要介紹了requests.gPython?用requests.get獲取網(wǎng)頁內(nèi)容為空?’?’,溫行首先舉例說明,具有一定得參考價值,需要的小伙伴可以參考一下
    2022-01-01
  • TensorFlow人工智能學(xué)習(xí)數(shù)據(jù)類型信息及轉(zhuǎn)換

    TensorFlow人工智能學(xué)習(xí)數(shù)據(jù)類型信息及轉(zhuǎn)換

    這篇文章主要為大家介紹了TensorFlow人工智能學(xué)習(xí)數(shù)據(jù)類型信息及轉(zhuǎn)換,
    2021-11-11
  • Python接口自動化測試的實現(xiàn)

    Python接口自動化測試的實現(xiàn)

    這篇文章主要介紹了Python接口自動化測試的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Python中的NumPy實用函數(shù)整理之percentile詳解

    Python中的NumPy實用函數(shù)整理之percentile詳解

    這篇文章主要介紹了Python中的NumPy實用函數(shù)整理之percentile詳解,NumPy函數(shù)percentile()用于計算指定維度上數(shù)組元素的第?n?個百分位數(shù),返回值為標(biāo)量或者數(shù)組,需要的朋友可以參考下
    2023-09-09
  • 基于matplotlib xticks用法詳解

    基于matplotlib xticks用法詳解

    這篇文章主要介紹了基于matplotlib xticks用法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • 詳解Python字符串對象的實現(xiàn)

    詳解Python字符串對象的實現(xiàn)

    本文介紹了 python 內(nèi)部是如何管理字符串對象,以及字符串查找操作是如何實現(xiàn)的,感興趣的小伙伴們可以參考一下
    2015-12-12
  • python編寫微信公眾號首圖思路詳解

    python編寫微信公眾號首圖思路詳解

    這篇文章主要介紹了python編寫微信公眾號首圖的思路,根據(jù)微信公眾號首圖要求,可以上傳一個不超過5M的圖片,且圖片尺寸要是2.35:1的尺寸,具體實現(xiàn)思路及代碼感興趣的朋友跟隨小編一起看看吧
    2019-12-12
  • Python+wxPython實現(xiàn)合并多個文本文件

    Python+wxPython實現(xiàn)合并多個文本文件

    在?Python?編程中,我們經(jīng)常需有時候,我們可能需要將多個文本文件合并成一個文件,要處理文本文件,本文就來介紹下如何使用?wxPython?模塊編寫一個簡單的程序,能夠讓用戶選擇多個文本文件,感興趣的可以了解下
    2023-08-08
  • Python解決asyncio文件描述符最大數(shù)量限制的問題

    Python解決asyncio文件描述符最大數(shù)量限制的問題

    這篇文章主要介紹了Python解決asyncio文件描述符最大數(shù)量限制的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • python自動填寫問卷星問卷以及提交問卷等功能

    python自動填寫問卷星問卷以及提交問卷等功能

    這篇文章主要給大家介紹了關(guān)于python自動填寫問卷星問卷以及提交問卷等功能的相關(guān)資料,包括使用Selenium庫模擬瀏覽器操作、定位元素、填寫表單等,通過本文的學(xué)習(xí),讀者可以了解如何利用Python自動化技術(shù)提高問卷填寫效率,需要的朋友可以參考下
    2023-03-03

最新評論

抚州市| 航空| 华池县| 马龙县| 绥棱县| 宁都县| 溆浦县| 泸州市| 山阳县| 麦盖提县| 江永县| 涟源市| 中方县| 那坡县| 江门市| 竹溪县| 界首市| 东至县| 广灵县| 临潭县| 邢台县| 民乐县| 车险| 泾川县| 龙陵县| 无棣县| 宁都县| 南和县| 盐亭县| 铜陵市| 扶余县| 石嘴山市| 女性| 隆回县| 南开区| 耒阳市| 宁武县| 呈贡县| 乐清市| 云林县| 建阳市|