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);
71 shouldIgnore: function(f)
73 if (f.name[0] == '.') {
75 if (f.name == '.htaccess') {
81 if (f.name.match(/~$/)) {
84 // ignore anything in top level!!!!
85 if (!f.vpath.length) {
93 parsePath: function(f) {
95 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
97 f.gitpath = gitlive + '/' + vpath_ar.shift();
98 f.vpath = vpath_ar.join('/');
105 onChanged : function(src)
107 return; // always ignore this..?
108 //this.parsePath(src);
110 onChangesDoneHint : function(src)
113 if (this.shouldIgnore(src)) {
118 if (typeof(this.just_created[src.path]) !='undefined') {
119 delete this.just_created[src.path];
120 this.lastAdd = new Date();
122 [ src.gitpath, 'add', src.vpath ],
123 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
124 [ src.gitpath , 'push', { all: true } ]
129 Git.run(src.gitpath, 'add', src.vpath);
130 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
131 Git.run(src.gitpath , 'push', { all: true } );
132 notify(src.name,"CHANGED", sp);
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 } ]
144 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
145 Git.run(src.gitpath , 'push', '--all' );
146 notify(src.name,"CHANGED", sp);
150 onDeleted : function(src)
153 if (this.shouldIgnore(src)) {
156 // should check if monitor needs removing..
157 // it should also check if it was a directory.. - so we dont have to commit all..
159 this.lastAdd = new Date();
161 [ src.gitpath, 'rm' , src.vpath ],
162 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
163 [ src.gitpath, 'push', { all: true } ]
169 var sp = Git.run(src.gitpath,'rm' , src.vpath);
170 Git.run(src.gitpath , 'push', { all: true } );
172 notify(src.name,"DELETED", sp);
175 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
176 Git.run(src.gitpath , 'push',{ all: true });
177 notify(src.name,"DELETED", sp);
181 onCreated : function(src)
184 if (this.shouldIgnore(src)) {
188 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
189 this.just_created[src.path] = true;
190 return; // we do not handle file create flags... - use done hint.
192 // director has bee created
193 this.monitor(src.path);
194 this.lastAdd = new Date();
196 [ src.gitpath, 'add' , src.vpath, { all: true } ],
197 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
198 [ src.gitpath, 'push', { all: true } ]
203 var sp = Git.run(src.gitpath, 'add', src.vpath);
204 Git.run(src.gitpath , 'push', { all: true } );
207 notify(src.path,"CREATED", sp);
210 //uh.call(fm,f,of, event_type);
211 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
212 Git.run(src.gitpath , 'push', { all: true } );
213 notify(src.path,"CREATED", sp);
217 onAttributeChanged : function(src) {
219 if (this.shouldIgnore(src)) {
222 this.lastAdd = new Date();
224 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
225 [ src.gitpath, 'push', { all: true } ]
230 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
231 Git.run(src.gitpath , 'push', { all: true } );
232 notify(src.path,"ATTRIBUTE_CHANGED", sp);
237 onMoved : function(src,dest)
240 this.parsePath(dest);
242 if (src.gitpath != dest.gitpath) {
244 this.onCreated(dest);
245 this.onChangedDoneHint(dest);
248 // needs to handle move to/from unsupported types..
250 if (this.shouldIgnore(src)) {
253 if (this.shouldIgnore(dest)) {
256 this.lastAdd = new Date();
258 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
259 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
260 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
261 [ src.gitpath, 'push', { all: true } ]
268 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
270 notify(dest.path,"MOVED", sp);
273 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
274 Git.run(src.gitpath , 'push', { all: true } );
275 notify(src.path,"MOVED", sp);
285 function notify(fn, act , sp)
287 var sum = act + " " + fn;
289 var notification = new Notify.Notification({
294 notification.set_timeout(500);
302 function errorDialog(data) {
303 var msg = new Gtk.MessageDialog({
304 message_type: Gtk.MessageType.ERROR,
305 buttons : Gtk.ButtonsType.OK,
317 // need a better icon...
320 Notify.init("gitlive");
321 monitor.add(GLib.get_home_dir() + "/gitlive");
324 //icon.signal["activate"].connect(on_left_click);