python调用git生成log文件_python解析git log后生成页面显示git更新日志信息
使用git log可以查到git上项目的更新日志。
如下两个git项目,我想把git的日志信息解析成一个便于在浏览器上查看的页面。
https://github.com/gityf/lua
https://github.com/gityf/db
使用git log命令获取git更新日志信息:
D:\git\github\lua>git log > ..\lua.gitlog
D:\git\github\db>git log > ..\dbutils.gitlog
生成两个git更新日志文件lua.gitlog和dbutils.gitlog。
文件内容格式是这样的:
commit a5ff94375f48c7de067a1c191cb60d720bf4f726
Author: Mr.YF
Date: Tue Jan 12 19:43:33 2016 +0800
add thrift binary analysis code and doc.
commit 9dc9437070867e8d8ba7c9d4365efe3f2c317caf
Author: Mr.YF
Date: Mon Jan 11 19:51:48 2016 +0800
add comments.
git log命令会输出关键字"commit","Merge","Author","Date"
使用下面脚本分析git日志,生成html的页面,便于查看。
'''
Created on 2016-1-25
@author: Mr.YF
'''
import os
import sys
def header():
headerHtml = '''//W3C//DTD HTML 4.01 Transitional//EN "http://www.w3.org/TR/html4/loose.dtd">
Statistics Report for gitcheck.
body {
font-family: arial, helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
color: black;
background: white;
}
th,td {
font-size: 10px;
}
h1 {
font-size: x-large;
margin-bottom: 0.5em;
}
h2 {
font-family: helvetica, arial;
font-size: x-large;
font-weight: bold;
font-style: italic;
color: #6020a0;
margin-top: 0em;
margin-bottom: 0em;
}
h3 {
font-family: helvetica, arial;
font-size: 16px;
font-weight: bold;
color: #b00040;
background: #e8e8d0;
margin-top: 0em;
margin-bottom: 0em;
}
li {
margin-top: 0.25em;
margin-right: 2em;
}
.hr {margin-top: 0.25em;
border-color: black;
border-bottom-style: solid;
}
.in {color: #6020a0; font-weight: bold; text-align: left;}
.frontend {background: #e8e8d0;}
.s {background: #e0e0e0;}
.a0 {background: #FF99CC; font-weight: bold;}
.a1 {background: #CCFF99;}
.a2 {background: #CCFFFF;}
.a3 {background: #CCCCFF;}
.a4 {background: #66CCCC;}
.a5 {background: #CCFF66;}
.a6 {background: #FFCC99;}
.maintain {background: #c07820;}
.rls {letter-spacing: 0.2em; margin-right: 1px;}
a.px:link {color: #ffff40; text-decoration: none;}
a.px:visited {color: #ffff40; text-decoration: none;}
a.px:hover {color: #ffffff; text-decoration: none;}
a.lfsb:link {color: #000000; text-decoration: none;}
a.lfsb:visited {color: #000000; text-decoration: none;}
a.lfsb:hover {color: #505050; text-decoration: none;}
table.tbl { border-collapse: collapse; border-style: none;}
table.tbl td { text-align: right; border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray; white-space: nowrap;}
table.tbl td.ac { text-align: center;}
table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}
table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}
table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}
table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}
table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}
table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}
table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}
u {text-decoration:none; border-bottom: 1px dotted black;}
-->
GitCheck Center
> General git information
return headerHtml
def footer():
footHtml = '''
'''
return footHtml
def row():
rowHtml = '''
%s%s%s%s%s'''
return rowHtml
def indexMainRow():
rowHtml = '''
IDbranch git log info.'''
return rowHtml
def indexRow():
rowHtml = '''
%d%s'''
return rowHtml
def tdClassId(pageId):
pageId += 1
if pageId >= 7:
pageId = 1
return pageId
def gitcheck(inFileName="gitcheck.in", outFileName="gitcheck.out.html"):
fn = open(inFileName, "r")
fnOut = open(outFileName, "w")
fnOut.write(header())
fnOut.write(row() % (0, "commit","Merge","Author","Date", "Comment"))
lines = fn.readlines()
beginTag = False
pageId = 1
goodLine = {0:"",1:"",2:"",3:"",4:""}
for line in lines:
if len(line) <= 2:
continue
if line.startswith("commit"):
beginTag = True
goodLine[0] = line[6:]
pageId = tdClassId(pageId)
continue
if beginTag:
if line.startswith("Merge: "):
goodLine[1] = line[7:]
elif line.startswith("Author: "):
goodLine[2] = line[8:]
elif line.startswith("Date: "):
goodLine[3] = line[6:]
else :
goodLine[4] = line
beginTag = False
fnOut.write(row() % (pageId,goodLine[0],goodLine[1],goodLine[2],goodLine[3],goodLine[4]))
goodLine = {0:"",1:"",2:"",3:"",4:""}
fn.close()
fnOut.write(footer())
fnOut.flush()
fnOut.close()
def lsHtmls(dirName="gitinfo"):
htmlFiles = []
allFile = os.listdir(dirName)
for f in allFile:
if f.endswith(".html"):
htmlFiles.append(f)
print f
return htmlFiles
def createIndex(dirName):
files = lsHtmls(dirName)
if len(files) > 0:
fnOut = open("index.html", "w")
fnOut.write(header())
fnOut.write(indexMainRow())
pageId = 1
ii = 1
for f in files:
fnOut.write(indexRow() % (ii, pageId, f, f))
ii = tdClassId(ii)
pageId += 1
fnOut.write(footer());
fnOut.close()
if __name__ == '__main__':
if len(sys.argv) >= 3:
gitcheck(sys.argv[1], sys.argv[2])
elif len(sys.argv) >= 2:
createIndex(sys.argv[1])
把python代码保存为gitcheck.py
使用如下命令解析日志文件lua.gitlog和dbutils.gitlog。
F:\pyworkspace\gitcheck>python gitcheck.py dbutils.gitlog gitinfo\dbutils.html
F:\pyworkspace\gitcheck>python gitcheck.py lua.gitlog gitinfo\lua_thrift_demo.html
F:\pyworkspace\gitcheck>python gitcheck.py gitinfo
dbutils.html
lua_thrift_demo.html
python gitcheck.py gitinfo会把目录gitinfo下所有的html文件汇总生成一个index.html主页。
效果如下:
主页
跳转到某个项目查看git日志信息
Done.
python调用git生成log文件_python解析git log后生成页面显示git更新日志信息相关推荐
- python生成sql文件_Python 数据库Insert语句脚本生成工具(SQL Server)
编写这个小工具,是因为平时部署项目的时候,需要导出一些公共的数据(权限.参数设置等),覆盖插入正式环境. 话不多说,直接上代码: import pyodbc import warnings impor ...
- 加载google Z-Xing库实现二维码解析与生成,并将解析结果在另一页面显示
1.首先需要下载Z-Xing 库项目下载文档,可在http://download.csdn.net/detail/catchingsun/8903065进行下载: 2.解析二维码,并跳转至新建Acti ...
- python解析log文件_python解析基于xml格式的日志文件
大家中午好,由于过年一直还没回到状态,好久没分享一波小知识了,今天,继续给大家分享一波Python解析日志的小脚本. 首先,同样的先看看日志是个啥样. 都是xml格式的,是不是看着就头晕了??没事,我 ...
- python调用接口上传文件_python上传文件接口
文件的参数组装: ('文件名',"open打开的文件(rb模式打开)",'文件的类型说明') 关于不同的请求参数类型,使用requests的处理: 1.文件上传(Content-T ...
- python调用接口上传文件_python接口自动化7-post文件上传
前言 文件上传在我们软件是不可少的,最多的使用是体现在我们后台,当然我们前台也会有.但是了解过怎样上传文件吗?这篇我们以禅道文档-创建文档,上传文件为例. post请求中的:Content-Type: ...
- python读取log文件_python文件读写(一)-txt, log, json, csv, xml文件
1.概述在平时自动化测试工作中,经常会用python对一些文件进行读写操作.其中使用最多的文件格式,就是txt, log, json, csv, xml, zip, tar, gz, ra ...
- 实现python调用Matlab的.m文件
------------------------------------------------------------------------------------------------- 本文 ...
- 四、日志系统:log文件夹下的log.h和log.cpp——TinyWebServer
四.日志系统:log文件夹下的log.h和log.cpp 本章是具体的日志系统类的介绍 1. 基础API 介绍一些API用法 (1)fputs #include <stdio.h> int ...
- Markdown入门和解决MD文件上传博客后图片无法显示问题
文章目录 Markdown基础和解决MD文件上传博客后图片无法显示问题 一.常见文本操作 1.标题 一级标题 二级标题 三级标题 四级标题 2.代码块 3.字体 4.引用 5.分割线 6.超链接 7. ...
最新文章
- 苹果要垄断?官方证实:T2安全芯片会限制新款Mac电脑第三方
- Ext.NET加入自定义验证JS函数
- Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://sch
- 数字文档搜寻指南 v6.0
- html 左侧 树形菜单,vue左侧菜单,树形图递归实现代码
- 王思聪也救不了熊猫直播了?
- Oracle推断值为非数字
- SqlServer2005基于已有表创建分区
- VC2005编译安装QT
- 手把手教你调用微信扫一扫,三分钟包会
- Alex 的 Hadoop 菜鸟教程: 第2课 hadoop 安装教程 (CentOS6 CDH分支 yum方式)
- 《Java性能优化权威指南》读书笔记
- 如何用Easy CHM制作CHM格式电子书(帮助文档)
- 海量计算机入门视频教程
- 不用U盘,给自己的电脑重装一个win10系统
- 【AAE】【Keras】实现merge出错:TypeError: ‘module‘ object is not callable
- 如何在电脑上安装一个Android虚拟机
- Neural Granger Causality for Nonlinear Time Series
- 修改xampp中的mysql的密码报错,ERROR 1348 (HY000): Column 'Password' is not updatable
- Spring AOP中的静态代理和动态代理的原理和实践