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);
76 var sp = Git.run.call(cmd);
79 cmd = array_shift(this.queue);
85 shouldIgnore: function(f)
87 if (f.name[0] == '.') {
89 if (f.name == '.htaccess') {
95 if (f.name.match(/~$/)) {
98 // ignore anything in top level!!!!
99 if (!f.vpath.length) {
107 parsePath: function(f) {
109 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
111 f.gitpath = gitlive + '/' + vpath_ar.shift();
112 f.vpath = vpath_ar.join('/');
119 onChanged : function(src)
121 return; // always ignore this..?
122 //this.parsePath(src);
124 onChangesDoneHint : function(src)
127 if (this.shouldIgnore(src)) {
132 if (typeof(this.just_created[src.path]) !='undefined') {
133 delete this.just_created[src.path];
134 this.lastAdd = new Date();
136 [ src.gitpath, 'add', src.vpath ],
137 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
138 [ src.gitpath , 'push', { all: true } ]
143 Git.run(src.gitpath, 'add', src.vpath);
144 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
145 Git.run(src.gitpath , 'push', { all: true } );
146 notify(src.name,"CHANGED", sp);
150 this.lastAdd = new Date();
152 [ src.gitpath, 'add', src.vpath ],
153 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
154 [ src.gitpath , 'push', { all: true } ]
158 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
159 Git.run(src.gitpath , 'push', '--all' );
160 notify(src.name,"CHANGED", sp);
164 onDeleted : function(src)
167 if (this.shouldIgnore(src)) {
170 // should check if monitor needs removing..
171 // it should also check if it was a directory.. - so we dont have to commit all..
173 this.lastAdd = new Date();
175 [ src.gitpath, 'rm' , src.vpath ],
176 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
177 [ src.gitpath, 'push', { all: true } ]
183 var sp = Git.run(src.gitpath,'rm' , src.vpath);
184 Git.run(src.gitpath , 'push', { all: true } );
186 notify(src.name,"DELETED", sp);
189 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
190 Git.run(src.gitpath , 'push',{ all: true });
191 notify(src.name,"DELETED", sp);
195 onCreated : function(src)
198 if (this.shouldIgnore(src)) {
202 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
203 this.just_created[src.path] = true;
204 return; // we do not handle file create flags... - use done hint.
206 // director has bee created
207 this.monitor(src.path);
208 this.lastAdd = new Date();
210 [ src.gitpath, 'add' , src.vpath, { all: true } ],
211 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
212 [ src.gitpath, 'push', { all: true } ]
217 var sp = Git.run(src.gitpath, 'add', src.vpath);
218 Git.run(src.gitpath , 'push', { all: true } );
221 notify(src.path,"CREATED", sp);
224 //uh.call(fm,f,of, event_type);
225 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
226 Git.run(src.gitpath , 'push', { all: true } );
227 notify(src.path,"CREATED", sp);
231 onAttributeChanged : function(src) {
233 if (this.shouldIgnore(src)) {
236 this.lastAdd = new Date();
238 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
239 [ src.gitpath, 'push', { all: true } ]
244 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
245 Git.run(src.gitpath , 'push', { all: true } );
246 notify(src.path,"ATTRIBUTE_CHANGED", sp);
251 onMoved : function(src,dest)
254 this.parsePath(dest);
256 if (src.gitpath != dest.gitpath) {
258 this.onCreated(dest);
259 this.onChangedDoneHint(dest);
262 // needs to handle move to/from unsupported types..
264 if (this.shouldIgnore(src)) {
267 if (this.shouldIgnore(dest)) {
270 this.lastAdd = new Date();
272 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
273 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
274 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
275 [ src.gitpath, 'push', { all: true } ]
282 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
284 notify(dest.path,"MOVED", sp);
287 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
288 Git.run(src.gitpath , 'push', { all: true } );
289 notify(src.path,"MOVED", sp);
299 function notify(fn, act , sp)
301 var sum = act + " " + fn;
303 var notification = new Notify.Notification({
308 notification.set_timeout(500);
316 function errorDialog(data) {
317 var msg = new Gtk.MessageDialog({
318 message_type: Gtk.MessageType.ERROR,
319 buttons : Gtk.ButtonsType.OK,
331 // need a better icon...
334 Notify.init("gitlive");
335 monitor.add(GLib.get_home_dir() + "/gitlive");
338 //icon.signal["activate"].connect(on_left_click);