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);
76 cmd = array_shift(this.queue);
77 var sp = Git.run.call(cmd);
81 success.push(sp.args.join(' '));
82 success.push(sp.output);
85 failure.push(sp.args.join(' '));
86 failure.push(sp.output);
87 failure.push(sp.stderr);
92 if (!this.queue.length) {
99 var notification = new Notify.Notification({
100 summary: "Git Live Commited",
101 body : success.join("\n")
105 notification.set_timeout(500);
108 if (success.length) {
110 var notification = new Notify.Notification({
111 summary: "Git Live ERROR!!",
112 body : failure.join("\n")
116 notification.set_timeout(500);
121 shouldIgnore: function(f)
123 if (f.name[0] == '.') {
125 if (f.name == '.htaccess') {
131 if (f.name.match(/~$/)) {
134 // ignore anything in top level!!!!
135 if (!f.vpath.length) {
143 parsePath: function(f) {
145 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
147 f.gitpath = gitlive + '/' + vpath_ar.shift();
148 f.vpath = vpath_ar.join('/');
155 onChanged : function(src)
157 return; // always ignore this..?
158 //this.parsePath(src);
160 onChangesDoneHint : function(src)
163 if (this.shouldIgnore(src)) {
168 if (typeof(this.just_created[src.path]) !='undefined') {
169 delete this.just_created[src.path];
170 this.lastAdd = new Date();
172 [ src.gitpath, 'add', src.vpath ],
173 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
174 [ src.gitpath , 'push', { all: true } ]
179 Git.run(src.gitpath, 'add', src.vpath);
180 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
181 Git.run(src.gitpath , 'push', { all: true } );
182 notify(src.name,"CHANGED", sp);
186 this.lastAdd = new Date();
188 [ src.gitpath, 'add', src.vpath ],
189 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
190 [ src.gitpath , 'push', { all: true } ]
194 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
195 Git.run(src.gitpath , 'push', '--all' );
196 notify(src.name,"CHANGED", sp);
200 onDeleted : function(src)
203 if (this.shouldIgnore(src)) {
206 // should check if monitor needs removing..
207 // it should also check if it was a directory.. - so we dont have to commit all..
209 this.lastAdd = new Date();
211 [ src.gitpath, 'rm' , src.vpath ],
212 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
213 [ src.gitpath, 'push', { all: true } ]
219 var sp = Git.run(src.gitpath,'rm' , src.vpath);
220 Git.run(src.gitpath , 'push', { all: true } );
222 notify(src.name,"DELETED", sp);
225 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
226 Git.run(src.gitpath , 'push',{ all: true });
227 notify(src.name,"DELETED", sp);
231 onCreated : function(src)
234 if (this.shouldIgnore(src)) {
238 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
239 this.just_created[src.path] = true;
240 return; // we do not handle file create flags... - use done hint.
242 // director has bee created
243 this.monitor(src.path);
244 this.lastAdd = new Date();
246 [ src.gitpath, 'add' , src.vpath, { all: true } ],
247 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
248 [ src.gitpath, 'push', { all: true } ]
253 var sp = Git.run(src.gitpath, 'add', src.vpath);
254 Git.run(src.gitpath , 'push', { all: true } );
257 notify(src.path,"CREATED", sp);
260 //uh.call(fm,f,of, event_type);
261 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
262 Git.run(src.gitpath , 'push', { all: true } );
263 notify(src.path,"CREATED", sp);
267 onAttributeChanged : function(src) {
269 if (this.shouldIgnore(src)) {
272 this.lastAdd = new Date();
274 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
275 [ src.gitpath, 'push', { all: true } ]
280 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
281 Git.run(src.gitpath , 'push', { all: true } );
282 notify(src.path,"ATTRIBUTE_CHANGED", sp);
287 onMoved : function(src,dest)
290 this.parsePath(dest);
292 if (src.gitpath != dest.gitpath) {
294 this.onCreated(dest);
295 this.onChangedDoneHint(dest);
298 // needs to handle move to/from unsupported types..
300 if (this.shouldIgnore(src)) {
303 if (this.shouldIgnore(dest)) {
306 this.lastAdd = new Date();
308 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
309 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
310 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
311 [ src.gitpath, 'push', { all: true } ]
318 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
320 notify(dest.path,"MOVED", sp);
323 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
324 Git.run(src.gitpath , 'push', { all: true } );
325 notify(src.path,"MOVED", sp);
335 function notify(fn, act , sp)
337 var sum = act + " " + fn;
339 var notification = new Notify.Notification({
344 notification.set_timeout(500);
352 function errorDialog(data) {
353 var msg = new Gtk.MessageDialog({
354 message_type: Gtk.MessageType.ERROR,
355 buttons : Gtk.ButtonsType.OK,
367 // need a better icon...
370 Notify.init("gitlive");
371 monitor.add(GLib.get_home_dir() + "/gitlive");
374 //icon.signal["activate"].connect(on_left_click);