python鉤子簡單腳本

#!/usr/bin/env python

import re

import sys

#驗證提交格式的腳本,其中[和]需要轉義\[

#放到腳本commit-msg裏面,在腳步裏面執行:python /xxx/xxx/xxx.py

mfile = open('/xxx/xxx/.git/COMMIT_EDITMSG', 'rt')
all = ''
while True:
    line = mfile.readline()
    if not line:
        break
    all += line
mfile.close()
msg = re.match('[.*]:.*', all)
if msg:

    print "successfully!"

else:
    print "Error!!"
    sys.exit(1)

    

#!usr/bin/python
#去除清單文件中revision之後的所有字符,執行方法:python xxx.py > file.xml
import re
fin = open('manifest.xml', 'rt')
fin.seek(0)
while True:
    line = fin.readline()
    n = re.search('sync-c', line)
    m = re.search('revision', line)
    if n:
        print line,
    elif m:
        list = re.split('revision', line)
        print list[0]+"/>"   
    else:
        print line,
    if not line:
    break
fin.close()
 

發佈了28 篇原創文章 · 獲贊 6 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章