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);
73 var cmd = array_shift(this.queue);
81 cmd = array_shift(this.queue);
87 shouldIgnore: function(f)
89 if (f.name[0] == '.') {
91 if (f.name == '.htaccess') {
97 if (f.name.match(/~$/)) {
100 // ignore anything in top level!!!!
101 if (!f.vpath.length) {
109 parsePath: function(f) {
111 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
113 f.gitpath = gitlive + '/' + vpath_ar.shift();
114 f.vpath = vpath_ar.join('/');
121 onChanged : function(src)
123 return; // always ignore this..?
124 //this.parsePath(src);
126 onChangesDoneHint : function(src)
129 if (this.shouldIgnore(src)) {
134 if (typeof(this.just_created[src.path]) !='undefined') {
135 delete this.just_created[src.path];
136 this.lastAdd = new Date();
138 [ src.gitpath, 'add', src.vpath ],
139 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
140 [ src.gitpath , 'push', { all: true } ]
145 Git.run(src.gitpath, 'add', src.vpath);
146 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
147 Git.run(src.gitpath , 'push', { all: true } );
148 notify(src.name,"CHANGED", sp);
152 this.lastAdd = new Date();
154 [ src.gitpath, 'add', src.vpath ],
155 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
156 [ src.gitpath , 'push', { all: true } ]
160 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
161 Git.run(src.gitpath , 'push', '--all' );
162 notify(src.name,"CHANGED", sp);
166 onDeleted : function(src)
169 if (this.shouldIgnore(src)) {
172 // should check if monitor needs removing..
173 // it should also check if it was a directory.. - so we dont have to commit all..
175 this.lastAdd = new Date();
177 [ src.gitpath, 'rm' , src.vpath ],
178 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
179 [ src.gitpath, 'push', { all: true } ]
185 var sp = Git.run(src.gitpath,'rm' , src.vpath);
186 Git.run(src.gitpath , 'push', { all: true } );
188 notify(src.name,"DELETED", sp);
191 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
192 Git.run(src.gitpath , 'push',{ all: true });
193 notify(src.name,"DELETED", sp);
197 onCreated : function(src)
200 if (this.shouldIgnore(src)) {
204 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
205 this.just_created[src.path] = true;
206 return; // we do not handle file create flags... - use done hint.
208 // director has bee created
209 this.monitor(src.path);
210 this.lastAdd = new Date();
212 [ src.gitpath, 'add' , src.vpath, { all: true } ],
213 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
214 [ src.gitpath, 'push', { all: true } ]
219 var sp = Git.run(src.gitpath, 'add', src.vpath);
220 Git.run(src.gitpath , 'push', { all: true } );
223 notify(src.path,"CREATED", sp);
226 //uh.call(fm,f,of, event_type);
227 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
228 Git.run(src.gitpath , 'push', { all: true } );
229 notify(src.path,"CREATED", sp);
233 onAttributeChanged : function(src) {
235 if (this.shouldIgnore(src)) {
238 this.lastAdd = new Date();
240 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
241 [ src.gitpath, 'push', { all: true } ]
246 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
247 Git.run(src.gitpath , 'push', { all: true } );
248 notify(src.path,"ATTRIBUTE_CHANGED", sp);
253 onMoved : function(src,dest)
256 this.parsePath(dest);
258 if (src.gitpath != dest.gitpath) {
260 this.onCreated(dest);
261 this.onChangedDoneHint(dest);
264 // needs to handle move to/from unsupported types..
266 if (this.shouldIgnore(src)) {
269 if (this.shouldIgnore(dest)) {
272 this.lastAdd = new Date();
274 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
275 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
276 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
277 [ src.gitpath, 'push', { all: true } ]
284 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
286 notify(dest.path,"MOVED", sp);
289 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
290 Git.run(src.gitpath , 'push', { all: true } );
291 notify(src.path,"MOVED", sp);
301 function notify(fn, act , sp)
303 var sum = act + " " + fn;
305 var notification = new Notify.Notification({
310 notification.set_timeout(500);
318 function errorDialog(data) {
319 var msg = new Gtk.MessageDialog({
320 message_type: Gtk.MessageType.ERROR,
321 buttons : Gtk.ButtonsType.OK,
333 // need a better icon...
336 Notify.init("gitlive");
337 monitor.add(GLib.get_home_dir() + "/gitlive");
340 //icon.signal["activate"].connect(on_left_click);