forked from LinGuoxi/homework-drexel2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomework.py
62 lines (51 loc) · 1.96 KB
/
homework.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ZhangYapeng"
__id__ = "320180940551"
__email__ = "[email protected]"
__copyright__ = 'ZhangYapeng only reserved'
import os, re, sys, subprocess, argparse
from datetime import datetime as dt
class get_dates_commit():
def __init__(self,rev,rev1):
self.rev = rev
self.rev1 = rev1
self.repository = 'F:\git_repository\linux-stable'
def get_parse(self):
parser = argparse.ArgumentParser(description='get_parser')
parser.add_argument('-sv','--starting_version', type=str,default='v4.4',help='The starting version to start counting')
parser.add_argument('-rn','--revison_number', type=str,required=True,help='The revision number to query from the base version')
parser.add_argument('-wc','--whether_cumulative', type=bool,default=False,help='whether to cumulative')
return parser
def get_commit_cnt(self):
gitcnt = "git rev-list --pretty=format:\"%ai\" " + self.rev +".."+self.rev1
git_rev_list = subprocess.Popen(['ubuntu',gitcnt],cwd=self.repository,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL,shell=True)
raw_counts = git_cmd.communicate()[0]
cnt = re.findall('[0-9]*-[0-9]*-[0-9]*', str(raw_counts))
return len(cnt)
def get_tag_days(self, git_cmd, base):
seconds = git_cmd.communicate()[0]
return ((int(seconds)-base))//3600
def main():
rev = sys.argv[1]
rev_range = int(sys.argv[2])
try:
if len(sys.argv) == 4:
if (sys.argv[3] == "c"):
cumulative = 1
else:
print("Dont know what you mean with %s" % sys.argv[3])
sys.exit(-1)
except:
pass
for sl in range(1,rev_range+1):
try:
print("commits: {0}, ".format(get_dates_commit(rev,rev+"."+str(sl)).get_commit_cnt()))
except TypeError:
print("You have an invalid input on the 1st param")
try:
print("time: {0}, ".format(get_dates_commit(rev,rev+"."+str(sl)).get_tag_days()))
except TypeError:
print("You have an invalid input on the 2nd param")
if __name__ == "__main__":
main()