This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually working commit timeline code.
- Loading branch information
0 parents
commit 8475f65
Showing
3 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.*.swp | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,263 @@ | ||
#! /usr/bin/env python | ||
|
||
colors = [ | ||
"black", | ||
"blue", | ||
"green", | ||
"red", | ||
"darkviolet", | ||
"orange", | ||
"brown", | ||
"magenta", | ||
"navy", | ||
] | ||
|
||
|
||
def make_commit_xml(subdirs, url_pattern): | ||
import sys | ||
from os import getcwd | ||
from os.path import join, basename | ||
from subprocess import Popen | ||
from git import Repo | ||
from xml.dom.minidom import Document | ||
from time import asctime | ||
|
||
doc = Document() | ||
data = doc.createElement("data") | ||
doc.appendChild(data) | ||
|
||
for i, subdir in enumerate(subdirs): | ||
subdir_base = basename(subdir) | ||
|
||
project_color = colors[i % len(colors)] | ||
|
||
repo = Repo(join(getcwd(), subdir)) | ||
|
||
cnt = repo.commit_count() | ||
|
||
for commit in repo.commits(max_count=cnt): | ||
com_xml = doc.createElement("event") | ||
data.appendChild(com_xml) | ||
msg = commit.message.split("\n") | ||
|
||
title = msg[0] | ||
|
||
short_title = title | ||
if len(subdirs) > 1: | ||
short_title = "[%s] %s" % (subdir_base, short_title) | ||
|
||
if len(short_title) > 25: | ||
short_title = short_title[:23]+"..." | ||
|
||
com_xml.setAttribute("start", asctime(commit.committed_date)) | ||
com_xml.setAttribute("title", short_title) | ||
com_xml.setAttribute("caption", title) | ||
com_xml.setAttribute("color", project_color) | ||
com_xml.setAttribute("link", url_pattern % { | ||
"project": subdir_base, | ||
"commit": commit.id, | ||
}) | ||
|
||
descr = "Project:%s<br>Author: %s<br>%s" % ( | ||
subdir_base, | ||
commit.committer, | ||
"\n".join(msg[1:])) | ||
com_txt = doc.createTextNode(descr) | ||
com_xml.appendChild(com_txt) | ||
|
||
return doc.toprettyxml(indent=" ") | ||
|
||
|
||
|
||
|
||
def erase_dir(dir): | ||
from os import listdir, unlink, rmdir | ||
from os.path import join | ||
for name in listdir(dir): | ||
unlink(join(dir, name)) | ||
rmdir(dir) | ||
|
||
|
||
|
||
|
||
TL_JS = """ | ||
var tl; | ||
var resize_timer_id = null; | ||
function on_load() | ||
{ | ||
var event_source = new Timeline.DefaultEventSource(0); | ||
var band_infos = [ | ||
Timeline.createBandInfo({ | ||
width: "90%", | ||
eventSource: event_source, | ||
intervalUnit: Timeline.DateTime.WEEK, | ||
intervalPixels: 250, | ||
}), | ||
Timeline.createBandInfo({ | ||
layout: "overview", | ||
width: "10%", | ||
trackHeight: 0.5, | ||
trackGap: 0.2, | ||
eventSource: event_source, | ||
intervalUnit: Timeline.DateTime.MONTH, | ||
intervalPixels: 50 | ||
}), | ||
]; | ||
band_infos[1].syncWith = 0; | ||
band_infos[1].highlight = true; | ||
tl = Timeline.create( | ||
document.getElementById("commit-timeline"), | ||
band_infos, | ||
Timeline.HORIZONTAL); | ||
Timeline.loadXML("commits.xml", | ||
function(xml, url) { event_source.loadXML(xml, url); } | ||
); | ||
} | ||
function on_resize() | ||
{ | ||
if (resize_timer_id == null) { | ||
resize_timer_id = window.setTimeout(function() { | ||
resize_timer_id = null; | ||
tl.layout(); | ||
}, 500); | ||
} | ||
} | ||
function fill_info_bubble(evt, elmt, theme, labeller) | ||
{ | ||
var doc = elmt.ownerDocument; | ||
var link = evt.getLink(); | ||
var divTitle = doc.createElement("div"); | ||
var textTitle = doc.createTextNode(evt._title); | ||
if (link != null) { | ||
var a = doc.createElement("a"); | ||
a.href = link; | ||
a.appendChild(textTitle); | ||
divTitle.appendChild(a); | ||
} else { | ||
divTitle.appendChild(textTitle); | ||
} | ||
theme.event.bubble.titleStyler(divTitle); | ||
elmt.appendChild(divTitle); | ||
var divBody = doc.createElement("div"); | ||
evt.fillDescription(divBody); | ||
theme.event.bubble.bodyStyler(divBody); | ||
elmt.appendChild(divBody); | ||
var divTime = doc.createElement("div"); | ||
evt.fillTime(divTime, labeller); | ||
theme.event.bubble.timeStyler(divTime); | ||
elmt.appendChild(divTime); | ||
} | ||
Timeline.OriginalEventPainter.prototype._showBubble = function(x, y, evt) | ||
{ | ||
var div = document.createElement("div"); | ||
var themeBubble = this._params.theme.event.bubble; | ||
fill_info_bubble(evt, div, this._params.theme, this._band.getLabeller()); | ||
SimileAjax.WindowManager.cancelPopups(); | ||
SimileAjax.Graphics.createBubbleForContentAndPoint(div, x, y, | ||
themeBubble.width, null, themeBubble.maxHeight); | ||
}; | ||
""" | ||
|
||
TL_CSS = """ | ||
#commit-timeline { | ||
height: 100%; | ||
border: 1px solid #aaa; | ||
font-size:8pt; | ||
font-family: Verdana,Arial,sans-serif ; | ||
} | ||
/* | ||
.timeline-band-layer-inner { | ||
overflow:hidden; | ||
} | ||
*/ | ||
.timeline-event-bubble-title { | ||
font-family: Verdana,Arial,sans-serif ; | ||
border-bottom:none; | ||
} | ||
.timeline-event-bubble-body { | ||
font-family: Verdana,Arial,sans-serif ; | ||
margin-bottom:0.3em; | ||
} | ||
.timeline-event-bubble-title a { | ||
text-decoration:none; | ||
} | ||
.timeline-event-bubble-time { | ||
font-size:8pt; | ||
font-family: Verdana,Arial,sans-serif ; | ||
} | ||
""" | ||
|
||
TL_HTML = """ | ||
<html> | ||
<head> | ||
<title>Commit Timeline</title> | ||
<script src="%(timeline_js)s" type="text/javascript"></script> | ||
<script src="main.js" type="text/javascript"></script> | ||
<link rel="stylesheet" href="main.css" type="text/css"></link> | ||
</head> | ||
</script> | ||
<body onload="on_load();" onresize="on_resize();"> | ||
<div id="commit-timeline"></div> | ||
</body> | ||
</html> | ||
""" | ||
|
||
|
||
|
||
|
||
def main(): | ||
import sys | ||
from optparse import OptionParser | ||
|
||
parser = OptionParser(usage="[options] git-tree git-tree ...") | ||
|
||
parser.add_option("--url-pattern", metavar="URL", | ||
default="http://git.tiker.net/%(project)s.git/commitdiff/%(commit)s") | ||
parser.add_option("-o", "--output-dir", metavar="DIRNAME", | ||
default="timeline") | ||
parser.add_option("--timeline-js", metavar="JAVASCRIPT", | ||
default="http://static.simile.mit.edu/timeline/api-2.3.0/timeline-api.js") | ||
parser.add_option("-d", "--delete", action="store_true") | ||
options, args = parser.parse_args() | ||
|
||
if args: | ||
if options.delete: | ||
erase_dir(options.output_dir) | ||
|
||
from os import makedirs | ||
makedirs(options.output_dir) | ||
|
||
from os.path import join | ||
open(join(options.output_dir, "commits.xml"), "w").write( | ||
make_commit_xml(args, options.url_pattern)) | ||
|
||
open(join(options.output_dir, "index.html"), "w").write(TL_HTML % { | ||
"timeline_js": options.timeline_js | ||
}) | ||
open(join(options.output_dir, "main.js"), "w").write(TL_JS) | ||
open(join(options.output_dir, "main.css"), "w").write(TL_CSS) | ||
else: | ||
parser.print_help() | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#! /bin/sh | ||
./commit-timeline -d -o ~/tmp/timeline \ | ||
--timeline-js=$HOME/pack/simile-timeline/src/webapp/api/timeline-api.js \ | ||
~/dam/research/software/{hedge,pyrticle,codepy,pycuda,pymbolic,pytools,boostmpi,experiments,meshpy,pylo,pymetis,pyopencl,pyublas} | ||
|
||
|