2 # Copyright (c) 2007 Heikki Hokkanen <hoxu@users.sf.net>
13 GNUPLOT_COMMON
= 'set terminal png transparent\nset size 0.5,0.5\n'
15 exectime_internal
= 0.0
16 exectime_external
= 0.0
17 time_start
= time
.time()
19 def getoutput(cmd
, quiet
= False):
20 global exectime_external
25 output
= commands
.getoutput(cmd
)
28 print '\r[%.5f] >> %s' % (end
- start
, cmd
)
29 exectime_external
+= (end
- start
)
32 def getkeyssortedbyvalues(dict):
33 return map(lambda el
: el
[1], sorted(map(lambda el
: (el
[1], el
[0]), dict.items())))
35 # TODO getdictkeyssortedbyvaluekey(dict, key) - eg. dict['author'] = { 'commits' : 512 } - ...key(dict, 'commits')
38 """Manages data collection from a revision control repository."""
40 self
.stamp_created
= time
.time()
44 # This should be the main function to extract data from the repository.
45 def collect(self
, dir):
47 self
.projectname
= os
.path
.basename(os
.path
.abspath(dir))
50 # : get a dictionary of author
51 def getAuthorInfo(self
, author
):
54 def getActivityByDayOfWeek(self
):
57 def getActivityByHourOfDay(self
):
61 # Get a list of authors
65 def getFirstCommitDate(self
):
66 return datetime
.datetime
.now()
68 def getLastCommitDate(self
):
69 return datetime
.datetime
.now()
71 def getStampCreated(self
):
72 return self
.stamp_created
77 def getTotalAuthors(self
):
80 def getTotalCommits(self
):
83 def getTotalFiles(self
):
86 def getTotalLOC(self
):
89 class GitDataCollector(DataCollector
):
90 def collect(self
, dir):
91 DataCollector
.collect(self
, dir)
93 self
.total_authors
= int(getoutput('git-log |git-shortlog -s |wc -l'))
94 #self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l'))
96 self
.activity_by_hour_of_day
= {} # hour -> commits
97 self
.activity_by_day_of_week
= {} # day -> commits
98 self
.activity_by_month_of_year
= {} # month [1-12] -> commits
99 self
.activity_by_hour_of_week
= {} # weekday -> hour -> commits
101 self
.authors
= {} # name -> {commits, first_commit_stamp, last_commit_stamp}
103 # author of the month
104 self
.author_of_month
= {} # month -> author -> commits
105 self
.author_of_year
= {} # year -> author -> commits
106 self
.commits_by_month
= {} # month -> commits
107 self
.commits_by_year
= {} # year -> commits
108 self
.first_commit_stamp
= 0
109 self
.last_commit_stamp
= 0
113 lines
= getoutput('git-show-ref --tags').split('\n')
117 (hash, tag
) = line
.split(' ')
118 tag
= tag
.replace('refs/tags/', '')
119 output
= getoutput('git-log "%s" --pretty=format:"%%at %%an" -n 1' % hash)
121 parts
= output
.split(' ')
124 stamp
= int(parts
[0])
127 self
.tags
[tag
] = { 'stamp': stamp
, 'hash' : hash, 'date' : datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d') }
130 # Collect revision statistics
131 # Outputs "<stamp> <author>"
132 lines
= getoutput('git-rev-list --pretty=format:"%at %an" HEAD |grep -v ^commit').split('\n')
134 # linux-2.6 says "<unknown>" for one line O_o
135 parts
= line
.split(' ')
138 stamp
= int(parts
[0])
142 author
= ' '.join(parts
[1:])
143 date
= datetime
.datetime
.fromtimestamp(float(stamp
))
145 # First and last commit stamp
146 if self
.last_commit_stamp
== 0:
147 self
.last_commit_stamp
= stamp
148 self
.first_commit_stamp
= stamp
153 if hour
in self
.activity_by_hour_of_day
:
154 self
.activity_by_hour_of_day
[hour
] += 1
156 self
.activity_by_hour_of_day
[hour
] = 1
160 if day
in self
.activity_by_day_of_week
:
161 self
.activity_by_day_of_week
[day
] += 1
163 self
.activity_by_day_of_week
[day
] = 1
166 if day
not in self
.activity_by_hour_of_week
:
167 self
.activity_by_hour_of_week
[day
] = {}
168 if hour
not in self
.activity_by_hour_of_week
[day
]:
169 self
.activity_by_hour_of_week
[day
][hour
] = 1
171 self
.activity_by_hour_of_week
[day
][hour
] += 1
175 if month
in self
.activity_by_month_of_year
:
176 self
.activity_by_month_of_year
[month
] += 1
178 self
.activity_by_month_of_year
[month
] = 1
181 if author
not in self
.authors
:
182 self
.authors
[author
] = {}
184 if 'last_commit_stamp' not in self
.authors
[author
]:
185 self
.authors
[author
]['last_commit_stamp'] = stamp
186 self
.authors
[author
]['first_commit_stamp'] = stamp
187 if 'commits' in self
.authors
[author
]:
188 self
.authors
[author
]['commits'] += 1
190 self
.authors
[author
]['commits'] = 1
192 # author of the month/year
193 yymm
= datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m')
194 if yymm
in self
.author_of_month
:
195 if author
in self
.author_of_month
[yymm
]:
196 self
.author_of_month
[yymm
][author
] += 1
198 self
.author_of_month
[yymm
][author
] = 1
200 self
.author_of_month
[yymm
] = {}
201 self
.author_of_month
[yymm
][author
] = 1
202 if yymm
in self
.commits_by_month
:
203 self
.commits_by_month
[yymm
] += 1
205 self
.commits_by_month
[yymm
] = 1
207 yy
= datetime
.datetime
.fromtimestamp(stamp
).year
208 if yy
in self
.author_of_year
:
209 if author
in self
.author_of_year
[yy
]:
210 self
.author_of_year
[yy
][author
] += 1
212 self
.author_of_year
[yy
][author
] = 1
214 self
.author_of_year
[yy
] = {}
215 self
.author_of_year
[yy
][author
] = 1
216 if yy
in self
.commits_by_year
:
217 self
.commits_by_year
[yy
] += 1
219 self
.commits_by_year
[yy
] = 1
221 # TODO Optimize this, it's the worst bottleneck
222 # outputs "<stamp> <files>" for each revision
223 self
.files_by_stamp
= {} # stamp -> files
224 lines
= getoutput('git-rev-list --pretty=format:"%at %H" HEAD |grep -v ^commit |while read line; do set $line; echo "$1 $(git-ls-tree -r "$2" |wc -l)"; done').split('\n')
225 self
.total_commits
= len(lines
)
227 parts
= line
.split(' ')
230 (stamp
, files
) = parts
[0:2]
232 self
.files_by_stamp
[int(stamp
)] = int(files
)
234 print 'Warning: failed to parse line "%s"' % line
237 self
.extensions
= {} # extension -> files, lines
238 lines
= getoutput('git-ls-files').split('\n')
239 self
.total_files
= len(lines
)
241 base
= os
.path
.basename(line
)
242 if base
.find('.') == -1:
245 ext
= base
[(base
.rfind('.') + 1):]
247 if ext
not in self
.extensions
:
248 self
.extensions
[ext
] = {'files': 0, 'lines': 0}
250 self
.extensions
[ext
]['files'] += 1
252 # FIXME filenames with spaces or special characters are broken
253 self
.extensions
[ext
]['lines'] += int(getoutput('wc -l < %s' % line
, quiet
= True))
255 print 'Warning: Could not count lines for file "%s"' % line
259 # N files changed, N insertions (+), N deletions(-)
261 self
.changes_by_date
= {} # stamp -> { files, ins, del }
262 lines
= getoutput('git-log --shortstat --pretty=format:"%at %an" |tac').split('\n')
263 files
= 0; inserted
= 0; deleted
= 0; total_lines
= 0
269 if line
.find('files changed,') == -1:
271 (stamp
, author
) = (int(line
[:pos
]), line
[pos
+1:])
272 self
.changes_by_date
[stamp
] = { 'files': files
, 'ins': inserted
, 'del': deleted
, 'lines': total_lines
}
274 numbers
= re
.findall('\d+', line
)
275 if len(numbers
) == 3:
276 (files
, inserted
, deleted
) = map(lambda el
: int(el
), numbers
)
277 total_lines
+= inserted
278 total_lines
-= deleted
280 print 'Warning: failed to handle line "%s"' % line
281 (files
, inserted
, deleted
) = (0, 0, 0)
282 #self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted }
283 self
.total_lines
= total_lines
285 def getActivityByDayOfWeek(self
):
286 return self
.activity_by_day_of_week
288 def getActivityByHourOfDay(self
):
289 return self
.activity_by_hour_of_day
291 def getAuthorInfo(self
, author
):
292 a
= self
.authors
[author
]
294 commits
= a
['commits']
295 commits_frac
= (100 * float(commits
)) / self
.getTotalCommits()
296 date_first
= datetime
.datetime
.fromtimestamp(a
['first_commit_stamp'])
297 date_last
= datetime
.datetime
.fromtimestamp(a
['last_commit_stamp'])
298 delta
= date_last
- date_first
300 res
= { 'commits': commits
, 'commits_frac': commits_frac
, 'date_first': date_first
.strftime('%Y-%m-%d'), 'date_last': date_last
.strftime('%Y-%m-%d'), 'timedelta' : delta
}
303 def getAuthors(self
):
304 return self
.authors
.keys()
306 def getFirstCommitDate(self
):
307 return datetime
.datetime
.fromtimestamp(self
.first_commit_stamp
)
309 def getLastCommitDate(self
):
310 return datetime
.datetime
.fromtimestamp(self
.last_commit_stamp
)
313 lines
= getoutput('git-show-ref --tags |cut -d/ -f3')
314 return lines
.split('\n')
316 def getTagDate(self
, tag
):
317 return self
.revToDate('tags/' + tag
)
319 def getTotalAuthors(self
):
320 return self
.total_authors
322 def getTotalCommits(self
):
323 return self
.total_commits
325 def getTotalFiles(self
):
326 return self
.total_files
328 def getTotalLOC(self
):
329 return self
.total_lines
331 def revToDate(self
, rev
):
332 stamp
= int(getoutput('git-log --pretty=format:%%at "%s" -n 1' % rev
))
333 return datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d')
336 """Creates the actual report based on given data."""
340 def create(self
, data
, path
):
344 def html_linkify(text
):
345 return text
.lower().replace(' ', '_')
347 def html_header(level
, text
):
348 name
= html_linkify(text
)
349 return '\n<h%d><a href="#%s" name="%s">%s</a></h%d>\n\n' % (level
, name
, name
, text
, level
)
351 class HTMLReportCreator(ReportCreator
):
352 def create(self
, data
, path
):
353 ReportCreator
.create(self
, data
, path
)
354 self
.title
= data
.projectname
356 # TODO copy the CSS if it does not exist
357 if not os
.path
.exists(path
+ '/gitstats.css'):
358 shutil
.copyfile('gitstats.css', path
+ '/gitstats.css')
361 f
= open(path
+ "/index.html", 'w')
362 format
= '%Y-%m-%d %H:%m:%S'
365 f
.write('<h1>GitStats - %s</h1>' % data
.projectname
)
370 f
.write('<dt>Project name</dt><dd>%s</dd>' % (data
.projectname
))
371 f
.write('<dt>Generated</dt><dd>%s (in %d seconds)</dd>' % (datetime
.datetime
.now().strftime(format
), time
.time() - data
.getStampCreated()));
372 f
.write('<dt>Report Period</dt><dd>%s to %s</dd>' % (data
.getFirstCommitDate().strftime(format
), data
.getLastCommitDate().strftime(format
)))
373 f
.write('<dt>Total Files</dt><dd>%s</dd>' % data
.getTotalFiles())
374 f
.write('<dt>Total Lines of Code</dt><dd>%s</dd>' % data
.getTotalLOC())
375 f
.write('<dt>Total Commits</dt><dd>%s</dd>' % data
.getTotalCommits())
376 f
.write('<dt>Authors</dt><dd>%s</dd>' % data
.getTotalAuthors())
379 f
.write('</body>\n</html>');
384 f
= open(path
+ '/activity.html', 'w')
386 f
.write('<h1>Activity</h1>')
389 #f.write('<h2>Last 30 days</h2>')
391 #f.write('<h2>Last 12 months</h2>')
394 f
.write(html_header(2, 'Hour of Day'))
395 hour_of_day
= data
.getActivityByHourOfDay()
396 f
.write('<table><tr><th>Hour</th>')
397 for i
in range(1, 25):
398 f
.write('<th>%d</th>' % i
)
399 f
.write('</tr>\n<tr><th>Commits</th>')
400 fp
= open(path
+ '/hour_of_day.dat', 'w')
401 for i
in range(0, 24):
403 f
.write('<td>%d</td>' % hour_of_day
[i
])
404 fp
.write('%d %d\n' % (i
, hour_of_day
[i
]))
406 f
.write('<td>0</td>')
407 fp
.write('%d 0\n' % i
)
409 f
.write('</tr>\n<tr><th>%</th>')
410 totalcommits
= data
.getTotalCommits()
411 for i
in range(0, 24):
413 f
.write('<td>%.2f</td>' % ((100.0 * hour_of_day
[i
]) / totalcommits
))
415 f
.write('<td>0.00</td>')
416 f
.write('</tr></table>')
417 f
.write('<img src="hour_of_day.png" alt="Hour of Day" />')
418 fg
= open(path
+ '/hour_of_day.dat', 'w')
419 for i
in range(0, 24):
421 fg
.write('%d %d\n' % (i
+ 1, hour_of_day
[i
]))
423 fg
.write('%d 0\n' % (i
+ 1))
427 f
.write(html_header(2, 'Day of Week'))
428 day_of_week
= data
.getActivityByDayOfWeek()
429 f
.write('<div class="vtable"><table>')
430 f
.write('<tr><th>Day</th><th>Total (%)</th></tr>')
431 fp
= open(path
+ '/day_of_week.dat', 'w')
432 for d
in range(0, 7):
435 commits
= day_of_week
[d
]
436 fp
.write('%d %d\n' % (d
+ 1, commits
))
438 f
.write('<th>%d</th>' % (d
+ 1))
440 f
.write('<td>%d (%.2f%%)</td>' % (day_of_week
[d
], (100.0 * day_of_week
[d
]) / totalcommits
))
442 f
.write('<td>0</td>')
444 f
.write('</table></div>')
445 f
.write('<img src="day_of_week.png" alt="Day of Week" />')
449 f
.write(html_header(2, 'Hour of Week'))
452 f
.write('<tr><th>Weekday</th>')
453 for hour
in range(0, 24):
454 f
.write('<th>%d</th>' % (hour
+ 1))
457 for weekday
in range(0, 7):
458 f
.write('<tr><th>%d</th>' % (weekday
+ 1))
459 for hour
in range(0, 24):
461 commits
= data
.activity_by_hour_of_week
[weekday
][hour
]
465 f
.write('<td>%d</td>' % commits
)
473 f
.write(html_header(2, 'Month of Year'))
474 f
.write('<div class="vtable"><table>')
475 f
.write('<tr><th>Month</th><th>Commits (%)</th></tr>')
476 fp
= open (path
+ '/month_of_year.dat', 'w')
477 for mm
in range(1, 13):
479 if mm
in data
.activity_by_month_of_year
:
480 commits
= data
.activity_by_month_of_year
[mm
]
481 f
.write('<tr><td>%d</td><td>%d (%.2f %%)</td></tr>' % (mm
, commits
, (100.0 * commits
) / data
.getTotalCommits()))
482 fp
.write('%d %d\n' % (mm
, commits
))
484 f
.write('</table></div>')
485 f
.write('<img src="month_of_year.png" alt="Month of Year" />')
487 # Commits by year/month
488 f
.write(html_header(2, 'Commits by year/month'))
489 f
.write('<div class="vtable"><table><tr><th>Month</th><th>Commits</th></tr>')
490 for yymm
in reversed(sorted(data
.commits_by_month
.keys())):
491 f
.write('<tr><td>%s</td><td>%d</td></tr>' % (yymm
, data
.commits_by_month
[yymm
]))
492 f
.write('</table></div>')
493 f
.write('<img src="commits_by_year_month.png" alt="Commits by year/month" />')
494 fg
= open(path
+ '/commits_by_year_month.dat', 'w')
495 for yymm
in sorted(data
.commits_by_month
.keys()):
496 fg
.write('%s %s\n' % (yymm
, data
.commits_by_month
[yymm
]))
500 f
.write(html_header(2, 'Commits by Year'))
501 f
.write('<div class="vtable"><table><tr><th>Year</th><th>Commits (% of all)</th></tr>')
502 for yy
in reversed(sorted(data
.commits_by_year
.keys())):
503 f
.write('<tr><td>%s</td><td>%d (%.2f%%)</td></tr>' % (yy
, data
.commits_by_year
[yy
], (100.0 * data
.commits_by_year
[yy
]) / data
.getTotalCommits()))
504 f
.write('</table></div>')
505 f
.write('<img src="commits_by_year.png" alt="Commits by Year" />')
506 fg
= open(path
+ '/commits_by_year.dat', 'w')
507 for yy
in sorted(data
.commits_by_year
.keys()):
508 fg
.write('%d %d\n' % (yy
, data
.commits_by_year
[yy
]))
511 f
.write('</body></html>')
516 f
= open(path
+ '/authors.html', 'w')
519 f
.write('<h1>Authors</h1>')
522 # Authors :: List of authors
523 f
.write(html_header(2, 'List of Authors'))
525 f
.write('<table class="authors">')
526 f
.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th><th>Age</th></tr>')
527 for author
in sorted(data
.getAuthors()):
528 info
= data
.getAuthorInfo(author
)
529 f
.write('<tr><td>%s</td><td>%d (%.2f%%)</td><td>%s</td><td>%s</td><td>%s</td></tr>' % (author
, info
['commits'], info
['commits_frac'], info
['date_first'], info
['date_last'], info
['timedelta']))
532 # Authors :: Author of Month
533 f
.write(html_header(2, 'Author of Month'))
535 f
.write('<tr><th>Month</th><th>Author</th><th>Commits (%)</th></tr>')
536 for yymm
in reversed(sorted(data
.author_of_month
.keys())):
537 authordict
= data
.author_of_month
[yymm
]
538 authors
= getkeyssortedbyvalues(authordict
)
540 commits
= data
.author_of_month
[yymm
][authors
[0]]
541 f
.write('<tr><td>%s</td><td>%s</td><td>%d (%.2f%% of %d)</td></tr>' % (yymm
, authors
[0], commits
, (100 * commits
) / data
.commits_by_month
[yymm
], data
.commits_by_month
[yymm
]))
545 f
.write(html_header(2, 'Author of Year'))
546 f
.write('<table><tr><th>Year</th><th>Author</th><th>Commits (%)</th></tr>')
547 for yy
in reversed(sorted(data
.author_of_year
.keys())):
548 authordict
= data
.author_of_year
[yy
]
549 authors
= getkeyssortedbyvalues(authordict
)
551 commits
= data
.author_of_year
[yy
][authors
[0]]
552 f
.write('<tr><td>%s</td><td>%s</td><td>%d (%.2f%% of %d)</td></tr>' % (yy
, authors
[0], commits
, (100 * commits
) / data
.commits_by_year
[yy
], data
.commits_by_year
[yy
]))
555 f
.write('</body></html>')
560 f
= open(path
+ '/files.html', 'w')
562 f
.write('<h1>Files</h1>')
566 f
.write('<dt>Total files</dt><dd>%d</dd>' % data
.getTotalFiles())
567 f
.write('<dt>Total lines</dt><dd>%d</dd>' % data
.getTotalLOC())
568 f
.write('<dt>Average file size</dt><dd>%.2f bytes</dd>' % ((100.0 * data
.getTotalLOC()) / data
.getTotalFiles()))
571 # Files :: File count by date
572 f
.write(html_header(2, 'File count by date'))
574 fg
= open(path
+ '/files_by_date.dat', 'w')
575 for stamp
in sorted(data
.files_by_stamp
.keys()):
576 fg
.write('%s %d\n' % (datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d'), data
.files_by_stamp
[stamp
]))
579 f
.write('<img src="files_by_date.png" alt="Files by Date" />')
581 #f.write('<h2>Average file size by date</h2>')
583 # Files :: Extensions
584 f
.write(html_header(2, 'Extensions'))
585 f
.write('<table><tr><th>Extension</th><th>Files (%)</th><th>Lines (%)</th><th>Lines/file</th></tr>')
586 for ext
in sorted(data
.extensions
.keys()):
587 files
= data
.extensions
[ext
]['files']
588 lines
= data
.extensions
[ext
]['lines']
589 f
.write('<tr><td>%s</td><td>%d (%.2f%%)</td><td>%d (%.2f%%)</td><td>%d</td></tr>' % (ext
, files
, (100.0 * files
) / data
.getTotalFiles(), lines
, (100.0 * lines
) / data
.getTotalLOC(), lines
/ files
))
592 f
.write('</body></html>')
597 f
= open(path
+ '/lines.html', 'w')
599 f
.write('<h1>Lines</h1>')
603 f
.write('<dt>Total lines</dt><dd>%d</dd>' % data
.getTotalLOC())
606 f
.write(html_header(2, 'Lines of Code'))
607 f
.write('<img src="lines_of_code.png" />')
609 fg
= open(path
+ '/lines_of_code.dat', 'w')
610 for stamp
in sorted(data
.changes_by_date
.keys()):
611 fg
.write('%d %d\n' % (stamp
, data
.changes_by_date
[stamp
]['lines']))
614 f
.write('</body></html>')
619 f
= open(path
+ '/tags.html', 'w')
621 f
.write('<h1>Tags</h1>')
625 f
.write('<dt>Total tags</dt><dd>%d</dd>' % len(data
.tags
))
626 if len(data
.tags
) > 0:
627 f
.write('<dt>Average commits per tag</dt><dd>%.2f</dd>' % (data
.getTotalCommits() / len(data
.tags
)))
631 f
.write('<tr><th>Name</th><th>Date</th></tr>')
632 # sort the tags by date desc
633 tags_sorted_by_date_desc
= map(lambda el
: el
[1], reversed(sorted(map(lambda el
: (el
[1]['date'], el
[0]), data
.tags
.items()))))
634 for tag
in tags_sorted_by_date_desc
:
635 f
.write('<tr><td>%s</td><td>%s</td></tr>' % (tag
, data
.tags
[tag
]['date']))
638 f
.write('</body></html>')
641 self
.createGraphs(path
)
644 def createGraphs(self
, path
):
645 print 'Generating graphs...'
648 f
= open(path
+ '/hour_of_day.plot', 'w')
649 f
.write(GNUPLOT_COMMON
)
652 set output 'hour_of_day.png'
654 set xrange [0.5:24.5]
657 plot 'hour_of_day.dat' using 1:2:(0.5) w boxes fs solid
662 f
= open(path
+ '/day_of_week.plot', 'w')
663 f
.write(GNUPLOT_COMMON
)
666 set output 'day_of_week.png'
671 plot 'day_of_week.dat' using 1:2:(0.5) w boxes fs solid
676 f
= open(path
+ '/month_of_year.plot', 'w')
677 f
.write(GNUPLOT_COMMON
)
680 set output 'month_of_year.png'
682 set xrange [0.5:12.5]
685 plot 'month_of_year.dat' using 1:2:(0.5) w boxes fs solid
689 # commits_by_year_month
690 f
= open(path
+ '/commits_by_year_month.plot', 'w')
691 f
.write(GNUPLOT_COMMON
)
694 set output 'commits_by_year_month.png'
699 set xtics rotate by 90 15768000
701 plot 'commits_by_year_month.dat' using 1:2:(0.5) w boxes fs solid
706 f
= open(path
+ '/commits_by_year.plot', 'w')
707 f
.write(GNUPLOT_COMMON
)
710 set output 'commits_by_year.png'
714 plot 'commits_by_year.dat' using 1:2:(0.5) w boxes fs solid
719 f
= open(path
+ '/files_by_date.plot', 'w')
720 f
.write(GNUPLOT_COMMON
)
723 set output 'files_by_date.png'
726 set timefmt "%Y-%m-%d"
727 set format x "%Y-%m-%d"
729 set xtics rotate by 90
730 plot 'files_by_date.dat' using 1:2 smooth csplines
735 f
= open(path
+ '/lines_of_code.plot', 'w')
736 f
.write(GNUPLOT_COMMON
)
739 set output 'lines_of_code.png'
743 set format x "%Y-%m-%d"
745 set xtics rotate by 90
746 plot 'lines_of_code.dat' using 1:2 w lines
751 files
= glob
.glob(path
+ '/*.plot')
753 out
= getoutput('gnuplot %s' % f
)
757 def printHeader(self
, f
, title
= ''):
759 """<?xml version="1.0" encoding="UTF-8"?>
760 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
761 <html xmlns="http://www.w3.org/1999/xhtml">
763 <title>GitStats - %s</title>
764 <link rel="stylesheet" href="gitstats.css" type="text/css" />
765 <meta name="generator" content="GitStats" />
770 def printNav(self
, f
):
774 <li><a href="index.html">General</a></li>
775 <li><a href="activity.html">Activity</a></li>
776 <li><a href="authors.html">Authors</a></li>
777 <li><a href="files.html">Files</a></li>
778 <li><a href="lines.html">Lines</a></li>
779 <li><a href="tags.html">Tags</a></li>
786 Usage: gitstats [options] <gitpath> <outputpath>
791 if len(sys
.argv
) < 3:
795 gitpath
= sys
.argv
[1]
796 outputpath
= os
.path
.abspath(sys
.argv
[2])
800 os
.makedirs(outputpath
)
803 if not os
.path
.isdir(outputpath
):
804 print 'FATAL: Output path is not a directory or does not exist'
807 print 'Git path: %s' % gitpath
808 print 'Output path: %s' % outputpath
812 print 'Collecting data...'
813 data
= GitDataCollector()
814 data
.collect(gitpath
)
818 print 'Generating report...'
819 report
= HTMLReportCreator()
820 report
.create(data
, outputpath
)
822 time_end
= time
.time()
823 exectime_internal
= time_end
- time_start
824 print 'Execution time %.5f secs, %.5f secs (%.2f %%) in external commands)' % (exectime_internal
, exectime_external
, (100.0 * exectime_external
) / exectime_internal
)