Workaround for git repository.
[gitstats.git] / gitstats
blob7c4d27eeaa79d4754f5dbc812839be9edaeb4072
1 #!/usr/bin/python
2 # Copyright (c) 2007 Heikki Hokkanen <hoxu@users.sf.net>
3 # GPLv2
4 import commands
5 import datetime
6 import glob
7 import os
8 import re
9 import shutil
10 import sys
11 import time
13 GNUPLOT_COMMON = 'set terminal png transparent\nset size 0.5,0.5\n'
15 def getoutput(cmd, quiet = False):
16 if not quiet:
17 print '>> %s' % cmd
18 output = commands.getoutput(cmd)
19 return output
21 def getkeyssortedbyvalues(dict):
22 return map(lambda el : el[1], sorted(map(lambda el : (el[1], el[0]), dict.items())))
24 # TODO getdictkeyssortedbyvaluekey(dict, key) - eg. dict['author'] = { 'commits' : 512 } - ...key(dict, 'commits')
26 class DataCollector:
27 """Manages data collection from a revision control repository."""
28 def __init__(self):
29 self.stamp_created = time.time()
30 pass
33 # This should be the main function to extract data from the repository.
34 def collect(self, dir):
35 self.dir = dir
38 # : get a dictionary of author
39 def getAuthorInfo(self, author):
40 return None
42 def getActivityByDayOfWeek(self):
43 return {}
45 def getActivityByHourOfDay(self):
46 return {}
49 # Get a list of authors
50 def getAuthors(self):
51 return []
53 def getFirstCommitDate(self):
54 return datetime.datetime.now()
56 def getLastCommitDate(self):
57 return datetime.datetime.now()
59 def getStampCreated(self):
60 return self.stamp_created
62 def getTags(self):
63 return []
65 def getTotalAuthors(self):
66 return -1
68 def getTotalCommits(self):
69 return -1
71 def getTotalFiles(self):
72 return -1
74 def getTotalLOC(self):
75 return -1
77 class GitDataCollector(DataCollector):
78 def collect(self, dir):
79 DataCollector.collect(self, dir)
81 self.total_authors = int(getoutput('git-log |git-shortlog -s |wc -l'))
82 self.total_commits = int(getoutput('git-rev-list HEAD |wc -l'))
83 self.total_files = int(getoutput('git-ls-files |wc -l'))
84 self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l'))
86 self.activity_by_hour_of_day = {} # hour -> commits
87 self.activity_by_day_of_week = {} # day -> commits
88 self.activity_by_month_of_year = {} # month [1-12] -> commits
89 self.activity_by_hour_of_week = {} # weekday -> hour -> commits
91 self.authors = {} # name -> {commits, first_commit_stamp, last_commit_stamp}
93 # author of the month
94 self.author_of_month = {} # month -> author -> commits
95 self.author_of_year = {} # year -> author -> commits
96 self.commits_by_month = {} # month -> commits
97 self.commits_by_year = {} # year -> commits
98 self.first_commit_stamp = 0
99 self.last_commit_stamp = 0
101 # tags
102 self.tags = {}
103 lines = getoutput('git-show-ref --tags').split('\n')
104 for line in lines:
105 if len(line) == 0:
106 continue
107 (hash, tag) = line.split(' ')
108 tag = tag.replace('refs/tags/', '')
109 output = getoutput('git-log "%s" --pretty=format:"%%at %%an" -n 1' % hash)
110 if len(output) > 0:
111 parts = output.split(' ')
112 stamp = 0
113 try:
114 stamp = int(parts[0])
115 except ValueError:
116 stamp = 0
117 self.tags[tag] = { 'stamp': stamp, 'hash' : hash, 'date' : datetime.datetime.fromtimestamp(stamp).strftime('%Y-%m-%d') }
118 pass
120 # Collect revision statistics
121 # Outputs "<stamp> <author>"
122 lines = getoutput('git-rev-list --pretty=format:"%at %an" HEAD |grep -v ^commit').split('\n')
123 for line in lines:
124 # linux-2.6 says "<unknown>" for one line O_o
125 parts = line.split(' ')
126 author = ''
127 try:
128 stamp = int(parts[0])
129 except ValueError:
130 stamp = 0
131 if len(parts) > 1:
132 author = ' '.join(parts[1:])
133 date = datetime.datetime.fromtimestamp(float(stamp))
135 # First and last commit stamp
136 if self.last_commit_stamp == 0:
137 self.last_commit_stamp = stamp
138 self.first_commit_stamp = stamp
140 # activity
141 # hour
142 hour = date.hour
143 if hour in self.activity_by_hour_of_day:
144 self.activity_by_hour_of_day[hour] += 1
145 else:
146 self.activity_by_hour_of_day[hour] = 1
148 # day of week
149 day = date.weekday()
150 if day in self.activity_by_day_of_week:
151 self.activity_by_day_of_week[day] += 1
152 else:
153 self.activity_by_day_of_week[day] = 1
155 # hour of week
156 if day not in self.activity_by_hour_of_week:
157 self.activity_by_hour_of_week[day] = {}
158 if hour not in self.activity_by_hour_of_week[day]:
159 self.activity_by_hour_of_week[day][hour] = 1
160 else:
161 self.activity_by_hour_of_week[day][hour] += 1
163 # month of year
164 month = date.month
165 if month in self.activity_by_month_of_year:
166 self.activity_by_month_of_year[month] += 1
167 else:
168 self.activity_by_month_of_year[month] = 1
170 # author stats
171 if author not in self.authors:
172 self.authors[author] = {}
173 # TODO commits
174 if 'last_commit_stamp' not in self.authors[author]:
175 self.authors[author]['last_commit_stamp'] = stamp
176 self.authors[author]['first_commit_stamp'] = stamp
177 if 'commits' in self.authors[author]:
178 self.authors[author]['commits'] += 1
179 else:
180 self.authors[author]['commits'] = 1
182 # author of the month/year
183 yymm = datetime.datetime.fromtimestamp(stamp).strftime('%Y-%m')
184 if yymm in self.author_of_month:
185 if author in self.author_of_month[yymm]:
186 self.author_of_month[yymm][author] += 1
187 else:
188 self.author_of_month[yymm][author] = 1
189 else:
190 self.author_of_month[yymm] = {}
191 self.author_of_month[yymm][author] = 1
192 if yymm in self.commits_by_month:
193 self.commits_by_month[yymm] += 1
194 else:
195 self.commits_by_month[yymm] = 1
197 yy = datetime.datetime.fromtimestamp(stamp).year
198 if yy in self.author_of_year:
199 if author in self.author_of_year[yy]:
200 self.author_of_year[yy][author] += 1
201 else:
202 self.author_of_year[yy][author] = 1
203 else:
204 self.author_of_year[yy] = {}
205 self.author_of_year[yy][author] = 1
206 if yy in self.commits_by_year:
207 self.commits_by_year[yy] += 1
208 else:
209 self.commits_by_year[yy] = 1
211 # outputs "<stamp> <files>" for each revision
212 self.files_by_stamp = {} # stamp -> files
213 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')
214 for line in lines:
215 parts = line.split(' ')
216 if len(parts) != 2:
217 continue
218 (stamp, files) = parts[0:2]
219 self.files_by_stamp[int(stamp)] = int(files)
221 # extensions
222 self.extensions = {} # extension -> files, lines
223 lines = getoutput('git-ls-files').split('\n')
224 for line in lines:
225 base = os.path.basename(line)
226 if base.find('.') == -1:
227 ext = ''
228 else:
229 ext = base[(base.rfind('.') + 1):]
231 if ext not in self.extensions:
232 self.extensions[ext] = {'files': 0, 'lines': 0}
234 self.extensions[ext]['files'] += 1
235 try:
236 self.extensions[ext]['lines'] += int(getoutput('wc -l < %s' % line, quiet = True))
237 except:
238 print 'Warning: Could not count lines for file "%s"' % line
240 def getActivityByDayOfWeek(self):
241 return self.activity_by_day_of_week
243 def getActivityByHourOfDay(self):
244 return self.activity_by_hour_of_day
246 def getAuthorInfo(self, author):
247 a = self.authors[author]
249 commits = a['commits']
250 commits_frac = (100 * float(commits)) / self.getTotalCommits()
251 date_first = datetime.datetime.fromtimestamp(a['first_commit_stamp'])
252 date_last = datetime.datetime.fromtimestamp(a['last_commit_stamp'])
253 delta = date_last - date_first
255 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 }
256 return res
258 def getAuthors(self):
259 return self.authors.keys()
261 def getFirstCommitDate(self):
262 return datetime.datetime.fromtimestamp(self.first_commit_stamp)
264 def getLastCommitDate(self):
265 return datetime.datetime.fromtimestamp(self.last_commit_stamp)
267 def getTags(self):
268 lines = getoutput('git-show-ref --tags |cut -d/ -f3')
269 return lines.split('\n')
271 def getTagDate(self, tag):
272 return self.revToDate('tags/' + tag)
274 def getTotalAuthors(self):
275 return self.total_authors
277 def getTotalCommits(self):
278 return self.total_commits
280 def getTotalFiles(self):
281 return self.total_files
283 def getTotalLOC(self):
284 return self.total_lines
286 def revToDate(self, rev):
287 stamp = int(getoutput('git-log --pretty=format:%%at "%s" -n 1' % rev))
288 return datetime.datetime.fromtimestamp(stamp).strftime('%Y-%m-%d')
290 class ReportCreator:
291 """Creates the actual report based on given data."""
292 def __init__(self):
293 pass
295 def create(self, data, path):
296 self.data = data
297 self.path = path
299 class HTMLReportCreator(ReportCreator):
300 def create(self, data, path):
301 ReportCreator.create(self, data, path)
303 # TODO copy the CSS if it does not exist
304 if not os.path.exists(path + '/gitstats.css'):
305 #shutil.copyfile('')
306 pass
308 f = open(path + "/index.html", 'w')
309 format = '%Y-%m-%d %H:%m:%S'
310 self.printHeader(f)
312 f.write('<h1>GitStats</h1>')
314 self.printNav(f)
316 f.write('<dl>');
317 f.write('<dt>Generated</dt><dd>%s (in %d seconds)</dd>' % (datetime.datetime.now().strftime(format), time.time() - data.getStampCreated()));
318 f.write('<dt>Report Period</dt><dd>%s to %s</dd>' % (data.getFirstCommitDate().strftime(format), data.getLastCommitDate().strftime(format)))
319 f.write('<dt>Total Files</dt><dd>%s</dd>' % data.getTotalFiles())
320 f.write('<dt>Total Lines of Code</dt><dd>%s</dd>' % data.getTotalLOC())
321 f.write('<dt>Total Commits</dt><dd>%s</dd>' % data.getTotalCommits())
322 f.write('<dt>Authors</dt><dd>%s</dd>' % data.getTotalAuthors())
323 f.write('</dl>');
325 f.write('</body>\n</html>');
326 f.close()
329 # Activity
330 f = open(path + '/activity.html', 'w')
331 self.printHeader(f)
332 f.write('<h1>Activity</h1>')
333 self.printNav(f)
335 f.write('<h2>Last 30 days</h2>')
337 f.write('<h2>Last 12 months</h2>')
339 # Hour of Day
340 f.write('\n<h2>Hour of Day</h2>\n\n')
341 hour_of_day = data.getActivityByHourOfDay()
342 f.write('<table><tr><th>Hour</th>')
343 for i in range(1, 25):
344 f.write('<th>%d</th>' % i)
345 f.write('</tr>\n<tr><th>Commits</th>')
346 fp = open(path + '/hour_of_day.dat', 'w')
347 for i in range(0, 24):
348 if i in hour_of_day:
349 f.write('<td>%d</td>' % hour_of_day[i])
350 fp.write('%d %d\n' % (i, hour_of_day[i]))
351 else:
352 f.write('<td>0</td>')
353 fp.write('%d 0\n' % i)
354 fp.close()
355 f.write('</tr>\n<tr><th>%</th>')
356 totalcommits = data.getTotalCommits()
357 for i in range(0, 24):
358 if i in hour_of_day:
359 f.write('<td>%.2f</td>' % ((100.0 * hour_of_day[i]) / totalcommits))
360 else:
361 f.write('<td>0.00</td>')
362 f.write('</tr></table>')
363 f.write('<img src="hour_of_day.png" alt="Hour of Day" />')
364 fg = open(path + '/hour_of_day.dat', 'w')
365 for i in range(0, 24):
366 if i in hour_of_day:
367 fg.write('%d %d\n' % (i + 1, hour_of_day[i]))
368 else:
369 fg.write('%d 0\n' % (i + 1))
370 fg.close()
372 # Day of Week
373 f.write('\n<h2>Day of Week</h2>\n\n')
374 day_of_week = data.getActivityByDayOfWeek()
375 f.write('<div class="vtable"><table>')
376 f.write('<tr><th>Day</th><th>Total (%)</th></tr>')
377 fp = open(path + '/day_of_week.dat', 'w')
378 for d in range(0, 7):
379 fp.write('%d %d\n' % (d + 1, day_of_week[d]))
380 f.write('<tr>')
381 f.write('<th>%d</th>' % (d + 1))
382 if d in day_of_week:
383 f.write('<td>%d (%.2f%%)</td>' % (day_of_week[d], (100.0 * day_of_week[d]) / totalcommits))
384 else:
385 f.write('<td>0</td>')
386 f.write('</tr>')
387 f.write('</table></div>')
388 f.write('<img src="day_of_week.png" alt="Day of Week" />')
389 fp.close()
391 # Hour of Week
392 f.write('\n<h2>Hour of Week</h2>\n\n')
393 f.write('<table>')
395 f.write('<tr><th>Weekday</th>')
396 for hour in range(0, 24):
397 f.write('<th>%d</th>' % (hour + 1))
398 f.write('</tr>')
400 for weekday in range(0, 7):
401 f.write('<tr><th>%d</th>' % (weekday + 1))
402 for hour in range(0, 24):
403 try:
404 commits = data.activity_by_hour_of_week[weekday][hour]
405 except KeyError:
406 commits = 0
407 if commits != 0:
408 f.write('<td>%d</td>' % commits)
409 else:
410 f.write('<td></td>')
411 f.write('</tr>')
413 f.write('</table>')
415 # Month of Year
416 f.write('\n<h2>Month of Year</h2>\n\n')
417 f.write('<div class="vtable"><table>')
418 f.write('<tr><th>Month</th><th>Commits (%)</th></tr>')
419 fp = open (path + '/month_of_year.dat', 'w')
420 for mm in range(1, 13):
421 commits = 0
422 if mm in data.activity_by_month_of_year:
423 commits = data.activity_by_month_of_year[mm]
424 f.write('<tr><td>%d</td><td>%d (%.2f %%)</td></tr>' % (mm, commits, (100.0 * commits) / data.getTotalCommits()))
425 fp.write('%d %d\n' % (mm, commits))
426 fp.close()
427 f.write('</table></div>')
428 f.write('<img src="month_of_year.png" alt="Month of Year" />')
430 # Commits by year/month
431 f.write('<h2>Commits by year/month</h2>')
432 f.write('<div class="vtable"><table><tr><th>Month</th><th>Commits</th></tr>')
433 for yymm in reversed(sorted(data.commits_by_month.keys())):
434 f.write('<tr><td>%s</td><td>%d</td></tr>' % (yymm, data.commits_by_month[yymm]))
435 f.write('</table></div>')
436 f.write('<img src="commits_by_year_month.png" alt="Commits by year/month" />')
437 fg = open(path + '/commits_by_year_month.dat', 'w')
438 for yymm in sorted(data.commits_by_month.keys()):
439 fg.write('%s %s\n' % (yymm, data.commits_by_month[yymm]))
440 fg.close()
442 # Commits by year
443 f.write('<h2>Commits by year</h2>')
444 f.write('<div class="vtable"><table><tr><th>Year</th><th>Commits (% of all)</th></tr>')
445 for yy in reversed(sorted(data.commits_by_year.keys())):
446 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()))
447 f.write('</table></div>')
448 f.write('<img src="commits_by_year.png" alt="Commits by Year" />')
449 fg = open(path + '/commits_by_year.dat', 'w')
450 for yy in sorted(data.commits_by_year.keys()):
451 fg.write('%d %d\n' % (yy, data.commits_by_year[yy]))
452 fg.close()
454 f.write('</body></html>')
455 f.close()
458 # Authors
459 f = open(path + '/authors.html', 'w')
460 self.printHeader(f)
462 f.write('<h1>Authors</h1>')
463 self.printNav(f)
465 # Authors :: List of authors
466 f.write('\n<h2>List of authors</h2>\n\n')
468 f.write('<table class="authors">')
469 f.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th><th>Age</th></tr>')
470 for author in sorted(data.getAuthors()):
471 info = data.getAuthorInfo(author)
472 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']))
473 f.write('</table>')
475 # Authors :: Author of Month
476 f.write('\n<h2>Author of Month</h2>\n\n')
477 f.write('<table>')
478 f.write('<tr><th>Month</th><th>Author</th><th>Commits (%)</th></tr>')
479 for yymm in reversed(sorted(data.author_of_month.keys())):
480 authordict = data.author_of_month[yymm]
481 authors = getkeyssortedbyvalues(authordict)
482 authors.reverse()
483 commits = data.author_of_month[yymm][authors[0]]
484 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]))
486 f.write('</table>')
488 f.write('\n<h2>Author of Year</h2>\n\n')
489 f.write('<table><tr><th>Year</th><th>Author</th><th>Commits (%)</th></tr>')
490 for yy in reversed(sorted(data.author_of_year.keys())):
491 authordict = data.author_of_year[yy]
492 authors = getkeyssortedbyvalues(authordict)
493 authors.reverse()
494 commits = data.author_of_year[yy][authors[0]]
495 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]))
496 f.write('</table>')
498 f.write('</body></html>')
499 f.close()
502 # Files
503 f = open(path + '/files.html', 'w')
504 self.printHeader(f)
505 f.write('<h1>Files</h1>')
506 self.printNav(f)
508 f.write('<dl>\n')
509 f.write('<dt>Total files</dt><dd>%d</dd>' % data.getTotalFiles())
510 f.write('<dt>Total lines</dt><dd>%d</dd>' % data.getTotalLOC())
511 f.write('<dt>Average file size</dt><dd>%.2f bytes</dd>' % ((100.0 * data.getTotalLOC()) / data.getTotalFiles()))
512 f.write('</dl>\n')
514 # Files :: File count by date
515 f.write('<h2>File count by date</h2>')
517 fg = open(path + '/files_by_date.dat', 'w')
518 for stamp in sorted(data.files_by_stamp.keys()):
519 fg.write('%s %d\n' % (datetime.datetime.fromtimestamp(stamp).strftime('%Y-%m-%d'), data.files_by_stamp[stamp]))
520 fg.close()
522 f.write('<img src="files_by_date.png" alt="Files by Date" />')
524 #f.write('<h2>Average file size by date</h2>')
526 # Files :: Extensions
527 f.write('\n<h2>Extensions</h2>\n\n')
528 f.write('<table><tr><th>Extension</th><th>Files (%)</th><th>Lines (%)</th><th>Lines/file</th></tr>')
529 for ext in sorted(data.extensions.keys()):
530 files = data.extensions[ext]['files']
531 lines = data.extensions[ext]['lines']
532 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))
533 f.write('</table>')
535 f.write('</body></html>')
536 f.close()
539 # Lines
540 f = open(path + '/lines.html', 'w')
541 self.printHeader(f)
542 f.write('<h1>Lines</h1>')
543 self.printNav(f)
545 f.write('<dl>\n')
546 f.write('<dt>Total lines</dt><dd>%d</dd>' % data.getTotalLOC())
547 f.write('</dl>\n')
549 f.write('</body></html>')
550 f.close()
553 # tags.html
554 f = open(path + '/tags.html', 'w')
555 self.printHeader(f)
556 f.write('<h1>Tags</h1>')
557 self.printNav(f)
559 f.write('<dl>')
560 f.write('<dt>Total tags</dt><dd>%d</dd>' % len(data.tags))
561 if len(data.tags) > 0:
562 f.write('<dt>Average commits per tag</dt><dd>%.2f</dd>' % (data.getTotalCommits() / len(data.tags)))
563 f.write('</dl>')
565 f.write('<table>')
566 f.write('<tr><th>Name</th><th>Date</th></tr>')
567 # sort the tags by date desc
568 tags_sorted_by_date_desc = map(lambda el : el[1], reversed(sorted(map(lambda el : (el[1]['date'], el[0]), data.tags.items()))))
569 for tag in tags_sorted_by_date_desc:
570 f.write('<tr><td>%s</td><td>%s</td></tr>' % (tag, data.tags[tag]['date']))
571 f.write('</table>')
573 f.write('</body></html>')
574 f.close()
576 self.createGraphs(path)
577 pass
579 def createGraphs(self, path):
580 print 'Generating graphs...'
582 # hour of day
583 f = open(path + '/hour_of_day.plot', 'w')
584 f.write(GNUPLOT_COMMON)
585 f.write(
587 set output 'hour_of_day.png'
588 unset key
589 set xrange [0.5:24.5]
590 set xtics 4
591 set ylabel "Commits"
592 plot 'hour_of_day.dat' using 1:2:(0.5) w boxes fs solid
593 """)
594 f.close()
596 # day of week
597 f = open(path + '/day_of_week.plot', 'w')
598 f.write(GNUPLOT_COMMON)
599 f.write(
601 set output 'day_of_week.png'
602 unset key
603 set xrange [0.5:7.5]
604 set xtics 1
605 set ylabel "Commits"
606 plot 'day_of_week.dat' using 1:2:(0.5) w boxes fs solid
607 """)
608 f.close()
610 # Month of Year
611 f = open(path + '/month_of_year.plot', 'w')
612 f.write(GNUPLOT_COMMON)
613 f.write(
615 set output 'month_of_year.png'
616 unset key
617 set xrange [0.5:12.5]
618 set xtics 1
619 set ylabel "Commits"
620 plot 'month_of_year.dat' using 1:2:(0.5) w boxes fs solid
621 """)
622 f.close()
624 # commits_by_year_month
625 f = open(path + '/commits_by_year_month.plot', 'w')
626 f.write(GNUPLOT_COMMON)
627 f.write(
629 set output 'commits_by_year_month.png'
630 unset key
631 set xdata time
632 set timefmt "%Y-%m"
633 set format x "%Y-%m"
634 set xtics rotate by 90 15768000
635 set ylabel "Commits"
636 plot 'commits_by_year_month.dat' using 1:2:(0.5) w boxes fs solid
637 """)
638 f.close()
640 # commits_by_year
641 f = open(path + '/commits_by_year.plot', 'w')
642 f.write(GNUPLOT_COMMON)
643 f.write(
645 set output 'commits_by_year.png'
646 unset key
647 set xtics 1
648 set ylabel "Commits"
649 plot 'commits_by_year.dat' using 1:2:(0.5) w boxes fs solid
650 """)
651 f.close()
653 # Files by date
654 f = open(path + '/files_by_date.plot', 'w')
655 f.write(GNUPLOT_COMMON)
656 f.write(
658 set output 'files_by_date.png'
659 unset key
660 set xdata time
661 set timefmt "%Y-%m-%d"
662 set format x "%Y-%m-%d"
663 set ylabel "Files"
664 set xtics rotate by 90
665 plot 'files_by_date.dat' using 1:2 smooth csplines
666 """)
667 f.close()
669 os.chdir(path)
670 files = glob.glob(path + '/*.plot')
671 for f in files:
672 print '>> gnuplot %s' % os.path.basename(f)
673 os.system('gnuplot %s' % f)
675 def printHeader(self, f):
676 f.write(
677 """<?xml version="1.0" encoding="UTF-8"?>
678 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
679 <html xmlns="http://www.w3.org/1999/xhtml">
680 <head>
681 <title>GitStats</title>
682 <link rel="stylesheet" href="gitstats.css" type="text/css" />
683 <meta name="generator" content="GitStats" />
684 </head>
685 <body>
686 """)
688 def printNav(self, f):
689 f.write("""
690 <div class="nav">
691 <ul>
692 <li><a href="index.html">General</a></li>
693 <li><a href="activity.html">Activity</a></li>
694 <li><a href="authors.html">Authors</a></li>
695 <li><a href="files.html">Files</a></li>
696 <li><a href="lines.html">Lines</a></li>
697 <li><a href="tags.html">Tags</a></li>
698 </ul>
699 </div>
700 """)
703 usage = """
704 Usage: gitstats [options] <gitpath> <outputpath>
706 Options:
709 if len(sys.argv) < 3:
710 print usage
711 sys.exit(0)
713 gitpath = sys.argv[1]
714 outputpath = os.path.abspath(sys.argv[2])
716 try:
717 os.makedirs(outputpath)
718 except OSError:
719 pass
720 if not os.path.isdir(outputpath):
721 print 'FATAL: Output path is not a directory or does not exist'
722 sys.exit(1)
724 print 'Git path: %s' % gitpath
725 print 'Output path: %s' % outputpath
727 os.chdir(gitpath)
729 print 'Collecting data...'
730 data = GitDataCollector()
731 data.collect(gitpath)
733 print 'Generating report...'
734 report = HTMLReportCreator()
735 report.create(data, outputpath)