Heikki Hokkanen 18 anni fa
parent
commit
baadfe7d75
1 ha cambiato i file con 19 aggiunte e 9 eliminazioni
  1. 19
    9
      statgit

+ 19
- 9
statgit Vedi File

11
 	def __init__(self):
11
 	def __init__(self):
12
 		pass
12
 		pass
13
 	
13
 	
14
+	##
15
+	# This should be the main function to extract data from the repository.
14
 	def collect(self, dir):
16
 	def collect(self, dir):
15
 		self.dir = dir
17
 		self.dir = dir
16
 	
18
 	
45
 class GitDataCollector(DataCollector):
47
 class GitDataCollector(DataCollector):
46
 	def collect(self, dir):
48
 	def collect(self, dir):
47
 		DataCollector.collect(self, dir)
49
 		DataCollector.collect(self, dir)
50
+
51
+		self.total_authors = int(commands.getoutput('git-log |git-shortlog -s |wc -l'))
52
+		self.total_commits = int(commands.getoutput('git-rev-list --all |wc -l'))
53
+		self.total_files = int(commands.getoutput('git-ls-files |wc -l'))
54
+		self.total_lines = int(commands.getoutput('git-ls-files |xargs cat |wc -l'))
48
 	
55
 	
49
 	def getAuthorInfo(self, author):
56
 	def getAuthorInfo(self, author):
50
 		commits = int(commands.getoutput('git-rev-list --all --author="%s" |wc -l' % author))
57
 		commits = int(commands.getoutput('git-rev-list --all --author="%s" |wc -l' % author))
53
 		date_last = '0000-00-00'
60
 		date_last = '0000-00-00'
54
 		rev_last = commands.getoutput('git-rev-list --all --author="%s" -n 1' % author)
61
 		rev_last = commands.getoutput('git-rev-list --all --author="%s" -n 1' % author)
55
 		rev_first = commands.getoutput('git-rev-list --all --author="%s" |tail -n 1' % author)
62
 		rev_first = commands.getoutput('git-rev-list --all --author="%s" |tail -n 1' % author)
56
-		stamp_last = int(commands.getoutput('git-log --pretty=format:%%at "%s" -n 1' % rev_last))
57
-		stamp_first = int(commands.getoutput('git-log --pretty=format:%%at "%s" -n 1' % rev_first))
58
-		date_first = datetime.datetime.fromtimestamp(stamp_first).strftime('%Y-%m-%d')
59
-		date_last = datetime.datetime.fromtimestamp(stamp_last).strftime('%Y-%m-%d')
63
+		date_first = self.revToDate(rev_first)
64
+		date_last = self.revToDate(rev_last)
60
 
65
 
61
 		res = { 'commits': commits, 'commits_frac': commits_frac, 'date_first': date_first, 'date_last': date_last }
66
 		res = { 'commits': commits, 'commits_frac': commits_frac, 'date_first': date_first, 'date_last': date_last }
62
 		return res
67
 		return res
66
 		return lines.split('\n')
71
 		return lines.split('\n')
67
 	
72
 	
68
 	def getTotalAuthors(self):
73
 	def getTotalAuthors(self):
69
-		return int(commands.getoutput('git-log |git-shortlog -s |wc -l'))
74
+		return self.total_authors
70
 	
75
 	
71
 	def getTotalCommits(self):
76
 	def getTotalCommits(self):
72
-		return int(commands.getoutput('git-rev-list --all |wc -l'))
77
+		return self.total_commits
73
 
78
 
74
 	def getTotalFiles(self):
79
 	def getTotalFiles(self):
75
-		files = commands.getoutput('git-ls-files |wc -l')
76
-		return int(files)
80
+		return self.total_files
77
 	
81
 	
78
 	def getTotalLOC(self):
82
 	def getTotalLOC(self):
79
-		return int(commands.getoutput('git-ls-files |xargs cat |wc -l'))
83
+		return self.total_lines
84
+	
85
+	def revToDate(self, rev):
86
+		stamp = int(commands.getoutput('git-log --pretty=format:%%at "%s" -n 1' % rev))
87
+		return datetime.datetime.fromtimestamp(stamp).strftime('%Y-%m-%d')
80
 
88
 
81
 class ReportCreator:
89
 class ReportCreator:
82
 	def __init__(self):
90
 	def __init__(self):
149
 
157
 
150
 os.chdir(gitpath)
158
 os.chdir(gitpath)
151
 
159
 
160
+print 'Collecting data...'
152
 data = GitDataCollector()
161
 data = GitDataCollector()
153
 data.collect(gitpath)
162
 data.collect(gitpath)
154
 
163
 
164
+print 'Generating report...'
155
 report = HTMLReportCreator()
165
 report = HTMLReportCreator()
156
 report.create(data, outputpath)
166
 report.create(data, outputpath)
157
 
167