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) {
98 var notification = new Notify.Notification({
100 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
103 notification.set_timeout(500);
108 shouldIgnore: function(f)
110 if (f.name[0] == '.') {
112 if (f.name == '.htaccess') {
118 if (f.name.match(/~$/)) {
121 // ignore anything in top level!!!!
122 if (!f.vpath.length) {
130 parsePath: function(f) {
132 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
134 f.gitpath = gitlive + '/' + vpath_ar.shift();
135 f.vpath = vpath_ar.join('/');
142 onChanged : function(src)
144 return; // always ignore this..?
145 //this.parsePath(src);
147 onChangesDoneHint : function(src)
150 if (this.shouldIgnore(src)) {
155 if (typeof(this.just_created[src.path]) !='undefined') {
156 delete this.just_created[src.path];
157 this.lastAdd = new Date();
159 [ src.gitpath, 'add', src.vpath ],
160 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
161 [ src.gitpath , 'push', { all: true } ]
166 Git.run(src.gitpath, 'add', src.vpath);
167 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
168 Git.run(src.gitpath , 'push', { all: true } );
169 notify(src.name,"CHANGED", sp);
173 this.lastAdd = new Date();
175 [ src.gitpath, 'add', src.vpath ],
176 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
177 [ src.gitpath , 'push', { all: true } ]
181 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
182 Git.run(src.gitpath , 'push', '--all' );
183 notify(src.name,"CHANGED", sp);
187 onDeleted : function(src)
190 if (this.shouldIgnore(src)) {
193 // should check if monitor needs removing..
194 // it should also check if it was a directory.. - so we dont have to commit all..
196 this.lastAdd = new Date();
198 [ src.gitpath, 'rm' , src.vpath ],
199 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
200 [ src.gitpath, 'push', { all: true } ]
206 var sp = Git.run(src.gitpath,'rm' , src.vpath);
207 Git.run(src.gitpath , 'push', { all: true } );
209 notify(src.name,"DELETED", sp);
212 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
213 Git.run(src.gitpath , 'push',{ all: true });
214 notify(src.name,"DELETED", sp);
218 onCreated : function(src)
221 if (this.shouldIgnore(src)) {
225 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
226 this.just_created[src.path] = true;
227 return; // we do not handle file create flags... - use done hint.
229 // director has bee created
230 this.monitor(src.path);
231 this.lastAdd = new Date();
233 [ src.gitpath, 'add' , src.vpath, { all: true } ],
234 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
235 [ src.gitpath, 'push', { all: true } ]
240 var sp = Git.run(src.gitpath, 'add', src.vpath);
241 Git.run(src.gitpath , 'push', { all: true } );
244 notify(src.path,"CREATED", sp);
247 //uh.call(fm,f,of, event_type);
248 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
249 Git.run(src.gitpath , 'push', { all: true } );
250 notify(src.path,"CREATED", sp);
254 onAttributeChanged : function(src) {
256 if (this.shouldIgnore(src)) {
259 this.lastAdd = new Date();
261 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
262 [ src.gitpath, 'push', { all: true } ]
267 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
268 Git.run(src.gitpath , 'push', { all: true } );
269 notify(src.path,"ATTRIBUTE_CHANGED", sp);
274 onMoved : function(src,dest)
277 this.parsePath(dest);
279 if (src.gitpath != dest.gitpath) {
281 this.onCreated(dest);
282 this.onChangedDoneHint(dest);
285 // needs to handle move to/from unsupported types..
287 if (this.shouldIgnore(src)) {
290 if (this.shouldIgnore(dest)) {
293 this.lastAdd = new Date();
295 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
296 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
297 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
298 [ src.gitpath, 'push', { all: true } ]
305 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
307 notify(dest.path,"MOVED", sp);
310 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
311 Git.run(src.gitpath , 'push', { all: true } );
312 notify(src.path,"MOVED", sp);
322 function notify(fn, act , sp)
324 var sum = act + " " + fn;
326 var notification = new Notify.Notification({
331 notification.set_timeout(500);
339 function errorDialog(data) {
340 var msg = new Gtk.MessageDialog({
341 message_type: Gtk.MessageType.ERROR,
342 buttons : Gtk.ButtonsType.OK,
354 // need a better icon...
357 Notify.init("gitlive");
358 monitor.add(GLib.get_home_dir() + "/gitlive");
361 //icon.signal["activate"].connect(on_left_click);