2 ///<script type="text/javascript">
6 * inotify hooks for ~/gitlive
7 * that commit and push any changes made.
8 * Bit like a revision controled backed up file system!?
12 GI = imports.gi.GIRepository;
14 GLib = imports.gi.GLib;
16 Notify = imports.gi.Notify;
18 Spawn = imports.Spawn;
20 StatusIcon = imports.StatusIcon.StatusIcon;
21 Monitor = imports.Monitor.Monitor;
24 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
25 Gtk.init (null, null);
27 var gitlive = GLib.get_home_dir() + "/gitlive";
29 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
30 var msg = new Gtk.MessageDialog({message_type:
31 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
39 var monitor = new Monitor({
43 nqv : false, // temp var while I switch to queued version.
47 this.lastAdd = new Date();
49 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
50 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
51 if (!_this.queue.length || _this.queueRunning) {
54 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
55 if (last < 4) { // wait 1/2 a seconnd before running.
62 Monitor.prototype.start.call(this);
63 var notification = new Notify.Notification({
65 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
68 notification.set_timeout(500);
74 * - pulls the items off the queue
75 * (as commands run concurrently and new items may get added while it's running)
76 * - runs the queue items
82 this.queueRunning = true;
84 this.queue.forEach(function (q) {
87 this.queue = []; // empty queue!
92 cmds.forEach(function(cmd) {
93 if (repos.indexOf(cmd[0]) < 0) {
96 var sp = Git.run.apply(Git,cmd);
100 success.push(sp.args.join(' '));
101 success.push(sp.output);
104 failure.push(sp.args.join(' '));
105 failure.push(sp.output);
106 failure.push(sp.stderr);
112 repos.forEach(function(r) {
113 var sp = Git.run(r , 'push', { all: true } );
120 if (success.length) {
122 var notification = new Notify.Notification({
123 summary: "Git Live Commited",
124 body : success.join("\n")
128 notification.set_timeout(500);
131 if (failure.length) {
133 var notification = new Notify.Notification({
134 summary: "Git Live ERROR!!",
135 body : failure.join("\n")
139 notification.set_timeout(500);
142 this.queueRunning = false;
145 shouldIgnore: function(f)
147 if (f.name[0] == '.') {
149 if (f.name == '.htaccess') {
155 if (f.name.match(/~$/)) {
158 // ignore anything in top level!!!!
159 if (!f.vpath.length) {
167 parsePath: function(f) {
169 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
171 f.gitpath = gitlive + '/' + vpath_ar.shift();
172 f.vpath = vpath_ar.join('/');
179 onChanged : function(src)
181 return; // always ignore this..?
182 //this.parsePath(src);
184 onChangesDoneHint : function(src)
187 if (this.shouldIgnore(src)) {
192 if (typeof(this.just_created[src.path]) !='undefined') {
193 delete this.just_created[src.path];
194 this.lastAdd = new Date();
196 [ src.gitpath, 'add', src.vpath ],
197 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
202 Git.run(src.gitpath, 'add', src.vpath);
203 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
204 Git.run(src.gitpath , 'push', { all: true } );
205 notify(src.name,"CHANGED", sp);
209 this.lastAdd = new Date();
211 [ src.gitpath, 'add', src.vpath ],
212 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
217 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
218 Git.run(src.gitpath , 'push', '--all' );
219 notify(src.name,"CHANGED", sp);
223 onDeleted : function(src)
226 if (this.shouldIgnore(src)) {
229 // should check if monitor needs removing..
230 // it should also check if it was a directory.. - so we dont have to commit all..
232 this.lastAdd = new Date();
234 [ src.gitpath, 'rm' , src.vpath ],
235 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
242 var sp = Git.run(src.gitpath,'rm' , src.vpath);
243 Git.run(src.gitpath , 'push', { all: true } );
245 notify(src.name,"DELETED", sp);
248 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
249 Git.run(src.gitpath , 'push',{ all: true });
250 notify(src.name,"DELETED", sp);
254 onCreated : function(src)
257 if (this.shouldIgnore(src)) {
261 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
262 this.just_created[src.path] = true;
263 return; // we do not handle file create flags... - use done hint.
265 // director has bee created
266 this.monitor(src.path);
267 this.lastAdd = new Date();
269 [ src.gitpath, 'add' , src.vpath, { all: true } ],
270 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
276 var sp = Git.run(src.gitpath, 'add', src.vpath);
277 Git.run(src.gitpath , 'push', { all: true } );
280 notify(src.path,"CREATED", sp);
283 //uh.call(fm,f,of, event_type);
284 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
285 Git.run(src.gitpath , 'push', { all: true } );
286 notify(src.path,"CREATED", sp);
290 onAttributeChanged : function(src) {
292 if (this.shouldIgnore(src)) {
295 this.lastAdd = new Date();
297 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
302 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
303 Git.run(src.gitpath , 'push', { all: true } );
304 notify(src.path,"ATTRIBUTE_CHANGED", sp);
309 onMoved : function(src,dest)
312 this.parsePath(dest);
314 if (src.gitpath != dest.gitpath) {
316 this.onCreated(dest);
317 this.onChangedDoneHint(dest);
320 // needs to handle move to/from unsupported types..
322 if (this.shouldIgnore(src)) {
325 if (this.shouldIgnore(dest)) {
328 this.lastAdd = new Date();
330 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
331 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
332 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
339 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
341 notify(dest.path,"MOVED", sp);
344 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
345 Git.run(src.gitpath , 'push', { all: true } );
346 notify(src.path,"MOVED", sp);
356 function notify(fn, act , sp)
358 var sum = act + " " + fn;
360 var notification = new Notify.Notification({
365 notification.set_timeout(500);
373 function errorDialog(data) {
374 var msg = new Gtk.MessageDialog({
375 message_type: Gtk.MessageType.ERROR,
376 buttons : Gtk.ButtonsType.OK,
388 // need a better icon...
391 Notify.init("gitlive");
392 monitor.add(GLib.get_home_dir() + "/gitlive");
395 //icon.signal["activate"].connect(on_left_click);