2 var File = imports.File.File;
11 var home = GLib.get_home_dir();
13 var flines = File.read( home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
14 // first just convert them..
15 // we had an old bug that did not put line breaks in there..
16 // however 00:00:00: is pretty distinct, so let'st try and split on it..
21 for (var i = 0; i < flines.length; i++) {
22 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
23 //print(JSON.stringify(xl));
24 for (var ii=1; ii< xl.length; ii+=2) {
26 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
28 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
35 print(JSON.stringify(lines,null,4));
39 for (var i = 0; i < lines.length; i++) {
41 var hour = line.start.format('H');
42 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
43 hours[hour][project] = (typeof(hours[project]) == 'undefined') ?
44 { total : 0, items : [] }
46 hours[hour][project].total += line.span;
47 hours[hour][project].items.push(line);
52 parseLine : function(l)
54 var ret = { cmd : false, line : l };
55 var ar = l.split(/\s+/);
56 print(JSON.stringify(ar));
58 var time = ar.shift();
59 print("time: " + time);
61 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
64 while (ret.cmd === false) {
67 if (ta[0] != '-') { //hopfully withc catch stuff.
72 // just assume it's the last bit..
74 throw "invalid line: " + l;
81 ret.title = ar.join(' ');
82 if (ret.title == 'IDLE') {
89 if (typeof(this[ret.cmd])=='undefined') {
90 ret.project = 'Unknown';
92 print( "Unknown application: " + ret.line);
93 throw { error : "TEST"};
95 if (typeof(this[ret.cmd])=='string') {
96 ret.project = this[ret.cmd]
107 '/usr/bin/perl' : function(ret) {
108 if (ret.title.match(/^PAC/)) {
109 ret.project = 'Unknown';
112 throw "Unknown match: " + ret.line;
114 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
115 '/usr/lib/chromium/chromium' : function (ret) {
119 case (ret.title.match(/Media Clipping Portal/)):
120 ret.project = 'Media Outreach';
124 ret.project = 'Browsing';
129 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
130 var l = ret.title.match(/Project\s+(^\)+)/);
132 ret.project="Unknown";
135 throw "Unknown match: " + ret.line;
137 'guake' : 'Local Terminal',
143 var res = GitLogParser.parse(xDate.Date.parseDate('2012-07-31', 'Y-m-d'));
144 print(JSON.stringify(res,null,4));
150 // summarize each hour
152 //convert line into 'Project / filename'