More todo items.
[gitstats.git] / gitstats
blob5470d6952b61445e1881ebadce7192e48e89c411
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 # FIXME filenames with spaces or special characters are broken
237 self.extensions[ext]['lines'] += int(getoutput('wc -l < %s' % line, quiet = True))
238 except:
239 print 'Warning: Could not count lines for file "%s"' % line
241 def getActivityByDayOfWeek(self):
242 return self.activity_by_day_of_week
244 def getActivityByHourOfDay(self):
245 return self.activity_by_hour_of_day
247 def getAuthorInfo(self, author):
248 a = self.authors[author]
250 commits = a['commits']
251 commits_frac = (100 * float(commits)) / self.getTotalCommits()
252 date_first = datetime.datetime.fromtimestamp(a['first_commit_stamp'])
253 date_last = datetime.datetime.fromtimestamp(a['last_commit_stamp'])
254 delta = date_last - date_first
256 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 }
257 return res
259 def getAuthors(self):
260 return self.authors.keys()
262 def getFirstCommitDate(self):
263 return datetime.datetime.fromtimestamp(self.first_commit_stamp)
265 def getLastCommitDate(self):
266 return datetime.datetime.fromtimestamp(self.last_commit_stamp)
268 def getTags(self):
269 lines = getoutput('git-show-ref --tags |cut -d/ -f3')
270 return lines.split('\n')
272 def getTagDate(self, tag):
273 return self.revToDate('tags/' + tag)
275 def getTotalAuthors(self):
276 return self.total_authors
278 def getTotalCommits(self):
279 return self.total_commits
281 def getTotalFiles(self):
282 return self.total_files
284 def getTotalLOC(self):
285 return self.total_lines
287 def revToDate(self, rev):
288 stamp = int(getoutput('git-log --pretty=format:%%at "%s" -n 1' % rev))
289 return datetime.datetime.fromtimestamp(stamp).strftime('%Y-%m-%d')
291 class ReportCreator:
292 """Creates the actual report based on given data."""
293 def __init__(self):
294 pass
296 def create(self, data, path):
297 self.data = data
298 self.path = path
300 def html_linkify(text):
301 return text.lower().replace(' ', '_')
303 def html_header(level, text):
304 name = html_linkify(text)
305 return '\n<h%d><a href="#%s" name="%s">%s</a></h%d>\n\n' % (level, name, name, text, level)
307 class HTMLReportCreator(ReportCreator):
308 def create(self, data, path):
309 ReportCreator.create(self, data, path)
311 # TODO copy the CSS if it does not exist
312 if not os.path.exists(path + '/gitstats.css'):
313 #shutil.copyfile('')
314 pass
316 f = open(path + "/index.html", 'w')
317 format = '%Y-%m-%d %H:%m:%S'
318 self.printHeader(f)
320 f.write('<h1>GitStats</h1>')
322 self.printNav(f)
324 f.write('<dl>');
325 f.write('<dt>Generated</dt><dd>%s (in %d seconds)</dd>' % (datetime.datetime.now().strftime(format), time.time() - data.getStampCreated()));
326 f.write('<dt>Report Period</dt><dd>%s to %s</dd>' % (data.getFirstCommitDate().strftime(format), data.getLastCommitDate().strftime(format)))
327 f.write('<dt>Total Files</dt><dd>%s</dd>' % data.getTotalFiles())
328 f.write('<dt>Total Lines of Code</dt><dd>%s</dd>' % data.getTotalLOC())
329 f.write('<dt>Total Commits</dt><dd>%s</dd>' % data.getTotalCommits())
330 f.write('<dt>Authors</dt><dd>%s</dd>' % data.getTotalAuthors())
331 f.write('</dl>');
333 f.write('</body>\n</html>');
334 f.close()
337 # Activity
338 f = open(path + '/activity.html', 'w')
339 self.printHeader(f)
340 f.write('<h1>Activity</h1>')
341 self.printNav(f)
343 #f.write('<h2>Last 30 days</h2>')
345 #f.write('<h2>Last 12 months</h2>')
347 # Hour of Day
348 f.write(html_header(2, 'Hour of Day'))
349 hour_of_day = data.getActivityByHourOfDay()
350 f.write('<table><tr><th>Hour</th>')
351 for i in range(1, 25):
352 f.write('<th>%d</th>' % i)
353 f.write('</tr>\n<tr><th>Commits</th>')
354 fp = open(path + '/hour_of_day.dat', 'w')
355 for i in range(0, 24):
356 if i in hour_of_day:
357 f.write('<td>%d</td>' % hour_of_day[i])
358 fp.write('%d %d\n' % (i, hour_of_day[i]))
359 else:
360 f.write('<td>0</td>')
361 fp.write('%d 0\n' % i)
362 fp.close()
363 f.write('</tr>\n<tr><th>%</th>')
364 totalcommits = data.getTotalCommits()
365 for i in range(0, 24):
366 if i in hour_of_day:
367 f.write('<td>%.2f</td>' % ((100.0 * hour_of_day[i]) / totalcommits))
368 else:
369 f.write('<td>0.00</td>')
370 f.write('</tr></table>')
371 f.write('<img src="hour_of_day.png" alt="Hour of Day" />')
372 fg = open(path + '/hour_of_day.dat', 'w')
373 for i in range(0, 24):
374 if i in hour_of_day:
375 fg.write('%d %d\n' % (i + 1, hour_of_day[i]))
376 else:
377 fg.write('%d 0\n' % (i + 1))
378 fg.close()
380 # Day of Week
381 f.write(html_header(2, 'Day of Week'))
382 day_of_week = data.getActivityByDayOfWeek()
383 f.write('<div class="vtable"><table>')
384 f.write('<tr><th>Day</th><th>Total (%)</th></tr>')
385 fp = open(path + '/day_of_week.dat', 'w')
386 for d in range(0, 7):
387 fp.write('%d %d\n' % (d + 1, day_of_week[d]))
388 f.write('<tr>')
389 f.write('<th>%d</th>' % (d + 1))
390 if d in day_of_week:
391 f.write('<td>%d (%.2f%%)</td>' % (day_of_week[d], (100.0 * day_of_week[d]) / totalcommits))
392 else:
393 f.write('<td>0</td>')
394 f.write('</tr>')
395 f.write('</table></div>')
396 f.write('<img src="day_of_week.png" alt="Day of Week" />')
397 fp.close()
399 # Hour of Week
400 f.write(html_header(2, 'Hour of Week'))
401 f.write('<table>')
403 f.write('<tr><th>Weekday</th>')
404 for hour in range(0, 24):
405 f.write('<th>%d</th>' % (hour + 1))
406 f.write('</tr>')
408 for weekday in range(0, 7):
409 f.write('<tr><th>%d</th>' % (weekday + 1))
410 for hour in range(0, 24):
411 try:
412 commits = data.activity_by_hour_of_week[weekday][hour]
413 except KeyError:
414 commits = 0
415 if commits != 0:
416 f.write('<td>%d</td>' % commits)
417 else:
418 f.write('<td></td>')
419 f.write('</tr>')
421 f.write('</table>')
423 # Month of Year
424 f.write(html_header(2, 'Month of Year'))
425 f.write('<div class="vtable"><table>')
426 f.write('<tr><th>Month</th><th>Commits (%)</th></tr>')
427 fp = open (path + '/month_of_year.dat', 'w')
428 for mm in range(1, 13):
429 commits = 0
430 if mm in data.activity_by_month_of_year:
431 commits = data.activity_by_month_of_year[mm]
432 f.write('<tr><td>%d</td><td>%d (%.2f %%)</td></tr>' % (mm, commits, (100.0 * commits) / data.getTotalCommits()))
433 fp.write('%d %d\n' % (mm, commits))
434 fp.close()
435 f.write('</table></div>')
436 f.write('<img src="month_of_year.png" alt="Month of Year" />')
438 # Commits by year/month
439 f.write(html_header(2, 'Commits by year/month'))
440 f.write('<div class="vtable"><table><tr><th>Month</th><th>Commits</th></tr>')
441 for yymm in reversed(sorted(data.commits_by_month.keys())):
442 f.write('<tr><td>%s</td><td>%d</td></tr>' % (yymm, data.commits_by_month[yymm]))
443 f.write('</table></div>')
444 f.write('<img src="commits_by_year_month.png" alt="Commits by year/month" />')
445 fg = open(path + '/commits_by_year_month.dat', 'w')
446 for yymm in sorted(data.commits_by_month.keys()):
447 fg.write('%s %s\n' % (yymm, data.commits_by_month[yymm]))
448 fg.close()
450 # Commits by year
451 f.write(html_header(2, 'Commits by Year'))
452 f.write('<div class="vtable"><table><tr><th>Year</th><th>Commits (% of all)</th></tr>')
453 for yy in reversed(sorted(data.commits_by_year.keys())):
454 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()))
455 f.write('</table></div>')
456 f.write('<img src="commits_by_year.png" alt="Commits by Year" />')
457 fg = open(path + '/commits_by_year.dat', 'w')
458 for yy in sorted(data.commits_by_year.keys()):
459 fg.write('%d %d\n' % (yy, data.commits_by_year[yy]))
460 fg.close()
462 f.write('</body></html>')
463 f.close()
466 # Authors
467 f = open(path + '/authors.html', 'w')
468 self.printHeader(f)
470 f.write('<h1>Authors</h1>')
471 self.printNav(f)
473 # Authors :: List of authors
474 f.write(html_header(2, 'List of Authors'))
476 f.write('<table class="authors">')
477 f.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th><th>Age</th></tr>')
478 for author in sorted(data.getAuthors()):
479 info = data.getAuthorInfo(author)
480 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']))
481 f.write('</table>')
483 # Authors :: Author of Month
484 f.write(html_header(2, 'Author of Month'))
485 f.write('<table>')
486 f.write('<tr><th>Month</th><th>Author</th><th>Commits (%)</th></tr>')
487 for yymm in reversed(sorted(data.author_of_month.keys())):
488 authordict = data.author_of_month[yymm]
489 authors = getkeyssortedbyvalues(authordict)
490 authors.reverse()
491 commits = data.author_of_month[yymm][authors[0]]
492 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]))
494 f.write('</table>')
496 f.write(html_header(2, 'Author of Year'))
497 f.write('<table><tr><th>Year</th><th>Author</th><th>Commits (%)</th></tr>')
498 for yy in reversed(sorted(data.author_of_year.keys())):
499 authordict = data.author_of_year[yy]
500 authors = getkeyssortedbyvalues(authordict)
501 authors.reverse()
502 commits = data.author_of_year[yy][authors[0]]
503 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]))
504 f.write('</table>')
506 f.write('</body></html>')
507 f.close()
510 # Files
511 f = open(path + '/files.html', 'w')
512 self.printHeader(f)
513 f.write('<h1>Files</h1>')
514 self.printNav(f)
516 f.write('<dl>\n')
517 f.write('<dt>Total files</dt><dd>%d</dd>' % data.getTotalFiles())
518 f.write('<dt>Total lines</dt><dd>%d</dd>' % data.getTotalLOC())
519 f.write('<dt>Average file size</dt><dd>%.2f bytes</dd>' % ((100.0 * data.getTotalLOC()) / data.getTotalFiles()))
520 f.write('</dl>\n')
522 # Files :: File count by date
523 f.write(html_header(2, 'File count by date'))
525 fg = open(path + '/files_by_date.dat', 'w')
526 for stamp in sorted(data.files_by_stamp.keys()):
527 fg.write('%s %d\n' % (datetime.datetime.fromtimestamp(stamp).strftime('%Y-%m-%d'), data.files_by_stamp[stamp]))
528 fg.close()
530 f.write('<img src="files_by_date.png" alt="Files by Date" />')
532 #f.write('<h2>Average file size by date</h2>')
534 # Files :: Extensions
535 f.write(html_header(2, 'Extensions'))
536 f.write('<table><tr><th>Extension</th><th>Files (%)</th><th>Lines (%)</th><th>Lines/file</th></tr>')
537 for ext in sorted(data.extensions.keys()):
538 files = data.extensions[ext]['files']
539 lines = data.extensions[ext]['lines']
540 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))
541 f.write('</table>')
543 f.write('</body></html>')
544 f.close()
547 # Lines
548 f = open(path + '/lines.html', 'w')
549 self.printHeader(f)
550 f.write('<h1>Lines</h1>')
551 self.printNav(f)
553 f.write('<dl>\n')
554 f.write('<dt>Total lines</dt><dd>%d</dd>' % data.getTotalLOC())
555 f.write('</dl>\n')
557 f.write('</body></html>')
558 f.close()
561 # tags.html
562 f = open(path + '/tags.html', 'w')
563 self.printHeader(f)
564 f.write('<h1>Tags</h1>')
565 self.printNav(f)
567 f.write('<dl>')
568 f.write('<dt>Total tags</dt><dd>%d</dd>' % len(data.tags))
569 if len(data.tags) > 0:
570 f.write('<dt>Average commits per tag</dt><dd>%.2f</dd>' % (data.getTotalCommits() / len(data.tags)))
571 f.write('</dl>')
573 f.write('<table>')
574 f.write('<tr><th>Name</th><th>Date</th></tr>')
575 # sort the tags by date desc
576 tags_sorted_by_date_desc = map(lambda el : el[1], reversed(sorted(map(lambda el : (el[1]['date'], el[0]), data.tags.items()))))
577 for tag in tags_sorted_by_date_desc:
578 f.write('<tr><td>%s</td><td>%s</td></tr>' % (tag, data.tags[tag]['date']))
579 f.write('</table>')
581 f.write('</body></html>')
582 f.close()
584 self.createGraphs(path)
585 pass
587 def createGraphs(self, path):
588 print 'Generating graphs...'
590 # hour of day
591 f = open(path + '/hour_of_day.plot', 'w')
592 f.write(GNUPLOT_COMMON)
593 f.write(
595 set output 'hour_of_day.png'
596 unset key
597 set xrange [0.5:24.5]
598 set xtics 4
599 set ylabel "Commits"
600 plot 'hour_of_day.dat' using 1:2:(0.5) w boxes fs solid
601 """)
602 f.close()
604 # day of week
605 f = open(path + '/day_of_week.plot', 'w')
606 f.write(GNUPLOT_COMMON)
607 f.write(
609 set output 'day_of_week.png'
610 unset key
611 set xrange [0.5:7.5]
612 set xtics 1
613 set ylabel "Commits"
614 plot 'day_of_week.dat' using 1:2:(0.5) w boxes fs solid
615 """)
616 f.close()
618 # Month of Year
619 f = open(path + '/month_of_year.plot', 'w')
620 f.write(GNUPLOT_COMMON)
621 f.write(
623 set output 'month_of_year.png'
624 unset key
625 set xrange [0.5:12.5]
626 set xtics 1
627 set ylabel "Commits"
628 plot 'month_of_year.dat' using 1:2:(0.5) w boxes fs solid
629 """)
630 f.close()
632 # commits_by_year_month
633 f = open(path + '/commits_by_year_month.plot', 'w')
634 f.write(GNUPLOT_COMMON)
635 f.write(
637 set output 'commits_by_year_month.png'
638 unset key
639 set xdata time
640 set timefmt "%Y-%m"
641 set format x "%Y-%m"
642 set xtics rotate by 90 15768000
643 set ylabel "Commits"
644 plot 'commits_by_year_month.dat' using 1:2:(0.5) w boxes fs solid
645 """)
646 f.close()
648 # commits_by_year
649 f = open(path + '/commits_by_year.plot', 'w')
650 f.write(GNUPLOT_COMMON)
651 f.write(
653 set output 'commits_by_year.png'
654 unset key
655 set xtics 1
656 set ylabel "Commits"
657 plot 'commits_by_year.dat' using 1:2:(0.5) w boxes fs solid
658 """)
659 f.close()
661 # Files by date
662 f = open(path + '/files_by_date.plot', 'w')
663 f.write(GNUPLOT_COMMON)
664 f.write(
666 set output 'files_by_date.png'
667 unset key
668 set xdata time
669 set timefmt "%Y-%m-%d"
670 set format x "%Y-%m-%d"
671 set ylabel "Files"
672 set xtics rotate by 90
673 plot 'files_by_date.dat' using 1:2 smooth csplines
674 """)
675 f.close()
677 os.chdir(path)
678 files = glob.glob(path + '/*.plot')
679 for f in files:
680 print '>> gnuplot %s' % os.path.basename(f)
681 os.system('gnuplot %s' % f)
683 def printHeader(self, f):
684 f.write(
685 """<?xml version="1.0" encoding="UTF-8"?>
686 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
687 <html xmlns="http://www.w3.org/1999/xhtml">
688 <head>
689 <title>GitStats</title>
690 <link rel="stylesheet" href="gitstats.css" type="text/css" />
691 <meta name="generator" content="GitStats" />
692 </head>
693 <body>
694 """)
696 def printNav(self, f):
697 f.write("""
698 <div class="nav">
699 <ul>
700 <li><a href="index.html">General</a></li>
701 <li><a href="activity.html">Activity</a></li>
702 <li><a href="authors.html">Authors</a></li>
703 <li><a href="files.html">Files</a></li>
704 <li><a href="lines.html">Lines</a></li>
705 <li><a href="tags.html">Tags</a></li>
706 </ul>
707 </div>
708 """)
711 usage = """
712 Usage: gitstats [options] <gitpath> <outputpath>
714 Options:
717 if len(sys.argv) < 3:
718 print usage
719 sys.exit(0)
721 gitpath = sys.argv[1]
722 outputpath = os.path.abspath(sys.argv[2])
724 try:
725 os.makedirs(outputpath)
726 except OSError:
727 pass
728 if not os.path.isdir(outputpath):
729 print 'FATAL: Output path is not a directory or does not exist'
730 sys.exit(1)
732 print 'Git path: %s' % gitpath
733 print 'Output path: %s' % outputpath
735 os.chdir(gitpath)
737 print 'Collecting data...'
738 data = GitDataCollector()
739 data.collect(gitpath)
741 print 'Generating report...'
742 report = HTMLReportCreator()
743 report.create(data, outputpath)