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."});
40 var monitor = new Monitor({
43 nqv : true, // temp var while I switch to queued version.
47 this.lastAdd = new Date();
49 Glib.idle_add(PRIORITY_LOW, function() {
50 if (!_this.queue.length) {
53 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
54 if (last < 5) { // wait 1/2 a seconnd before running.
60 Monitor.prototype.start.call(this);
61 var notification = new Notify.Notification({
63 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
66 notification.set_timeout(500);
77 cmd = array_shift(this.queue);
78 var sp = Git.run.call(cmd);
82 success.push(sp.args.join(' '));
83 success.push(sp.output);
86 failure.push(sp.args.join(' '));
87 failure.push(sp.output);
88 failure.push(sp.stderr);
93 if (!this.queue.length) {
100 var notification = new Notify.Notification({
101 summary: "Git Live Commited",
102 body : success.join("\n")
106 notification.set_timeout(500);
109 if (success.length) {
111 var notification = new Notify.Notification({
112 summary: "Git Live ERROR!!",
113 body : failure.join("\n")
117 notification.set_timeout(500);
122 shouldIgnore: function(f)
124 if (f.name[0] == '.') {
126 if (f.name == '.htaccess') {
132 if (f.name.match(/~$/)) {
135 // ignore anything in top level!!!!
136 if (!f.vpath.length) {
144 parsePath: function(f) {
146 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
148 f.gitpath = gitlive + '/' + vpath_ar.shift();
149 f.vpath = vpath_ar.join('/');
156 onChanged : function(src)
158 return; // always ignore this..?
159 //this.parsePath(src);
161 onChangesDoneHint : function(src)
164 if (this.shouldIgnore(src)) {
169 if (typeof(this.just_created[src.path]) !='undefined') {
170 delete this.just_created[src.path];
171 this.lastAdd = new Date();
173 [ src.gitpath, 'add', src.vpath ],
174 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
175 [ src.gitpath , 'push', { all: true } ]
180 Git.run(src.gitpath, 'add', src.vpath);
181 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
182 Git.run(src.gitpath , 'push', { all: true } );
183 notify(src.name,"CHANGED", sp);
187 this.lastAdd = new Date();
189 [ src.gitpath, 'add', src.vpath ],
190 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
191 [ src.gitpath , 'push', { all: true } ]
195 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
196 Git.run(src.gitpath , 'push', '--all' );
197 notify(src.name,"CHANGED", sp);
201 onDeleted : function(src)
204 if (this.shouldIgnore(src)) {
207 // should check if monitor needs removing..
208 // it should also check if it was a directory.. - so we dont have to commit all..
210 this.lastAdd = new Date();
212 [ src.gitpath, 'rm' , src.vpath ],
213 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
214 [ src.gitpath, 'push', { all: true } ]
220 var sp = Git.run(src.gitpath,'rm' , src.vpath);
221 Git.run(src.gitpath , 'push', { all: true } );
223 notify(src.name,"DELETED", sp);
226 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
227 Git.run(src.gitpath , 'push',{ all: true });
228 notify(src.name,"DELETED", sp);
232 onCreated : function(src)
235 if (this.shouldIgnore(src)) {
239 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
240 this.just_created[src.path] = true;
241 return; // we do not handle file create flags... - use done hint.
243 // director has bee created
244 this.monitor(src.path);
245 this.lastAdd = new Date();
247 [ src.gitpath, 'add' , src.vpath, { all: true } ],
248 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
249 [ src.gitpath, 'push', { all: true } ]
254 var sp = Git.run(src.gitpath, 'add', src.vpath);
255 Git.run(src.gitpath , 'push', { all: true } );
258 notify(src.path,"CREATED", sp);
261 //uh.call(fm,f,of, event_type);
262 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
263 Git.run(src.gitpath , 'push', { all: true } );
264 notify(src.path,"CREATED", sp);
268 onAttributeChanged : function(src) {
270 if (this.shouldIgnore(src)) {
273 this.lastAdd = new Date();
275 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
276 [ src.gitpath, 'push', { all: true } ]
281 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
282 Git.run(src.gitpath , 'push', { all: true } );
283 notify(src.path,"ATTRIBUTE_CHANGED", sp);
288 onMoved : function(src,dest)
291 this.parsePath(dest);
293 if (src.gitpath != dest.gitpath) {
295 this.onCreated(dest);
296 this.onChangedDoneHint(dest);
299 // needs to handle move to/from unsupported types..
301 if (this.shouldIgnore(src)) {
304 if (this.shouldIgnore(dest)) {
307 this.lastAdd = new Date();
309 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
310 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
311 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
312 [ src.gitpath, 'push', { all: true } ]
319 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
321 notify(dest.path,"MOVED", sp);
324 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
325 Git.run(src.gitpath , 'push', { all: true } );
326 notify(src.path,"MOVED", sp);
336 function notify(fn, act , sp)
338 var sum = act + " " + fn;
340 var notification = new Notify.Notification({
345 notification.set_timeout(500);
353 function errorDialog(data) {
354 var msg = new Gtk.MessageDialog({
355 message_type: Gtk.MessageType.ERROR,
356 buttons : Gtk.ButtonsType.OK,
368 // need a better icon...
371 Notify.init("gitlive");
372 monitor.add(GLib.get_home_dir() + "/gitlive");
375 //icon.signal["activate"].connect(on_left_click);